Posted: Fri Mar 30, 2007 3:04 pm Post subject: Functional TYS
Write a program that will list all the factors of a given number. Only one variable may be used maximum. If you are writing this TYS in a procedureal/imperative language, take another crack at it afterwords in something from the functional realm. Good Luck!
Note: Functional Programmers - please don't post functional answers right away, let others post there replies first please, thanks
Sponsor Sponsor
Catalyst
Posted: Fri Mar 30, 2007 5:11 pm Post subject: Re: Functional TYS
i love c++ because it lets me write code like this while still having higher level features
Posted: Fri Mar 30, 2007 6:35 pm Post subject: Re: Functional TYS
Lisp:
(defun factor-find-start (N) (sort (factor-find N 1) #'<) )
(defun factor-find (N X) (cond ((> X (sqrt N))nil) ((zerop(mod N X)) (if(eq X (/ N X)) (cons X (factor-find N (1+ X))) (cons X (cons(/ N X)(factor-find N (1+ X)))) ) ) ( t (factor-find N (1+ X))) ) )