Advertisement
sci4me

SFML Pure Collatz

Feb 21st, 2016
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. let collatz = (n) -> {
  2. if(x % 2 == 0) {
  3. return n / 2;
  4. } else {
  5. return 3 * n + 1;
  6. }
  7. };
  8.  
  9. let steps = (n) -> {
  10. if(n <= 1) {
  11. return 0;
  12. }
  13.  
  14. let s = (a, b) -> {
  15. if(a == 1) {
  16. return b;
  17. }
  18.  
  19. return s(collatz(a), b + 1);
  20. };
  21.  
  22. return s(n, 0);
  23. };
  24.  
  25. print(steps(5));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement