Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Functional Programming
diff options
context:
space:
mode:
1 files changed, 9 insertions, 8 deletions
-rw-r--r--Year 2/Functional Programming/hw1.rkt17
diff --git a/Year 2/Functional Programming/hw1.rkt b/Year 2/Functional Programming/hw1.rkt
index 548e441..3d3e0e2 100644
--- a/Year 2/Functional Programming/hw1.rkt
+++ b/Year 2/Functional Programming/hw1.rkt
@@ -3,18 +3,19 @@
;;; Задача 1
(define (sum-digits n)
- (if (= n 0)
- 0
- (+ (sum-digits (quotient n 10)) (remainder n 10))))
+ (define (calc-iter n total)
+ (if (= n 0)
+ total
+ (calc-iter (quotient n 10) (+ total (remainder n 10)))))
+ (calc-iter n 0))
(define (count-specials k a b)
(if (or (<= k 0) (> a b))
0
- (+
- (count-specials k (add1 a) b)
- (if (and (= (remainder a k) 0) (= (remainder (sum-digits a) k) 0))
- 1
- 0))))
+ (+ (count-specials k (add1 a) b)
+ (if (and (= 0 (remainder a k))
+ (= 0 (remainder (sum-digits a) k)))
+ 1 0))))
;;; Задача 2