diff --git a/OUTPUT b/OUTPUT index f9e0ba8..a2494d2 100644 --- a/OUTPUT +++ b/OUTPUT @@ -429,3 +429,17 @@ ex2.bash : res=20394514442037 ex12-c : res=20394514442037 time: 0:00.00 real, 0.00 user, 0.00 sys context-switch: 0+1, page-faults: 0+74 + +========================================= +================= day19 ================= +========================================= + ++++++++++++++++++ ex1 +ex1.bash : res=285 + time: 0:00.56 real, 0.55 user, 0.00 sys + context-switch: 12+1, page-faults: 0+5967 + ++++++++++++++++++ ex2 +ex2.bash : res=412 + time: 0:03.37 real, 3.34 user, 0.03 sys + context-switch: 19+1, page-faults: 0+11909 diff --git a/day19/OUTPUT b/day19/OUTPUT new file mode 100644 index 0000000..8fa428b --- /dev/null +++ b/day19/OUTPUT @@ -0,0 +1,8 @@ +ex1.bash : res=285 + time: 0:00.56 real, 0.55 user, 0.00 sys + context-switch: 12+1, page-faults: 0+5967 + +ex2.bash : res=412 + time: 0:03.37 real, 3.34 user, 0.03 sys + context-switch: 19+1, page-faults: 0+11909 + diff --git a/day19/README b/day19/README index 8bdc720..318a794 100644 --- a/day19/README +++ b/day19/README @@ -54,8 +54,6 @@ Your goal is to determine the number of messages that completely match rule 0. I How many messages completely match rule 0? Your puzzle answer was 285. - -The first half of this puzzle is complete! It provides one gold star: * --- Part Two --- As you look over the list of messages, you realize your matching rules aren't quite right. To fix them, completely replace rules 8: 42 and 11: 42 31 with the following: @@ -138,8 +136,10 @@ However, after updating rules 8 and 11, a total of 12 messages match: After updating rules 8 and 11, how many messages completely match rule 0? -Answer: +Your puzzle answer was 412. -Although it hasn't changed, you can still get your puzzle input. +Both parts of this puzzle are complete! They provide two gold stars: ** -You can also [Share] this puzzle. +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. diff --git a/day19/ex2.bash b/day19/ex2.bash index cd2c992..d4b8324 100755 --- a/day19/ex2.bash +++ b/day19/ex2.bash @@ -8,8 +8,8 @@ shopt -s extglob declare -a RULE=() MATCH=() STRING=() # shellcheck disable=SC2034 -declare var_0 -declare -i res=0 MAXPROF=0 +declare var_0 rule8 rule11 +declare -i res=0 # build a regexp use-able by bash =~ operator. # Recursively replace rules, until we get final text values. @@ -23,8 +23,6 @@ function buildtree { shift 2 local args=$* res="" arg t - ((prof > MAXPROF)) && MAXPROF=$prof - for arg in $args; do if [[ -z "${arg/[|ab]}" ]]; then res+="$arg" @@ -69,29 +67,25 @@ done # hack: -# 1) build part 1 tree +# 1) build rules 42 and 31 # 2) calculate rule 8 and 11 with some "guessed" minimum possible value -# 3) rebuild tree from scratch, but with rules 8 and 11 pre-loaded -buildtree 1 var_0 0 +# 3) build rule 0 -# This value was found manually: stable from 5. +# result is "stable" from this value SOME_LIMIT=5 -tmp8="(${MATCH[42]})+" -tmp11="(${MATCH[42]}${MATCH[31]})" + +buildtree 1 var_0 42 +buildtree 1 var_0 31 +rule8="${MATCH[42]}+" +rule11="${MATCH[42]}${MATCH[31]}" for ((i=2; i