advent-of-code/lib/shared.moon

25 lines
432 B
Plaintext
Raw Permalink Normal View History

2019-12-10 14:15:38 -06:00
export input_for_day, input_matcher, reduce
read_whole_file = =>
f = assert io.open @, "rb"
content = f\read "*all"
f\close()
content
input_for_day = =>
read_whole_file "input/#{@}.txt"
input_matcher = (pattern) =>
contents = read_whole_file "input/#{@}.txt"
contents\gmatch pattern
reduce = (initial, f) =>
acc = initial
for e in @
if "table" == type e
acc = f acc, unpack e
else
acc = f acc, e
acc