Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 18 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253

Haskell, 103(削除) 103 (削除ここまで) 87 bytes

Horribly inefficient, but does not rely on floating point arithmetic. Here a(x) = sqrt(f(x)+a(x-1)) is a helper sequence, that simplifies the computation.

a 1=(1,1)0=0
a x|n<x=[k|k<-snd([1..],m<-[k^2-a(x-1)),m<-[k|k<-[1..],k^2>nm>0,notElem(k^2-n)$(fst.a)<$>[1 m$f<$>[1..x-1]]!!0=0
f x=(m^2-n,ma x)
fst.^2-a(x-1)

Try it online! Try it online!

Haskell, 103 bytes

Horribly inefficient, but does not rely on floating point arithmetic.

a 1=(1,1)
a x|n<-snd(a(x-1)),m<-[k|k<-[1..],k^2>n,notElem(k^2-n)$(fst.a)<$>[1..x-1]]!!0=(m^2-n,m)
fst.a

Try it online!

Haskell, (削除) 103 (削除ここまで) 87 bytes

Horribly inefficient, but does not rely on floating point arithmetic. Here a(x) = sqrt(f(x)+a(x-1)) is a helper sequence, that simplifies the computation.

a 0=0
a x=[k|k<-[1..],m<-[k^2-a(x-1)],m>0,notElem m$f<$>[1..x-1]]!!0
f x=(a x)^2-a(x-1)

Try it online!

Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253

Haskell, 103 bytes

Horribly inefficient, but does not rely on floating point arithmetic.

a 1=(1,1)
a x|n<-snd(a(x-1)),m<-[k|k<-[1..],k^2>n,notElem(k^2-n)$(fst.a)<$>[1..x-1]]!!0=(m^2-n,m)
fst.a

Try it online!

AltStyle によって変換されたページ (->オリジナル) /