day 12 part 1, FINALLY
[aoc_eblake.git] / 2015 / advent10.sh
blob3de30ab3e72c71bd2356c3fb3753ab4f2650b8b2
1 val=${1-1} rounds=${2-5}
2 echo "running $rounds iterations on initial input $val"
3 exec 3>&1
4 # visit rounds val
5 visit() {
6 echo "starting visit $@" >&3
7 if [[ $1 == 0 ]]; then
8 echo $val | sed 's/\(.\)/\1\n/g'
9 return
11 exec < <(visit $(($1 - 1)) $val)
12 read prev
13 lines=1
14 index=1
15 count=1
16 summary="($prev"
17 while read next; do
18 [[ ! $next ]] && continue
19 lines=$((lines + 1))
20 if [[ $lines -lt 70 ]]; then
21 summary+="$next"
22 elif [[ $lines == 70 ]]; then
23 summary+=...
25 if [[ $next == $prev ]]; then
26 count=$((count+1))
27 else
28 echo $count
29 echo $prev
30 prev=$next count=1
32 done
33 echo $count
34 echo $prev
35 echo "$summary)" >&3
36 echo "visit $1 parsed $lines bytes" >&3
38 echo "final length $(visit $rounds $val | wc -l)"