Skip to content

Commit 917b487

Browse files
authored
Merge pull request #157 from Flipez/examples-aoc
Examples aoc
2 parents d70be5e + 390163c commit 917b487

File tree

14 files changed

+4427
-0
lines changed

14 files changed

+4427
-0
lines changed

examples/aoc/2018/day1.rl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def parseChanges(lines)
2+
changes = []
3+
foreach idx, line in lines
4+
changes.yoink(line.strip().plz_i())
5+
end
6+
return changes
7+
end
8+
9+
def part1(input)
10+
freq = 0
11+
foreach idx, change in parseChanges(input)
12+
freq = freq + change
13+
end
14+
return freq
15+
end
16+
17+
def part2(input)
18+
freqs = [0]
19+
changes = parseChanges(input)
20+
while (true)
21+
foreach idx, change in changes
22+
lastFreq = freqs[-1] + change
23+
if (freqs.index(lastFreq) != -1)
24+
return lastFreq
25+
end
26+
freqs.yoink(lastFreq)
27+
end
28+
end
29+
end
30+
31+
input = IO.open("day1.txt").lines()
32+
33+
puts(part1(input))
34+
puts(part2(input))

0 commit comments

Comments
 (0)