advent-of-code/2019/01/day1.awk

20 lines
259 B
Awk
Raw Permalink Normal View History

2019-12-01 06:47:41 +01:00
#!/usr/bin/awk -f
2019-12-01 07:00:45 +01:00
function calc_fuel(mass) {
return int(mass / 3) - 2;
}
2019-12-01 06:47:41 +01:00
{
2019-12-01 07:00:45 +01:00
c = calc_fuel($1);
p1 += c;
while (c > 0) {
p2 += c;
c = calc_fuel(c);
}
2019-12-01 06:47:41 +01:00
}
2019-12-01 21:04:00 +01:00
2019-12-01 06:47:41 +01:00
END {
2019-12-01 07:00:45 +01:00
printf("Part 1: %s\n", p1)
printf("Part 2: %s\n", p2)
2019-12-01 06:47:41 +01:00
}