From 21ee11d3df3000a77d5b36d3c7e0a18d9a07d599 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 6 Dec 2022 13:43:46 +0200 Subject: Add stdlib stuff, aoc22_1 example --- examples/aoc22_1.milch | 29 +++++++++++++++++++++++++++++ examples/aoc22_1.txt | 14 ++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 examples/aoc22_1.milch create mode 100644 examples/aoc22_1.txt (limited to 'examples') diff --git a/examples/aoc22_1.milch b/examples/aoc22_1.milch new file mode 100644 index 0000000..4170661 --- /dev/null +++ b/examples/aoc22_1.milch @@ -0,0 +1,29 @@ +(import! "stdlib/common.milch") + +;; utils + +; convert ["a" "b" "c"] into "abc" +(let! str-from-vec (\[vec] + (foldr concat "" vec))) + +;; solution + +(let! sample-path "examples/aoc22_1.txt") +(let! sample-input (read-file! sample-path)) + +(print-fmt! "Read {0} characters from \"{1}\"\n" [ + (len sample-input) + sample-path]) + +(let! sample-vec (to-vec sample-input)) + +(let! result1 (pipe sample-vec [ + (split-by "\n") + (map str-from-vec) + (split-by "") + (map (map parse-int)) + (map (foldr + 0)) + max +])) + +(print-fmt! "Result 1: {0}\n" [result1]) diff --git a/examples/aoc22_1.txt b/examples/aoc22_1.txt new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/examples/aoc22_1.txt @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 -- cgit v1.3