[ create a new paste ] login | about

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

programmingpraxis - Scheme, pasted on Oct 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
; two-base palindromes

(define (digits n . args)
  (let ((b (if (null? args) 10 (car args))))
    (let loop ((n n) (d '()))
      (if (zero? n) d
          (loop (quotient n b)
                (cons (modulo n b) d))))))

(define (palin? n b)
  (let ((ds (digits n b)))
    (equal? ds (reverse ds))))

(do ((n 1 (+ n 1))) (#f)
  (when (and (palin? n 10) (palin? n 8))
    (display (digits n)) (display " ")
    (display (digits n 8)) (display " ")
    (newline)))


Output:
(1) (1) 
(2) (2) 
(3) (3) 
(4) (4) 
(5) (5) 
(6) (6) 
(7) (7) 
(9) (1 1) 
(1 2 1) (1 7 1) 
(2 9 2) (4 4 4) 
(3 3 3) (5 1 5) 
(3 7 3) (5 6 5) 
(4 1 4) (6 3 6) 
(5 8 5) (1 1 1 1) 
(3 6 6 3) (7 1 1 7) 
(8 7 7 8) (2 1 1 1 2) 
(1 3 1 3 1) (3 1 5 1 3) 
(1 3 3 3 1) (3 2 0 2 3) 
(2 6 4 6 2) (6 3 5 3 6) 
(2 6 6 6 2) (6 4 0 4 6) 
(3 0 1 0 3) (7 2 6 2 7) 
(3 0 3 0 3) (7 3 1 3 7) 
(2 0 7 7 0 2) (6 2 5 5 2 6) 
(6 2 8 8 2 6) (2 3 1 4 1 3 2) 
(6 6 0 0 6 6) (2 4 1 1 1 4 2) 
(1 4 9 6 9 4 1) (5 5 5 3 5 5 5) 
(1 9 3 5 3 9 1) (7 3 0 4 0 3 7) 
(1 9 7 0 7 9 1) (7 4 1 1 1 4 7) 

Timeout


Create a new paste based on this one


Comments: