day 14 semi-golf, with missing fifth glyph
[aoc_eblake.git] / 2015 / advent20.sh
blobf62c802b670e1a29eeaeab1490541bf2f0d62eb9
1 house=${1-0}
2 target=${2-33100000}
3 got=0
4 max=0
5 while [[ $got -lt $target ]]; do
6 (( house++ % 1000 )) || echo " $((house-1)) at $got, max $max"
7 if [[ $house == 1 ]]; then
8 got=11
9 max=11
10 continue
12 got=$(((house + (house <= 50))*11))
13 odd=$((house&1))
14 i=$((2+$odd))
15 while (( i <= 50 && i*i < house )); do
16 if ! (( house % i )); then
17 # echo " $house $i"
18 got=$((got + (house/i)*11))
19 ((house/i <= 50)) && got=$((got + i*11))
21 i=$((i+1+odd))
22 done
23 (( i <= 50 && i*i == house )) && got=$((got + i*11))
24 # echo " house $house got $got"
25 [[ $max -lt $got ]] && max=$got
26 done
27 echo "house $house got $got gifts"