Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let collatz = (n) -> {
- if(x % 2 == 0) {
- return n / 2;
- } else {
- return 3 * n + 1;
- }
- };
- let steps = (n) -> {
- if(n <= 1) {
- return 0;
- }
- let s = (a, b) -> {
- if(a == 1) {
- return b;
- }
- return s(collatz(a), b + 1);
- };
- return s(n, 0);
- };
- print(steps(5));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement