You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
386 B
Bash
27 lines
386 B
Bash
5 years ago
|
#!/usr/bin/env bash
|
||
|
cd "$(dirname "$0")";
|
||
|
|
||
|
function calc_requirement() {
|
||
|
local input=$1;
|
||
|
|
||
|
a=$((input / 3));
|
||
|
a=$((a - 2));
|
||
|
|
||
|
if [ "$a" -gt 0 ]; then
|
||
|
b=$(calc_requirement "$a");
|
||
|
a=$((a + b));
|
||
|
else
|
||
|
a=0;
|
||
|
fi
|
||
|
|
||
|
echo $a;
|
||
|
}
|
||
|
|
||
|
output=0;
|
||
|
while read nr; do
|
||
|
a=$(calc_requirement "$nr");
|
||
|
output=$((a + output));
|
||
|
done < ./input
|
||
|
|
||
|
echo $output;
|