RE: [Golfing] Collatz Conjecture 08-22-2015, 02:51 AM
#23
(08-22-2015, 02:42 AM)Shebang Wrote: Sure!
So, in this instance, h is the character that triggers the while-loop. What it does is pop off the top three items from the stack:In this case:
- A string, which is the body of the while loop.
- A string, which is the condition the while loop executes on
- A value, which is passed to the condition and body.
- _2%;_3*1+;2/?p is the body of the loop.
- 1> is the condition
- i is the value (coming from user input in this case).
So, what this code does is:
- Take user input.
- While this user input is greater than 1:
- Check if it's divisible by 2.
- If so, divide it by 2.
- If not, multiply by 3 and add 1.
- Print out the result.
That's basically it!It's essentially a direct conversion of the Python code.
Exact conversation of the JS code, too.






It's essentially a direct conversion of the Python code.![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)