[ create a new paste ] login | about

Link: http://codepad.org/eBHSOzIP    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Oct 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
; magic 1089

(define (rev n)
  (let loop ((n n) (x 0))
    (if (zero? n) x
      (loop (quotient n 10)
            (+ (* x 10) (modulo n 10))))))

(define (magic n)
  (let ((d (- n (rev n))))
    (+ d (rev d))))

(display (magic 532)) (newline)
(display (magic 235)) (newline)
(display (magic 854)) (newline)


Output:
1
2
3
1089
21
1089


Create a new paste based on this one


Comments: