Scheme Source Code

; Author: Hannes du Plooy
; Date: 8 October 2013
; Objective: To solve the following
;  ONE
;  ONE
;  ONE
; +ONE
; ----
;  TEN

(define (println lst)
    (do ((lst2 lst (cdr lst2)))
        ((null? lst2))
        (display (car lst2)))
    (newline))
    
(define done #f)

(do ((O 1 (+ O 1)))
    ((or (>= O 10) done))
    (do ((E 0 (+ E 1)))
        ((or (>= E 10) done))
        (if (not (= O E))
            (let* ((tmp1 (* E 4))
                   (carry1 (floor (/ tmp1 10)))
                   (N (remainder tmp1 10))
                   (tmp2 (+ carry1 (* N 4)))
                   (carry2 (floor (/ tmp2 10)))
                   (E2 (remainder tmp2 10))
                   (T (+ carry2 (* O 4))))
                  (if (not (or (= N O) (= N E) (not (= E E2)) (>= T 10) (= T O) (= T E) (= T N)))
                    (begin
                      (set! done #t)
                      (display "Answer is")(newline)(newline)
                      (println (list #\space O N E))
                      (println (list #\space O N E))
                      (println (list #\space O N E))
                      (println (list #\+ O N E))
                      (display "----")(newline)
                      (println (list #\space T E N))
                    )
                   )
            )
        )
    )
)