Browse Source

Day 1

master
William Davis 9 months ago
commit
c22786bac4
  1. 2000
      01/data
  2. 25
      01/main.awk

2000
01/data

File diff suppressed because it is too large Load Diff

25
01/main.awk

@ -0,0 +1,25 @@
BEGIN { last = "a million" }
{
# problem 1
if ( $0 > last ) problem_1_answer++
last = $0
# problem 2
{ lines[++count] = $0 }
}
END {
prev_total = "a billion"
for ( i = 1; i <= count - 2; i++ ) {
current_total = lines[i] + lines[i + 1] + lines[i + 2]
if ( current_total > prev_total ) problem_2_answer++
prev_total = current_total
}
print problem_1_answer # 1655
print problem_2_answer # 1683
}
Loading…
Cancel
Save