Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function collatz(n) {
- if(n % 2 == 0) {
- return n / 2;
- } else {
- return 3 * n + 1;
- }
- }
- function steps(n) {
- if(n <= 1) {
- return 0;
- }
- function s1(a, b) {
- if(a == 1) {
- return b;
- }
- return s1(collatz(a), b + 1);
- }
- return s1(n, 0);
- }
- console.log(steps(17));
Add Comment
Please, Sign In to add comment