Working part 2

This commit is contained in:
2024-12-20 01:01:41 +08:00
parent fd78069221
commit 0134815002
2 changed files with 63 additions and 69 deletions

View File

@ -4,8 +4,8 @@ FILE=$1
ITER=1
MACHINE_ITER=999
DEBUG=false
INCREMENT=1
TAIL_NUM=16
INCREMENT=100000000000
TAIL_NUM=3
# Load registry values
REG_A=$(grep 'Register A:' "$FILE" | cut -f2 -d: )
@ -13,8 +13,8 @@ REG_B=$(grep 'Register B:' "$FILE" | cut -f2 -d: )
REG_C=$(grep 'Register C:' "$FILE" | cut -f2 -d: )
# Rewrite registry A starting value
#REG_A=100000000000000
REG_A=164541160582800
REG_A=100000000000000
#REG_A=164541160582800
# Load input string
read -r -a INPUT <<< "$(grep 'Program:' "$FILE" | cut -f2 -d: | tr ',' ' ' )"
@ -28,17 +28,25 @@ printf "Registers A: %s B: %s C: %s\n" "$REG_A" "$REG_B" "$REG_C" >&2
. machine.sh
# Iterate registry A until last nth digits are matched
while ! check_tail "$TAIL_NUM"
PIN_DIGITS=0
while ! check_tail "$INPUT_LEN" "$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
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 ))
done