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

Commonmark migration
Source Link

#dc, (削除) 30 (削除ここまで) 28 bytes

dc, (削除) 30 (削除ここまで) 28 bytes

?[d5*2+d2%*+2/d1<f1+]dsfx1-p

This uses the formula from Jo King's answer, slightly adapted so we dup after adding 2.

##Explanation ? # read input [ d1<f ]dsfx # repeat until we reach 1 d52+d2%+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2 1+ # count iterations 1-p # decrement and print result

Explanation

? # read input
 [ d1<f ]dsfx # repeat until we reach 1 
 d5*2+d2%*+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2
 1+ # count iterations
 1-p # decrement and print result

Previous answer: 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

#Explanation

Explanation

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result

#dc, (削除) 30 (削除ここまで) 28 bytes

?[d5*2+d2%*+2/d1<f1+]dsfx1-p

This uses the formula from Jo King's answer, slightly adapted so we dup after adding 2.

##Explanation ? # read input [ d1<f ]dsfx # repeat until we reach 1 d52+d2%+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2 1+ # count iterations 1-p # decrement and print result


Previous answer: 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

#Explanation

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result

dc, (削除) 30 (削除ここまで) 28 bytes

?[d5*2+d2%*+2/d1<f1+]dsfx1-p

This uses the formula from Jo King's answer, slightly adapted so we dup after adding 2.

Explanation

? # read input
 [ d1<f ]dsfx # repeat until we reach 1 
 d5*2+d2%*+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2
 1+ # count iterations
 1-p # decrement and print result

Previous answer: 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

Explanation

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result
Explanations aren't runnable as-is
Source Link
Toby Speight
  • 7k
  • 1
  • 30
  • 43

#dc, (削除) 30 (削除ここまで) 28 bytes

?[d5*2+d2%*+2/d1<f1+]dsfx1-p

This uses the formula from Jo King's answer, slightly adapted so we dup after adding 2.

##Readable version##Explanation ? # read input [ d1<f ]dsfx # repeat until we reach 1 d52+d2%+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2 1+ # count iterations 1-p # decrement and print result


Previous answer: 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

Readable version

#Explanation

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result

#dc, (削除) 30 (削除ここまで) 28 bytes

?[d5*2+d2%*+2/d1<f1+]dsfx1-p

This uses the formula from Jo King's answer, slightly adapted so we dup after adding 2.

##Readable version ? # read input [ d1<f ]dsfx # repeat until we reach 1 d52+d2%+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2 1+ # count iterations 1-p # decrement and print result


Previous answer: 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

Readable version

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result

#dc, (削除) 30 (削除ここまで) 28 bytes

?[d5*2+d2%*+2/d1<f1+]dsfx1-p

This uses the formula from Jo King's answer, slightly adapted so we dup after adding 2.

##Explanation ? # read input [ d1<f ]dsfx # repeat until we reach 1 d52+d2%+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2 1+ # count iterations 1-p # decrement and print result


Previous answer: 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

#Explanation

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result
-2 bytes
Source Link
Toby Speight
  • 7k
  • 1
  • 30
  • 43

#dc, 30(削除) 30 (削除ここまで) 28 bytes

?[d5*2+d2%*+2/d1<f1+]dsfx1-p

This uses the formula from Jo King's answer , slightly adapted so we dup after adding 2.

##Readable version ? # read input [ d1<f ]dsfx # repeat until we reach 1 d52+d2%+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2 1+ # count iterations 1-p # decrement and print result


Previous answer: 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

Readable version

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result

#dc, 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

Readable version

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result

#dc, (削除) 30 (削除ここまで) 28 bytes

?[d5*2+d2%*+2/d1<f1+]dsfx1-p

This uses the formula from Jo King's answer , slightly adapted so we dup after adding 2.

##Readable version ? # read input [ d1<f ]dsfx # repeat until we reach 1 d52+d2%+2/ # n → (n + (5n+2)%2 * (5n+2)) / 2 1+ # count iterations 1-p # decrement and print result


Previous answer: 30 bytes

?[6*4+]sm[d2~1=md1!=f]dsfxz1-p

We keep all the intermediate results on the stack, then count the size of the stack. We save bytes by always doing the division by two, but if the remainder is 1, then we multiply by 6 and add 4 (3 for the remainders and 1 for the Collatz constant). The final stack count contains all the numbers we've seen; the number of operations is one less than that.

Readable version

? # input
[6*4+]sm # helper function
[d2~1=md1!=f]dsfx # recursion
z1-p # print result
Source Link
Toby Speight
  • 7k
  • 1
  • 30
  • 43
Loading

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