[ create a new paste ] login | about

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

programmingpraxis - Scheme, pasted on Sep 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
; torn numbers

(define (torn? n)
  (define (square x) (* x x))
  (let loop ((ten-power 10))
    (if (< n ten-power) #f
      (let ((a (quotient n ten-power))
            (b (modulo n ten-power)))
        (if (= (square (+ a b)) n) #t
          (loop (* ten-power 10)))))))

(do ((n 10 (+ n 1))) (#f)
  (when (torn? n) (display n) (newline)))


Output:
1
2
3
4
5
6
7
8
9
10
11
12
81
100
2025
3025
9801
10000
88209
494209
998001
1000000

Timeout


Create a new paste based on this one


Comments: