1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/bin/sh -e
E="../target/debug/day09"
### https://adventofcode.com/2019/day/2
# Opcode 1 adds together numbers read from two positions and stores the result
# in a third position. The three integers immediately after the opcode tell you
# these three positions - the first two indicate the positions from which you
# should read the input values, and the third indicates the position at which
# the output should be stored.
# Opcode 2 works exactly like opcode 1, except it multiplies the two inputs
# instead of adding them. Again, the three integers after the opcode indicate
# where the inputs and outputs are, not their values.
### https://adventofcode.com/2019/day/5
# Opcode 3 takes a single integer as input and saves it to the position given
# by its only parameter. For example, the instruction 3,50 would take an input
# value and store it at address 50.
# Opcode 4 outputs the value of its only parameter. For example, the
# instruction 4,50 would output the value at address 50.
# Each parameter of an instruction is handled based on its parameter mode.
# Right now, your ship computer already understands parameter mode 0, position
# mode, which causes the parameter to be interpreted as a position - if the
# parameter is 50, its value is the value stored at address 50 in memory. Until
# now, all parameters have been in position mode.
# Now, your ship computer will also need to handle parameters in mode 1,
# immediate mode. In immediate mode, a parameter is interpreted as a value - if
# the parameter is 50, its value is simply 50.
# Opcode 5 is jump-if-true: if the first parameter is non-zero, it sets the
# instruction pointer to the value from the second parameter. Otherwise, it
# does nothing.
# Opcode 6 is jump-if-false: if the first parameter is zero, it sets the
# instruction pointer to the value from the second parameter. Otherwise, it
# does nothing.
# Opcode 7 is less than: if the first parameter is less than the second
# parameter, it stores 1 in the position given by the third parameter.
# Otherwise, it stores 0.
# Opcode 8 is equals: if the first parameter is equal to the second parameter,
# it stores 1 in the position given by the third parameter. Otherwise, it
# stores 0.
### https://adventofcode.com/2019/day/9
# Opcode 9 adjusts the relative base by the value of its only parameter. The
# relative base increases (or decreases, if the value is negative) by the value
# of the parameter.
PROGRAMS=${@:-programs/test-*.iac}
for PROGRAM in ${PROGRAMS}
do
echo "Starting ${PROGRAM}"
if [ -e ${PROGRAM%.iac}.in ]; then
INPUT=`cat ${PROGRAM%.iac}.in`
else
INPUT="0"
fi
if [ -e ${PROGRAM%.iac}.out ]; then
EXPECTED="`cat ${PROGRAM%.iac}.out`"
else
EXPECTED=""
fi
OUTPUT=`echo "${INPUT}" | RUST_BACKTRACE=1 \
"${E}" --program "${PROGRAM}" --mode stdio '0' | tee /dev/stderr`
echo "${PROGRAM} finished"
if [ "${EXPECTED}" = "${OUTPUT}" ]; then
echo "Expected output recieved: ${OUTPUT}"
else
echo "Incorrect output!"
echo "Expected |${EXPECTED}| != Actual |${OUTPUT}|"
exit 1
fi
echo ""
done
|