summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
f1b1e23)
- Use an associative array rather than an indexed array
- Work from the fold outwards rather than the edge inwards
display_map() {
for (( y=0; y<$max_y; y++ )); do
for (( x=0; x<$max_x; x++ )); do
display_map() {
for (( y=0; y<$max_y; y++ )); do
for (( x=0; x<$max_x; x++ )); do
- offset=$(((y*$max_x) + $x))
- case "${map[$offset]}" in
+ case "${map[$x,$y]}" in
-for (( a=0; a<$(($max_x * $max_y)); a++ )); do
- map[$a]=0
+for (( y=0; y<$max_y; y++ )); do
+ for (( x=0; x<$max_x; x++ )); do
+ map["$x,$y"]=0
+ done
done
for point in "${points[@]}"; do
x=${point%,*}
y=${point#*,}
done
for point in "${points[@]}"; do
x=${point%,*}
y=${point#*,}
- offset=$((($y*$max_x)+$x))
- map[$offset]=1
done
fold() {
local line="$1"
local axis=${line%=*}
local point=${line#*=}
done
fold() {
local line="$1"
local axis=${line%=*}
local point=${line#*=}
if [ $point -gt $new_max_x ]; then
new_max_x=$point
fi
if [ $point -gt $new_max_x ]; then
new_max_x=$point
fi
- local adj=$((max_x % 2))
for (( y=0; y<$max_y; y++ )); do
for (( x=0; x<$new_max_x; x++ )); do
for (( y=0; y<$max_y; y++ )); do
for (( x=0; x<$new_max_x; x++ )); do
- x_1=$(($point - $new_max_x + $x))
- x_2=$(($max_x - ($new_max_x - $point) - $x - $adj))
- offset_1=$((($y * $max_x) + $x_1))
- offset_2=$((($y * $max_x) + $x_2))
+ # be sensible instead of insane, work from the middle out
+ x_1=$(($point-$x-1)) # always one left of the point
+ x_2=$(($point+$x+1)) # always one right of the point
fi
if [ $x_2 -ge $max_x ]; then
fi
if [ $x_2 -ge $max_x ]; then
- new_map+=($((${map[$offset_1]} | ${map[$offset_2]})))
+ new_x=$(($new_max_x-$x-1)) # work from the right of the new image, left
+ new_map["$new_x,$y"]=$((${map["$x_1,$y"]} | ${map["$x_2,$y"]}))
if [ $point -gt $new_max_y ]; then
new_max_y=$point
fi
if [ $point -gt $new_max_y ]; then
new_max_y=$point
fi
- local adj=$((max_y % 2))
for (( y=0; y<$new_max_y; y++ )); do
for (( y=0; y<$new_max_y; y++ )); do
- # do the y offsets here
- y_1=$(($point - $new_max_y + $y))
- y_2=$(($max_y - ($new_max_y - $point) - $y - $adj))
- offset_1=$(($y_1 * $max_x))
- offset_2=$(($y_2 * $max_x))
+ y_1=$(($point-$y-1)) # always above the fold
+ y_2=$(($point+$y+1)) # always below the fold
fi
if [ $y_2 -ge $max_y ]; then
fi
if [ $y_2 -ge $max_y ]; then
+ new_y=$(($new_max_y-$y-1)) # work from the bottom of the new image, up
for (( x=0; x<$max_x; x++ )); do
for (( x=0; x<$max_x; x++ )); do
- off_1=$(($offset_1+$x))
- off_2=$(($offset_2+$x))
- new_map+=($((${map[$off_1]} | ${map[$off_2]})))
+ new_map["$x,$new_y"]=$((${map["$x,$y_1"]} | ${map["$x,$y_2"]}))
+
+ for k in "${!new_map[@]}"; do
+ map[$k]=${new_map[$k]}
+ done
}
get_points_count() {
local count=0
}
get_points_count() {
local count=0
- for point in "${map[@]}"; do
- ((count+=$point))
+ for (( y=0; y<$max_y; y++ )); do
+ for (( x=0; x<$max_x; x++ )); do
+ ((count+=${map[$x,$y]}))
+ done
-echo
-#display_map
-echo
echo "There are $(get_points_count) dots visible after first fold"
for (( f=1; f<${#folds[@]}; f++ )); do
echo "Doing fold $((f+1)) of ${#folds[@]}"
echo "There are $(get_points_count) dots visible after first fold"
for (( f=1; f<${#folds[@]}; f++ )); do
echo "Doing fold $((f+1)) of ${#folds[@]}"