Compare commits

..

1 Commits

Author SHA1 Message Date
848866c48c Some bash cleanup (Day19/part 2) 2021-07-21 19:28:36 +02:00
4 changed files with 35 additions and 17 deletions

14
OUTPUT
View File

@@ -429,3 +429,17 @@ ex2.bash : res=20394514442037
ex12-c : res=20394514442037 ex12-c : res=20394514442037
time: 0:00.00 real, 0.00 user, 0.00 sys time: 0:00.00 real, 0.00 user, 0.00 sys
context-switch: 0+1, page-faults: 0+74 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

8
day19/OUTPUT Normal file
View File

@@ -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

View File

@@ -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? How many messages completely match rule 0?
Your puzzle answer was 285. Your puzzle answer was 285.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two --- --- 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: 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? 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.

View File

@@ -8,8 +8,8 @@ shopt -s extglob
declare -a RULE=() MATCH=() STRING=() declare -a RULE=() MATCH=() STRING=()
# shellcheck disable=SC2034 # shellcheck disable=SC2034
declare var_0 declare var_0 rule8 rule11
declare -i res=0 MAXPROF=0 declare -i res=0
# build a regexp use-able by bash =~ operator. # build a regexp use-able by bash =~ operator.
# Recursively replace rules, until we get final text values. # Recursively replace rules, until we get final text values.
@@ -23,8 +23,6 @@ function buildtree {
shift 2 shift 2
local args=$* res="" arg t local args=$* res="" arg t
((prof > MAXPROF)) && MAXPROF=$prof
for arg in $args; do for arg in $args; do
if [[ -z "${arg/[|ab]}" ]]; then if [[ -z "${arg/[|ab]}" ]]; then
res+="$arg" res+="$arg"
@@ -73,21 +71,19 @@ done
# 2) calculate rule 8 and 11 with some "guessed" minimum possible value # 2) calculate rule 8 and 11 with some "guessed" minimum possible value
# 3) build rule 0 # 3) build rule 0
# result starts to be "stable" from this value # result is "stable" from this value
SOME_LIMIT=5 SOME_LIMIT=5
buildtree 1 var_0 42 buildtree 1 var_0 42
buildtree 1 var_0 31 buildtree 1 var_0 31
tmp8="(${MATCH[42]})+" rule8="${MATCH[42]}+"
tmp11="(${MATCH[42]}${MATCH[31]})" rule11="${MATCH[42]}${MATCH[31]}"
for ((i=2; i<SOME_LIMIT; ++i)); do for ((i=2; i<SOME_LIMIT; ++i)); do
tmp11+="|((${MATCH[42]}){$i}(${MATCH[31]}){$i})" rule11+="|${MATCH[42]}{$i}${MATCH[31]}{$i}"
done done
MATCH[8]="$tmp8" MATCH[8]="$rule8"
MATCH[11]="($tmp11)" MATCH[11]="($rule11)"
buildtree 1 var_0 0 buildtree 1 var_0 0
res=0
for str in "${STRING[@]}"; do for str in "${STRING[@]}"; do
[[ "$str" =~ ^${MATCH[0]}$ ]] && ((res++)) [[ "$str" =~ ^${MATCH[0]}$ ]] && ((res++))
done done