diff options
author | cos <cos> | 2019-12-07 23:09:12 +0100 |
---|---|---|
committer | cos <cos> | 2019-12-07 23:09:16 +0100 |
commit | edface94833462d5ccb3496ed631b2d3815646ec (patch) | |
tree | db4fe081453ae3583ac8f4560ca3163cef7d76fa /2019/rust/day07/calibrate_amplifiers_with_feedback.sh | |
parent | 9973aaf401649c6ffd3d14295ce6dd9e9e63d159 (diff) | |
download | adventofcode-edface94833462d5ccb3496ed631b2d3815646ec.zip |
Add day07, 2019
Solution search is implemented as shell scripts. Ugly and
fragile, but it got the task done.
Diffstat (limited to '2019/rust/day07/calibrate_amplifiers_with_feedback.sh')
-rwxr-xr-x | 2019/rust/day07/calibrate_amplifiers_with_feedback.sh | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/2019/rust/day07/calibrate_amplifiers_with_feedback.sh b/2019/rust/day07/calibrate_amplifiers_with_feedback.sh new file mode 100755 index 0000000..7a3a896 --- /dev/null +++ b/2019/rust/day07/calibrate_amplifiers_with_feedback.sh @@ -0,0 +1,50 @@ +#!/bin/sh -e + +launch_chain() +{ + local input_file="input_$1_$2_$3_$4_$5_$6.txt" + local p="input" + + (echo ${6}; (echo ${5}; (echo ${4}; (echo ${3}; (echo "${2} + ${1}" > "${input_file}";tail -f "${input_file}")| RUST_BACKTRACE=1 \ + ../target/debug/day07 --mode stdio --program "${p}") | \ + ../target/debug/day07 --mode stdio --program "${p}") | \ + ../target/debug/day07 --mode stdio --program "${p}") | \ + ../target/debug/day07 --mode stdio --program "${p}") | \ + ../target/debug/day07 --mode stdio --program "${p}" >> "${input_file}" + tail -1 "${input_file}" +} + +H=0 +I=0 +P="" +for A in `seq 5 9`; do + for B in `seq 5 9`; do + for C in `seq 5 9`; do + for D in `seq 5 9`; do + for E in `seq 5 9`; do + [ ${A} -ne ${B} ] || continue + [ ${A} -ne ${C} ] || continue + [ ${A} -ne ${D} ] || continue + [ ${A} -ne ${E} ] || continue + [ ${B} -ne ${C} ] || continue + [ ${B} -ne ${D} ] || continue + [ ${B} -ne ${E} ] || continue + [ ${C} -ne ${D} ] || continue + [ ${C} -ne ${E} ] || continue + [ ${D} -ne ${E} ] || continue + + O=`launch_chain ${I} ${A} ${B} ${C} ${D} ${E}` + V=`echo "${O}" | tail -1 ` + [ "${H}" -ge "${V}" ] || { + P="${A},${B},${C},${D},${E}"; + H="${V}"; + HI="${I}"; + } + done + done + done + done +done + +echo "Highest value: ${H} for phase set ${P}" |