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

clearer comments
Source Link
chunes
  • 27.8k
  • 3
  • 32
  • 55

Factor + math.extras project-euler.014, 59 bytes

[ collatz [ < ] monotonic-count rest 1 prefix 48 v+n bin> ]

Try it online!

There is no way Factor would be competitive withusing the mathy recursive algorithm. Too many symbols means too much whitespace. So we take advantage of the fact that Factor has a built-in collatz sequence word and a simple way to detect increases in a sequence.

Explanation

 ! 3
collatz ! { 3 10 5 16 8 4 2 1 }
[ < ] monotonic-count ! { 0 1 0 1 0 0 0 0 } (did it increase? then 1)
rest 1 prefix ! { 1 1 0 1 0 0 0 0 } (change first element to 1)
48 v+n ! { 49 49 48 49 48 48 48 48 } (add 48 [equivalent to "11010000"])
bin> ! 208 (convert from binary)

Factor + math.extras project-euler.014, 59 bytes

[ collatz [ < ] monotonic-count rest 1 prefix 48 v+n bin> ]

Try it online!

There is no way Factor would be competitive with the mathy recursive algorithm. Too many symbols means too much whitespace. So we take advantage of the fact that Factor has a built-in collatz sequence word and a simple way to detect increases in a sequence.

Explanation

 ! 3
collatz ! { 3 10 5 16 8 4 2 1 }
[ < ] monotonic-count ! { 0 1 0 1 0 0 0 0 } (did it increase? then 1)
rest 1 prefix ! { 1 1 0 1 0 0 0 0 } (change first element to 1)
48 v+n ! { 49 49 48 49 48 48 48 48 } (add 48 [equivalent to "11010000"])
bin> ! 208 (convert from binary)

Factor + math.extras project-euler.014, 59 bytes

[ collatz [ < ] monotonic-count rest 1 prefix 48 v+n bin> ]

Try it online!

There is no way Factor would be competitive using the mathy recursive algorithm. Too many symbols means too much whitespace. So we take advantage of the fact that Factor has a built-in collatz sequence word and a simple way to detect increases in a sequence.

Explanation

 ! 3
collatz ! { 3 10 5 16 8 4 2 1 }
[ < ] monotonic-count ! { 0 1 0 1 0 0 0 0 } (did it increase? then 1)
rest 1 prefix ! { 1 1 0 1 0 0 0 0 } (change first element to 1)
48 v+n ! { 49 49 48 49 48 48 48 48 } (add 48 [equivalent to "11010000"])
bin> ! 208 (convert from binary)
Source Link
chunes
  • 27.8k
  • 3
  • 32
  • 55

Factor + math.extras project-euler.014, 59 bytes

[ collatz [ < ] monotonic-count rest 1 prefix 48 v+n bin> ]

Try it online!

There is no way Factor would be competitive with the mathy recursive algorithm. Too many symbols means too much whitespace. So we take advantage of the fact that Factor has a built-in collatz sequence word and a simple way to detect increases in a sequence.

Explanation

 ! 3
collatz ! { 3 10 5 16 8 4 2 1 }
[ < ] monotonic-count ! { 0 1 0 1 0 0 0 0 } (did it increase? then 1)
rest 1 prefix ! { 1 1 0 1 0 0 0 0 } (change first element to 1)
48 v+n ! { 49 49 48 49 48 48 48 48 } (add 48 [equivalent to "11010000"])
bin> ! 208 (convert from binary)

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