Oh hey, glad you decided to come by and help.
I have been working hard setting sudokus for my friends for Christmas,
but I keep loosing track of where I saved them.
The standard way to save a solution is as a string of 81 digits from top left to bottom right,
however my notes are always getting super messy.
Can you help me find all the valid sudokus in my notes?
Obviously finding instances of strings in large files is a clear case for Reg-Ex.
Please write me a Reg-Ex that matches all valid sudokus in a file
Examples of valid sudokus:
324978156569214873718563924693721485471859362852346719287435691946182537135697248
169247358524813679387596142798625431213478596456931827975184263842369715631752984
974512638286437915351968742642853179519674823837291456165729384728346591493185267
Examples of invalid sudokus:
Two 9s in row 2 and two 8s in row 3:
324978156569214973718563824693721485471859362852346719287435691946182537135697248
Two 5s in col 5 and two 1s in col 6:
726341895534978216981256437418632579692751384357894162875463921249187653163529748
Two 6s in boxes 5 and 9 and two 2s in boxes 6 and 8:
638951472792438156154672389546817293819364725273596841425189637981723564367245918
Two 1s in row 5, col 2, and box 4:
936187452842569173157234689263875941514912736719346825475693218391728564628451397
More examples of valid and invalid Sudoku can be found here:
Enter your Reg-Ex bellow, you don't need to include flags. Keep in mind that unlike in PCRE2, in ECMA (which the browser uses) the 0 in {0,8} is required
Solution:
Need a hint? Click below:
One layer of unrolling is unavoidable (as far as I can tell). But you shouldn't need more than that
More hints? Click below:
Sudoku has 3 types of rules: row, col, and box rules. Each one can either be thought of as "no digit may appear twice in this set" or "every digit must appear in this set". Both formulations may be helpful for different rules.
Final Hint? Click below:
Negative lookaheads are your friend. Try to match each type of failure first, and then invert the Reg-Ex to match the valid sudokus.