From 11c9fba2c4698dc3e78baba82fefdc2300a657d8 Mon Sep 17 00:00:00 2001 From: Dominique Liberda Date: Fri, 9 Dec 2022 13:34:27 +0100 Subject: [PATCH] day 5, part 2 --- 05/02.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 05/README.md | 7 +++++++ 2 files changed, 53 insertions(+) create mode 100755 05/02.sh diff --git a/05/02.sh b/05/02.sh new file mode 100755 index 0000000..e385c9c --- /dev/null +++ b/05/02.sh @@ -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" + diff --git a/05/README.md b/05/README.md index 44754de..637245c 100644 --- a/05/README.md +++ b/05/README.md @@ -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 accept input from stdin (whereas I (Paula?) like to accept input from argv) + +## part 2 + +... remember L31? + +so I removed that `| rev`, and that did the trick for the 2nd part. +BOORIIIIING