Please excuse my absence over the past few days. Fell ill with bronchitis. Still feverish, so this post may be a nonsensical ramble, but hopefully you'll respond with your coherent solutions!
Day 4 - secure container
1.4 seconds
Instructions for part 1 were good. Part 2 made no sense to me. Took lots of discussion with other colleagues before I could make sense of it.
Seemed like a straighforward problem. Generate all the numbers between two given numbers (thank you Generate Rows tool!), and then make a really ugly filter to determine that the numbers are either the same left to right or increase.
Now to determine the adjacent numbers, I used a fun little RegEx trick: REGEX_CountMatches(tostring([Num1]), "([0-9])\1")>=1 This looks for any repetition of the same number.
Part 2 was challenging for me because I had trouble understanding which numbers were ok to have more than just a pair, and which weren't. Still not sure this was the best approach, but it did work in the end. I counted distinct numbers in each passcode that passed through part 1. and also counted how many times each number appeared in the passcode. To do this, parsed each number in each code out, and used some Summarizes, then joined back together.
An ugly formula determines if it meets the criteria for a passcode or not:
If [CountDistinct_Num1]=5 THEN "Y"
ELSEIF [CountDistinct_Num1]=4 AND [Count]>2 THEN "N"
ELSEIF [CountDistinct_Num1]=3 AND [Count]=4 THEN "N"
ELSEIF [CountDistinct_Num1]=2 AND [Count] In (3,5) THEN "N"
ELSEIF [CountDistinct_Num1]=1 THEN "N"
ELSE "Y" ENDIF
Ultimately, anything with an N doesn't meet the criteria. Here's a snapshot. Happy solving!
Cheers,
Esther
Hi @estherb47!
Great use of REGEX_CountMatches()!
I don't use that one enough!
Other REGEX muscles got a workout though!
I didn't realize that numeric references were supported in POSIX regex!! Since lookarounds aren't supported, I guess I just assumed that numeric references weren't either! So, I went with the very ugly regex below to find repeating digits:
regex_match(
tostring([num]),
'\d*(0{2}|1{2}|2{2}|3{2}|4{2}|5{2}|6{2}|7{2}|8{2}|9{2})\d*'
)
For checking increasing digits, I tried several methods for splitting out the digits, including this very ridiculous combination of formulas 😂
I also tried:
On my laptop, splitting the characters into rows or columns using a parsing tool was consistently faster than parsing them within the filter. I wonder if the efficiency gain is due to running the parsing operation all at once (rather than parsing and comparing each record within the filter)?
My Advent of Code solutions are on github here: https://github.com/kelly-gilbert/advent-of-code/tree/master/2019-alteryx