File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
tests/unittests/resources/RosettaSuite Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ (import std.List)
2+
3+ (let self-exponent (fun (x n acc)
4+ (if (> n 0)
5+ (self-exponent x (- n 1) (* x acc))
6+ acc)))
7+
8+ (let cache (list:map (list:iota 0 10) (fun (x) (if (= x 0) 0 (self-exponent x x 1)))))
9+
10+ (let is_munchhausen (fun (number) {
11+ (mut total 0)
12+ (mut n number)
13+ (mut continue true)
14+
15+ (while (and (> n 0) continue) {
16+ (let digit (mod n 10))
17+ (set total (+ total (@ cache digit)))
18+ (if (> total number)
19+ (set continue false)
20+ (set n (math:floor (/ n 10)))) })
21+
22+ (= total number) }))
23+
24+
25+ (assert (is_munchhausen 1) "1 is a Munchhausen number")
26+ (assert (is_munchhausen 3435) "3435 is a Munchhausen number")
27+
28+ (assert (not (is_munchhausen 677)) "677 is not a Munchhausen number")
You can’t perform that action at this time.
0 commit comments