about summary refs log tree commit diff
path: root/others/volume1/086.scm
blob: a45a81db6b07f5e476ae5223fdf7b93ae93f6a9c (plain) (blame)
1
2
3
4
5
6
7
(define (collatz n output)
  (if (> n 1)
      (if (= (remainder n 2) 0)
          (collatz (quotient n 2) (append output '("x 2\n")))
          (collatz (+ (* n 3) 1) (append output '("div 3\n"))))
      output))
(for-each display (reverse (collatz (read) '())))