diff options
author | Marvin Borner | 2024-03-23 19:18:16 +0100 |
---|---|---|
committer | Marvin Borner | 2024-03-23 19:18:16 +0100 |
commit | 7bfc78b122ad9cbb65eed16f7de4d4021547c2a8 (patch) | |
tree | e45a22aeddb12257a94e32083ed10dfa3a0da66e /samples/euler/004.bruijn | |
parent | fc9980e5e19602748b8cc596cdd07c02ac2889f1 (diff) |
Some Project Euler solutions
Diffstat (limited to 'samples/euler/004.bruijn')
-rw-r--r-- | samples/euler/004.bruijn | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/samples/euler/004.bruijn b/samples/euler/004.bruijn new file mode 100644 index 0000000..e04cb4c --- /dev/null +++ b/samples/euler/004.bruijn @@ -0,0 +1,19 @@ +# TODO: This has serious performance problems + +:import std/Combinator . +:import std/List . +:import std/Math . + +# palindrome? S.number→string → [S.eq? S.<~>0 0] + +palindrome? [y [[[&[[>?2 (4 (3 ⋅ (+10) + 0) 1) (3 =? 5)]] (quot-rem 0 (+10))]]] (+0) 0] + +# combs [[S.concat-map [S.map (mul 0) ({ 0 → 1 })] ({ ((+10) ** --1) → 0 })] --((+10) ** 0)] + +solve [[y [[[0 =? 3 1 rec]]] empty ((+10) ** --1)] ((+10) ** 0)] → lmax + rec 2 (comb ++ 1) ++0 + comb y [[[0 =? 6 1 (2 ([palindrome? 0 (0 : 2) 2] (3 ⋅ 0)) ++0)]]] empty 0 + +:test ((solve (+2)) =? (+9009)) ([[1]]) + +main [solve (+3)] |