```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 ``` ```; ten-digit pandigital numbers divisible by 1 through 9 (define sort #f) (define merge #f) (let () (define dosort (lambda (pred? ls n) (if (= n 1) (list (car ls)) (let ((i (quotient n 2))) (domerge pred? (dosort pred? ls i) (dosort pred? (list-tail ls i) (- n i))))))) (define domerge (lambda (pred? l1 l2) (cond ((null? l1) l2) ((null? l2) l1) ((pred? (car l2) (car l1)) (cons (car l2) (domerge pred? l1 (cdr l2)))) (else (cons (car l1) (domerge pred? (cdr l1) l2)))))) (set! sort (lambda (pred? l) (if (null? l) l (dosort pred? l (length l))))) (set! merge (lambda (pred? l1 l2) (domerge pred? l1 l2)))) (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 (undigits ds . args) (let ((b (if (null? args) 10 (car args)))) (let loop ((ds ds) (n 0)) (if (null? ds) n (loop (cdr ds) (+ (* n b) (car ds))))))) (define (pandigital? n) (= (undigits (sort < (digits n))) 123456789)) (let loop ((n 1000001520) (i 2)) (when (positive? i) (cond ((pandigital? n) (display n) (newline) (loop (+ n 2520) (- i 1))) (else (loop (+ n 2520) i))))) (let loop ((n 9999997560) (i 2)) (when (positive? i) (cond ((pandigital? n) (display n) (newline) (loop (- n 2520) (- i 1))) (else (loop (- n 2520) i))))) ```
 ```1 2 3 4 ``` ```1234759680 1234857960 9876351240 9876134520 ```