Add day 1 part 2 (awk)
This commit is contained in:
parent
da1d55a240
commit
b68651c4f8
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/awk -f
|
||||
|
||||
function calc_fuel(mass) {
|
||||
return int(mass / 3) - 2;
|
||||
}
|
||||
|
||||
{
|
||||
c = calc_fuel($1);
|
||||
while (c > 0) {
|
||||
s += c;
|
||||
c = calc_fuel(c);
|
||||
}
|
||||
}
|
||||
END {
|
||||
print s;
|
||||
}
|
Loading…
Reference in New Issue
Block a user