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
95 new_offset=$((($y * $new_max_x) + $x))
96 new_map[$new_offset]=$((${map[$offset_1]} | ${map[$offset_2]}))
103 local new_max_y=$(($max_y - $point - 1))
104 if [ $point -gt $new_max_y ]; then
107 local adj=$((max_y % 2))
108 for (( y=0; y<$new_max_y; y++ )); do
109 # do the y offsets here
110 y_1=$(($point - $new_max_y + $y))
111 y_2=$(($max_y - ($new_max_y - $point) - $y - $adj))
112 offset_1=$(($y_1 * $max_x))
113 offset_2=$(($y_2 * $max_x))
114 if [ $y_1 -lt 0 ]; then
117 if [ $y_2 -ge $max_y ]; then
120 for (( x=0; x<$max_x; x++ )); do
121 off_1=$(($offset_1+$x))
122 off_2=$(($offset_2+$x))
124 new_offset=$((($y * $max_x) + $x))
125 new_map[$new_offset]=$((${map[$off_1]} | ${map[$off_2]}))
128 map=("${new_map[@]}")
136 for point in "${map[@]}"; do
150 echo "There are $(get_points_count) dots visible after first fold"
151 for (( f=1; f<${#folds[@]}; f++ )); do
152 echo "Doing fold $((f+1)) of ${#folds[@]}"
156 echo "After all folds:"