-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 10.sh
59 lines (50 loc) · 1.4 KB
/
Day 10.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
varlist=()
tribonacci=(1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136 5768 10609 19513 35890 66012)
i=0
while read line
do
varlist[i]=${line%?}
i=$((i+1))
done < "${1:-/dev/stdin}"
IFS=$'\n' varlist=($(sort -n <<<"${varlist[*]}"))
varlist[$(($i-1))]=$((${varlist[$(($i-2))]}+3))
last=0
count=0
ones=0
threes=0
consecOnes=0
possibilities=1
while [ "x${varlist[count]}" != "x" ]
do
step=$((${varlist[count]}-$last))
last=${varlist[count]}
if [ $step = 1 ]
then
ones=$(($ones+1))
consecOnes=$(($consecOnes+1))
echo "${varlist[count]} : step $step, consecOnes: $consecOnes"
else
options=1
if [ $step = 3 ]
then
threes=$(($threes+1))
if [ $consecOnes -gt 0 ]
then
options=${tribonacci[consecOnes]}
fi
else
if [ $consecOnes -gt 0 ]
then
options=$((${tribonacci[consecOnes]}+${tribonacci[$(($consecOnes-1))]}))
fi
fi
echo "${varlist[count]} : step $step, options: $options"
possibilities=$(($possibilities*$options))
consecOnes=0
fi
count=$(( $count + 1 ))
done
answer1=$(($ones*$threes))
echo "Answer 1: $ones * $threes = $answer1"
possibilities=$(($possibilities*${tribonacci[consecOnes]}))
echo "Answer 2: $possibilities"