[ create a new paste ] login | about

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

programmingpraxis - Scheme, pasted on Oct 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(define (pandigital? . xs)
  (let ((ds (make-vector 10 #f)))1
    (let x-loop ((xs xs))
      (if (null? xs) #t
        (let d-loop ((x (car xs)))
          (if (zero? x) (x-loop (cdr xs))
            (let ((q (quotient x 10))
                  (r (remainder x 10)))
              (if (vector-ref ds r) #f
                (begin (vector-set! ds r #t)
                       (d-loop q))))))))))

(time (begin (display
  (let a-loop ((a 100))
    (let b-loop ((b (+ a 1)))
      (if (= b 1000) (a-loop (+ a 1))
        (let ((c (+ a b)))
          (if (and (< 999 c) (pandigital? a b c)) a
            (b-loop (+ b 1)))))))) (newline)))


Output:
1
2
246
cpu time: 10 real time: 469 gc time: 0


Create a new paste based on this one


Comments: