Day 13
This commit is contained in:
44
13/01.sh
Executable file
44
13/01.sh
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
declare -A dots
|
||||||
|
folds=()
|
||||||
|
|
||||||
|
while read line; do
|
||||||
|
if [[ $line == *','* ]]; then
|
||||||
|
dots[$line]=1
|
||||||
|
else
|
||||||
|
folds+=( $(sed 's/fold along //' <<< $line) )
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
fold=${folds[0]}
|
||||||
|
fold_axis=$(sed 's/=.*$//' <<< $fold)
|
||||||
|
fold_coord=$(sed 's/^.*=//' <<< $fold)
|
||||||
|
new_dots=()
|
||||||
|
todel_dots=()
|
||||||
|
|
||||||
|
for dot in ${!dots[@]}; do
|
||||||
|
dot_x=$(sed 's/,.*$//' <<< $dot)
|
||||||
|
dot_y=$(sed 's/^.*,//' <<< $dot)
|
||||||
|
if [[ $fold_axis == 'x' ]]; then
|
||||||
|
if [ $dot_x -gt $fold_coord ]; then
|
||||||
|
new_dots+=( "$((fold_coord*2-dot_x)),$dot_y" )
|
||||||
|
todel_dots+=( $dot )
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ $dot_y -gt $fold_coord ]; then
|
||||||
|
new_dots+=( "$dot_x,$((fold_coord*2-dot_y))" )
|
||||||
|
todel_dots+=( $dot )
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for todel_dot in ${todel_dots[@]}; do
|
||||||
|
unset dots[$todel_dot]
|
||||||
|
done
|
||||||
|
|
||||||
|
for new_dot in ${new_dots[@]}; do
|
||||||
|
dots[$new_dot]=1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ${#dots[@]}
|
||||||
62
13/02.sh
Executable file
62
13/02.sh
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
declare -A dots
|
||||||
|
folds=()
|
||||||
|
min_x=-1
|
||||||
|
min_y=-1
|
||||||
|
|
||||||
|
while read line; do
|
||||||
|
if [[ $line == *','* ]]; then
|
||||||
|
dots[$line]=1
|
||||||
|
else
|
||||||
|
folds+=( $(sed 's/fold along //' <<< $line) )
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for fold in ${folds[@]}; do
|
||||||
|
fold_axis=$(sed 's/=.*$//' <<< $fold)
|
||||||
|
fold_coord=$(sed 's/^.*=//' <<< $fold)
|
||||||
|
new_dots=()
|
||||||
|
todel_dots=()
|
||||||
|
|
||||||
|
if [[ $fold_axis == 'x' ]] && { [ $fold_coord -lt $min_x ] || [ $min_x -eq -1 ] ;}; then
|
||||||
|
min_x=$fold_coord
|
||||||
|
elif [[ $fold_axis == 'y' ]] && { [ $fold_coord -lt $min_y ] || [ $min_y -eq -1 ] ;}; then
|
||||||
|
min_y=$fold_coord
|
||||||
|
fi
|
||||||
|
|
||||||
|
for dot in ${!dots[@]}; do
|
||||||
|
dot_x=$(sed 's/,.*$//' <<< $dot)
|
||||||
|
dot_y=$(sed 's/^.*,//' <<< $dot)
|
||||||
|
if [[ $fold_axis == 'x' ]]; then
|
||||||
|
if [ $dot_x -gt $fold_coord ]; then
|
||||||
|
new_dots+=( "$((fold_coord*2-dot_x)),$dot_y" )
|
||||||
|
todel_dots+=( $dot )
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ $dot_y -gt $fold_coord ]; then
|
||||||
|
new_dots+=( "$dot_x,$((fold_coord*2-dot_y))" )
|
||||||
|
todel_dots+=( $dot )
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for todel_dot in ${todel_dots[@]}; do
|
||||||
|
unset dots[$todel_dot]
|
||||||
|
done
|
||||||
|
|
||||||
|
for new_dot in ${new_dots[@]}; do
|
||||||
|
dots[$new_dot]=1
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
for j in $(seq 0 $min_y); do
|
||||||
|
for i in $(seq 0 $min_x); do
|
||||||
|
if [ ${dots["$i,$j"]} ]; then
|
||||||
|
echo -n '#'
|
||||||
|
else
|
||||||
|
echo -n ' '
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user