Skip to main content
added 587 characters in body
Source Link
Ajax1234
  • 7.7k
  • 1
  • 15
  • 28

Python3, 231386 bytes:

def f(n):
 A,I=[1],[]
 while sum(1/i for i in A)+1/(A[-1]+1)<=n:A.append(A[-1]+1)
 q = [([1]A[:],n,0)]
 while 1:
  c,d,k = q.pop(0)
  if(s:=sum(1/i for i in c))==n:return c
  F=1
  if d:
   l =l= c[-1]
   while (s+1/(l:=l+1))>n or l in I:1
    if l>10e7:I.append(A.pop());q=[(A[:],n,0)];F=0;break
   if F:q.append((c+[l],d-(k:=l>(c[-1]+1)),k))
  if k and F:
   q.append((c[:-1]+[c[-1]+1],d,k))

Try it online!Try it online!

Local results (Macbook Pro):

1 [1]
2 [1, 2, 3, 6]
3 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 230, 57960]
4 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 31, 32, 33, 34, 45, 7397, 82673165]
python3 egyptian_tests.py  29.14s user 0.15s system 99% cpu 29.480 total

Python3, 231 bytes:

def f(n):
 q = [([1],n,0)]
 while 1:
  c,d,k = q.pop(0)
  if(s:=sum(1/i for i in c))==n:return c
  if d:
   l = c[-1]
   while (s+1/(l:=l+1))>n:1
   q.append((c+[l],d-(k:=l>(c[-1]+1)),k))
  if k:
   q.append((c[:-1]+[c[-1]+1],d,k))

Try it online!

Python3, 386 bytes:

def f(n):
 A,I=[1],[]
 while sum(1/i for i in A)+1/(A[-1]+1)<=n:A.append(A[-1]+1)
 q = [(A[:],n,0)]
 while 1:
  c,d,k = q.pop(0)
  if(s:=sum(1/i for i in c))==n:return c
  F=1
  if d:
   l= c[-1]
   while (s+1/(l:=l+1))>n or l in I:
    if l>10e7:I.append(A.pop());q=[(A[:],n,0)];F=0;break
   if F:q.append((c+[l],d-(k:=l>(c[-1]+1)),k))
  if k and F:
   q.append((c[:-1]+[c[-1]+1],d,k))

Try it online!

Local results (Macbook Pro):

1 [1]
2 [1, 2, 3, 6]
3 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 230, 57960]
4 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 31, 32, 33, 34, 45, 7397, 82673165]
python3 egyptian_tests.py  29.14s user 0.15s system 99% cpu 29.480 total
Source Link
Ajax1234
  • 7.7k
  • 1
  • 15
  • 28

Python3, 231 bytes:

def f(n):
 q = [([1],n,0)]
 while 1:
  c,d,k = q.pop(0)
  if(s:=sum(1/i for i in c))==n:return c
  if d:
   l = c[-1]
   while (s+1/(l:=l+1))>n:1
   q.append((c+[l],d-(k:=l>(c[-1]+1)),k))
  if k:
   q.append((c[:-1]+[c[-1]+1],d,k))

Try it online!