From: Brett Parker Date: Sun, 6 Dec 2020 20:27:24 +0000 (+0000) Subject: Add some comments for the opcodes X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2019.git/commitdiff_plain/670345fb59a21f6ff316f31315beb32e6dd15ed8?ds=sidebyside;hp=5f982cb107e2c59c80b87efa0fcc0abff639bb90 Add some comments for the opcodes --- 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)