aboutsummaryrefslogtreecommitdiffstats
path: root/examples/aoc22_1.milch
blob: 417066147b600ce33b527a3046e987d076b48d58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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])