8 filename="${1:-example.txt}"
14 while read -u 3 line; do
15 if [ "$line" == "" ]; then
20 if [ $x -gt $max_x ]; then
23 if [ $y -gt $max_y ]; then
32 while read -u 3 line; do
33 folds+=(${line#fold along })
37 for (( y=0; y<$max_y; y++ )); do
38 for (( x=0; x<$max_x; x++ )); do
39 offset=$(((y*$max_x) + $x))
40 case "${map[$offset]}" in
56 for (( a=0; a<$(($max_x * $max_y)); a++ )); do
60 for point in "${points[@]}"; do
63 offset=$((($y*$max_x)+$x))
70 local point=${line#*=}
77 local new_max_x=$(($max_x - $point - 1))
78 if [ $point -gt $new_max_x ]; then
81 local adj=$((max_x % 2))
82 for (( y=0; y<$max_y; y++ )); do
83 for (( x=0; x<$new_max_x; x++ )); do
84 x_1=$(($point - $new_max_x + $x))
85 x_2=$(($max_x - ($new_max_x - $point) - $x - $adj))
86 offset_1=$((($y * $max_x) + $x_1))
87 offset_2=$((($y * $max_x) + $x_2))
88 if [ $x_1 -lt 0 ]; then
91 if [ $x_2 -ge $max_x ]; then
94 new_map+=($((${map[$offset_1]} | ${map[$offset_2]})))
101 local new_max_y=$(($max_y - $point - 1))
102 if [ $point -gt $new_max_y ]; then
105 local adj=$((max_y % 2))
106 for (( y=0; y<$new_max_y; y++ )); do
107 # do the y offsets here
108 y_1=$(($point - $new_max_y + $y))
109 y_2=$(($max_y - ($new_max_y - $point) - $y - $adj))
110 offset_1=$(($y_1 * $max_x))
111 offset_2=$(($y_2 * $max_x))
112 if [ $y_1 -lt 0 ]; then
115 if [ $y_2 -ge $max_y ]; then
118 for (( x=0; x<$max_x; x++ )); do
119 off_1=$(($offset_1+$x))
120 off_2=$(($offset_2+$x))
121 new_map+=($((${map[$off_1]} | ${map[$off_2]})))
124 map=("${new_map[@]}")
132 for point in "${map[@]}"; do
146 echo "There are $(get_points_count) dots visible after first fold"
147 for (( f=1; f<${#folds[@]}; f++ )); do
148 echo "Doing fold $((f+1)) of ${#folds[@]}"
152 echo "After all folds:"