11 while read -u 3 -N $((image_width*$image_height)) layer; do
12 layers[$layer_number]=$layer
13 layer_number=$((layer_number+1))
16 echo "Got $layer_number layers"
22 countstring="$(echo -n "$data" | sed -e 's#[^'$digit']##g;')"
30 for layer_number in ${!layers[@]}; do
31 count=$(get_count 0 ${layers[$layer_number]})
32 if [ $count -lt $lowest_zero_count ] || [ $lowest_zero_count -eq -1 ]; then
33 lowest_zero_count=$count
34 zero_count_layer=$layer_number
38 one_count=$(get_count 1 ${layers[$zero_count_layer]})
39 two_count=$(get_count 2 ${layers[$zero_count_layer]})
41 echo "Layer $zero_count_layer has the fewest zeros ($lowest_zero_count)"
42 echo "Answer of number of 1s * number of 2s: $one_count * $two_count = $((one_count * two_count))"
46 for (( y=0; y<$image_height; y++ )); do
47 offset=$(($image_width*$y))
48 for (( x=0; x<$image_width; x++ )); do
49 for (( layer=1; layer<=$layer_number; layer++ )); do
50 data=${layers[$layer]}
51 case ${data:$((offset+x)):1} in
66 printf "=%.0s" {0..26}
68 for (( y=0; y<$image_height; y++ )); do
69 offset=$(($image_width*$y))
70 echo "|${image:$offset:25}|"
72 printf "=%.0s" {0..26}