(import std.List) (let self-exponent (fun (x n acc) (if (> n 0) (self-exponent x (- n 1) (* x acc)) acc))) (let cache (list:map (list:iota 0 10) (fun (x) (if (= x 0) 0 (self-exponent x x 1))))) (let is_munchausen (fun (number) { (mut total 0) (mut n number) (mut continue true) (while (and (> n 0) continue) { (let digit (mod n 10)) (set total (+ total (@ cache digit))) (if (> total number) (set continue false) (set n (math:floor (/ n 10)))) }) (= total number) })) (let max_val 5000) (mut i 1) (while (< i max_val) { (if (is_munchausen i) (print i)) (set i (+ 1 i)) })