X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2019.git/blobdiff_plain/5f982cb107e2c59c80b87efa0fcc0abff639bb90..4ac2392b4fa89d2a9372a8c142882ab068cb4ead:/day5/computer.sh diff --git a/day5/computer.sh b/day5/computer.sh index e0eab88..529af8a 100644 --- a/day5/computer.sh +++ b/day5/computer.sh @@ -23,6 +23,7 @@ run_program() { param_count=3 case $instruction in 01|02) + # 01 - add, 02 multiply symbol="+" if [ $instruction == "02" ]; then symbol="*" @@ -38,12 +39,14 @@ run_program() { data[$res_loc]=$(($val1 $symbol $val2)) ;; 03) + # 03 - read input read -p "input: " input res_loc=${data[$((pos+1))]} data[$res_loc]=$input param_count=1 ;; 04) + # 04 - output if [ ${immediate[1]} -eq 1 ]; then echo ${data[$((pos+1))]} else @@ -53,6 +56,7 @@ run_program() { param_count=1 ;; 05|06) + # 05 - jump-if-true, 06 - jump-if-false val=${data[$((pos+1))]} jumpto=${data[$((pos+2))]} param_count=2 @@ -68,7 +72,8 @@ run_program() { continue fi ;; - 07) + 07|08) + # 07 - is less than, 08 - is equal val1=${data[$((pos+1))]} val2=${data[$((pos+2))]} res_pos=${data[$((pos+3))]} @@ -78,26 +83,15 @@ run_program() { if [ ${immediate[2]} -eq 0 ]; then val2=${data[$val2]} fi - if [ $val1 -lt $val2 ]; then - data[$res_pos]=1 + data[$res_pos]=0 + if [ "$instruction" == "07" ]; then + if [ $val1 -lt $val2 ]; then + data[$res_pos]=1 + fi else - data[$res_pos]=0 - fi - ;; - 08) - val1=${data[$((pos+1))]} - val2=${data[$((pos+2))]} - res_pos=${data[$((pos+3))]} - if [ ${immediate[1]} -eq 0 ]; then - val1=${data[$val1]} - fi - if [ ${immediate[2]} -eq 0 ]; then - val2=${data[$val2]} - fi - if [ $val1 -eq $val2 ]; then - data[$res_pos]=1 - else - data[$res_pos]=0 + if [ $val1 -eq $val2 ]; then + data[$res_pos]=1 + fi fi ;; 99)