This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun num_check (x) (if (or (eq (mod x 3) 0) (eq (mod x 5) 0)) x 0)) | |
(defun sum(x) (if (eq x 3) 3 (+ (num_check x) (sum (- x 1))))) | |
(sum 3) | |
3 | |
(sum 5) | |
8 | |
(sum 10) | |
33 | |
(sum 1000) | |
Debugger entered--Lisp error: (error "Lisp nesting exceeds `max-lisp-eval-depth'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) Server VM, Java 1.6.0_20). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> def num_check(n: Int):Int = if ( (n % 3) == 0 || (n % 5) == 0 ) n else 0 | |
num_check: (n: Int)Int | |
scala> def do_sum(x: Int):Int = if ( x == 3 ) 3 else num_check(x) + do_sum(x - 1) | |
do_sum: (x: Int)Int | |
scala> do_sum(10) | |
res0: Int = 33 | |
scala> do_sum(100) | |
res1: Int = 2418 | |
scala> do_sum(1000) | |
res2: Int = 234168 |
No comments:
Post a Comment