2024-12-17 15:48:25 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
FILE=$1
|
2024-12-18 12:13:16 +08:00
|
|
|
ITER=1
|
|
|
|
MACHINE_ITER=999
|
2024-12-17 17:09:19 +08:00
|
|
|
DEBUG=false
|
2024-12-20 01:01:41 +08:00
|
|
|
INCREMENT=100000000000
|
|
|
|
TAIL_NUM=3
|
2024-12-17 15:48:25 +08:00
|
|
|
|
2024-12-18 12:17:06 +08:00
|
|
|
# Load registry values
|
2024-12-17 15:48:25 +08:00
|
|
|
REG_A=$(grep 'Register A:' "$FILE" | cut -f2 -d: )
|
|
|
|
REG_B=$(grep 'Register B:' "$FILE" | cut -f2 -d: )
|
|
|
|
REG_C=$(grep 'Register C:' "$FILE" | cut -f2 -d: )
|
2024-12-18 12:17:06 +08:00
|
|
|
|
|
|
|
# Rewrite registry A starting value
|
2024-12-20 01:01:41 +08:00
|
|
|
REG_A=100000000000000
|
|
|
|
#REG_A=164541160582800
|
2024-12-18 12:17:06 +08:00
|
|
|
|
|
|
|
# Load input string
|
2024-12-17 15:48:25 +08:00
|
|
|
read -r -a INPUT <<< "$(grep 'Program:' "$FILE" | cut -f2 -d: | tr ',' ' ' )"
|
|
|
|
INPUT_LEN=${#INPUT[@]}
|
|
|
|
printf "Registers A: %s B: %s C: %s\n" "$REG_A" "$REG_B" "$REG_C" >&2
|
2024-12-18 12:13:16 +08:00
|
|
|
#printf "Input: " >&2
|
|
|
|
#printf "%s " "${INPUT[@]}" >&2
|
|
|
|
#printf "\n" >&2
|
2024-12-17 15:48:25 +08:00
|
|
|
|
2024-12-17 17:09:19 +08:00
|
|
|
# Load machine operations
|
|
|
|
. machine.sh
|
2024-12-17 15:48:25 +08:00
|
|
|
|
2024-12-18 12:17:06 +08:00
|
|
|
# Iterate registry A until last nth digits are matched
|
2024-12-20 01:01:41 +08:00
|
|
|
PIN_DIGITS=0
|
|
|
|
while ! check_tail "$INPUT_LEN" "$PIN_DIGITS"
|
2024-12-17 15:48:25 +08:00
|
|
|
do
|
2024-12-20 01:01:41 +08:00
|
|
|
while ! check_tail "$TAIL_NUM" "$PIN_DIGITS"
|
|
|
|
do
|
|
|
|
read -r -a OUTPUT <<< "$( execute_machine )"
|
|
|
|
printf "Register A: %s\n" "$REG_A"
|
|
|
|
printf "Output:\t"
|
|
|
|
printf "%s " "${OUTPUT[@]}"
|
|
|
|
printf "\n"
|
|
|
|
printf "Input:\t"
|
|
|
|
printf "%s " "${INPUT[@]}"
|
|
|
|
printf "\n"
|
|
|
|
(( REG_A+=INCREMENT))
|
|
|
|
#(( ITER-- ))
|
|
|
|
if [[ $ITER -eq 0 ]] ; then break ; fi
|
|
|
|
done
|
|
|
|
PIN_DIGITS=$TAIL_NUM
|
|
|
|
printf "Matched digit. Reducing count"
|
|
|
|
(( TAIL_NUM+=1 ))
|
|
|
|
(( INCREMENT/= 50 ))
|
2024-12-18 12:13:16 +08:00
|
|
|
done
|