diff options
| Commit | 9733f1336ee8054767a2516744cbd187cfa3b851 (patch) | |
|---|---|---|
| Author | 2022-10-19 18:25:45 +0300 | |
| Committer | 2022-10-19 18:25:45 +0300 | |
| Files | e5651ffd05431034d6e553911ca99b8d7f002b45 | |
| uni-projects-9733f1336ee8054767a2516744cbd187cfa3b851.tar uni-projects-9733f1336ee8054767a2516744cbd187cfa3b851.tar.gz uni-projects-9733f1336ee8054767a2516744cbd187cfa3b851.zip | ||
| Parent | 48cdff17bb05b1774c20601698fd57e719030f87 (diff) | |
[FP/HW1] Reworked sum-digits to be iterable and changed formatting of count-specials
1 files changed, 9 insertions, 8 deletions
| -rw-r--r-- | Year 2/Functional Programming/hw1.rkt | 17 |
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 |
