day 5, part 1
This commit is contained in:
parent
c23d3346ea
commit
5e5a92d0e7
46
05/01.sh
Executable file
46
05/01.sh
Executable 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]="$(echo ${asd[@]:0:${ins[1]}}| rev) ${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"
|
||||||
|
|
17
05/README.md
Normal file
17
05/README.md
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# day 05 (actually 09, oops)
|
||||||
|
|
||||||
|
again, put your things in /tmp/05
|
||||||
|
|
||||||
|
## part 1
|
||||||
|
|
||||||
|
biggest part of what threw me off is the fact that I can't read.
|
||||||
|
I have assumed that multiple crate moves were meant as
|
||||||
|
"grab n crates at once", while in reality they meant "grab one,
|
||||||
|
then another, then another..."
|
||||||
|
That's why L31 has that funky subshell with a rev.
|
||||||
|
|
||||||
|
Wrapping everything in () was a fun hack I thought about to parse
|
||||||
|
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
|
||||||
|
accept input from stdin (whereas I (Paula?) like to accept input
|
||||||
|
from argv)
|
Loading…
Reference in a new issue