Thursday, March 1, 2012

MIT/GNU SCHEME PROGRAM FOR ARMSTRONG NUMBERS

;Copyright (C) 2010 Massachusetts Institute of Technology
;This is free software; see the source for copying conditions. There is NO warranty; not even
;for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

;Image saved on Tuesday March 9, 2010 at 9:43:38 PM
 ; Release 9.0.1 || Microcode 15.1 || Runtime 15.7 || Win32 1.8 || SF 4.41 || LIAR/i386 4.118
  ;Edwin 3.116
;You are in an interaction window of the Edwin editor.
;Type `C-h' for help, or `C-h t' for a tutorial.
;`C-h m' will describe some commands.
;`C-h' means: hold down the Ctrl key and type `h'.
;Package: (user)
(/ 25.0 7)
;Value: 3.5714285714285716


(define (armstrong? c) (if (= c (armstrong c)) #t #f))


(define (armstrong c) (if (< c 1) 0 (+ (cube (% 10 c)) (armstrong (divide c 10)))))
;Value: armstrong

(define (cube c) (* c c c))
;Value: cube

(define (% a c) (if (> a c) c (% a (- c a))))



;Value: %

(define (divide c a) (if (< c a) 0 (+ 1 (divide (- c a) a))))
;Value: divide

(divide 323 10)
;Value: 32
(% 3 2)
(% 10 323)






No comments:

Post a Comment