27 lines
672 B
Text
27 lines
672 B
Text
load "bool.quox"
|
||
load "nat.quox"
|
||
load "string.quox"
|
||
load "list.quox"
|
||
load "io.quox"
|
||
|
||
|
||
def hash : ω.String → ℕ =
|
||
letω hash1 : ω.ℕ → ω.Char → ℕ =
|
||
λ n c ⇒ case char.ws? c return ℕ of {
|
||
'true ⇒ n;
|
||
'false ⇒ nat.mod (nat.times 17 (nat.plus (char.to-ℕ c) n)) 256
|
||
} in
|
||
string.foldlω ℕ 0 hash1
|
||
|
||
def split : ω.String → List String =
|
||
letω comma = char.from-ℕ 0x2C in
|
||
string.split (char.eq comma)
|
||
|
||
#[main]
|
||
def part1 =
|
||
io.bindω String True
|
||
(io.read-fileω "in/day15")
|
||
(λ s ⇒ io.dump ℕ (list.sum (list.mapω String ℕ hash (split s))))
|
||
|
||
|
||
def0 ShittyHashMap = Vec 8 (Vec 8 (Vec 8 (List (String × ℕ))))
|