I would like to translate the following Python code to C++.
def puzzle(i):
ps = set()
def sp(i, p=2):
if i==1: return ''
d = ps.add(p) or 0
while i % p == 0:
d,i = d+1,i//p
while any(p % q == 0 for q in ps):
p+=1
return puzzle(d) + sp(i,p)
return f'({sp(si)})' if i else '.'
I made a couple of tries but got stuck with recursive lambda/function<> (I tried to implement a nested function with it). So the main problem for me is to implement the sp() inside puzzle(). However, I don't necessary want it to be nested, just so the code works. I am beginner in C++, so I'm sorry if it'd be too trivial. Thanks in advance.
source https://stackoverflow.com/questions/75538678/how-to-write-the-following-python-code-in-c
Comments
Post a Comment