day 5, part 2

This commit is contained in:
Dominique Liberda 2022-12-09 13:34:27 +01:00
parent 5e5a92d0e7
commit 11c9fba2c4
2 changed files with 53 additions and 0 deletions

46
05/02.sh Executable file
View file

@ -0,0 +1,46 @@
#!/bin/bash
# still Paula fronting! i think!
data="$(cat /tmp/05 | sed 's/ / _ /g;s/\[//g;s/\]//g')"
x=0
IFS=$'\n'
(
while read line; do
[[ "$line" == '1 '* ]] && break
IFS=' '
uwu=($line)
for (( i=0; i<${#uwu[@]}; i++ )); do
[[ "${uwu[$i]}" != _ ]] && meow[$i]="${meow[$i]} ${uwu[$i]}"
done
done
read line;
while read line; do
ins=($line)
from=$((${ins[3]}-1))
to=$((${ins[5]}-1))
asd=(${meow[$from]})
echo "moving ${ins[1]} things from ${ins[3]} to ${ins[5]}"
echo "from, initial: ${meow[$from]}"
echo "what? ${asd[@]:0:${ins[1]}}"
echo "to, initial: ${meow[$to]}"
meow[$from]=${asd[@]:${ins[1]}:${#asd[@]}}
meow[$to]="${asd[@]:0:${ins[1]}} ${meow[$to]}"
echo "from, after: ${meow[$from]}"
echo "to, after: ${meow[$to]}"
echo ---
done
IFS=' '
x=''
for (( i=0; i<${#meow[@]}; i++ )); do
a=(${meow[$i]})
echo "$i: ${meow[$i]}"
x="$x${a[0]}"
done
echo "$x"
) <<< "$data"

View file

@ -15,3 +15,10 @@ the header separately from the rest of the code - probably wouldn't
be needed if Tulip was fronting and writing the code, she likes to be needed if Tulip was fronting and writing the code, she likes to
accept input from stdin (whereas I (Paula?) like to accept input accept input from stdin (whereas I (Paula?) like to accept input
from argv) from argv)
## part 2
... remember L31?
so I removed that `| rev`, and that did the trick for the 2nd part.
BOORIIIIING