Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Simple modulus math

Name: Anonymous 2011-01-22 7:16

Solve this prague, I'm having a brain fart.

anus :: Int -> [Int]

0 -> [1,2,3,4]
1 -> [2,3,4,1]
2 -> [3,4,1,2]
3 -> [4,1,2,3]
4 -> [1,2,3,4]
5 -> [2,3,4,1]
e t c...

Name: Anonymous 2011-01-22 9:17

>>1
(define (rotate x)
  (append (cdr x) (list (car x))))
(let loop ((i 0)
           (x '(1 2 3 4))
           (r '()))
  (if (> i 10) (reverse r)
      (loop (+ i 1) (rotate x) (cons x r))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List