Blog
2024-12-22
I showed off and part-solved a prototype version of this puzzle with Katie Steckles in the fifteenth Finite Group livestream.
You can watch a recording of this stream, and watch our future streams if you sign up to
our Patreon.
I clearly haven't already made enough Christmas puzzles this year, so I've made another one. If you've used regular expressions before, head straight to
mscroggs.co.uk/regexmas to try the puzzle. If you've not, read on...
What is a regular expression
Regular expressions are strings of characters that can be used in multiple programming languages to validate text.
Regular expressions are usually written between two
/
characters. Between the slashes, characters have the following meaning:^
(not inside square brackets) means the start of the text.$
means the end of the text.- A set of characters are written between
[
and]
means any of these characters.
For example, the regular expression - A set of characters are written between
[^
and]
means any character except one of these. For example, the regular expression/^[^df]$/
matches any character except d or f. ?
means the previous item may or may not appear. For example, the regular expression/^ab?c$/
matches "ac" or "abc".+
means the previous item can appear one or more times. For example, the regular expression/^ab+c$/
matches "abc", "abbc", "abbbc", and so on.*
means the previous item can appear zero or more times. For example, the regular expression/^ab*c$/
matches "ac", "abc", "abbc", and so on.{
and}
with a number between means the previous item can appear this number of times. For example, the regular expression/^ab{4}c$/
matches "abbbbc".|
means either the stuff to the left or the stuff to the right. For example, the regular expression/^ab|c$/
matches "ab" or "c"..
means any character. For example, the regular expression/^ab|.$/
matches "ab" or any single character.(
and)
can be used to group together other symbols. Groups in brackets can be later referred to by writing\1
,\2
, etc to refer to the first, second, etc bracketed group. For example, the regular expression/^(a|b)\1$/
matches "aa" or "bb".
/^[abc]$/
matches "a", "b", or "c".
The puzzle
My regular expression Christmas puzzle is shown below. You can either solve it on this page or at mscroggs.co.uk/regexmas
using the buttons or your keyboard, or you can download
this PDF of the puzzle.
In the grid below, write r, g, b, c, m, y, k, or w in every square so that:
- each row (reading left to right) satisfies the regular expression to the right of the row;
- each column (reading top to bottom) satisfies the regular expression below the column.
The squares containing an r will be coloured red,
those containing a g will be coloured green,
those containing a b will be coloured blue,
those containing a c will be coloured cyan,
those containing an m will be coloured magenta,
those containing a y will be coloured yellow,
those containing a k will be coloured black, and those containing a w will be left white.
/^w+yw+$/
/^([kw]+)[^kw]\1$/
/^(g|wwwg|gww)+.$/
/^wy?g*y+w+$/
/^((w|gg)(ww|g)){3}$/
/^[wg](w|g)[gw](.)\2+\1{2}$/
/^.g*[^y]$/
/^([gk][gk][gk])\1\1$/
/^yw+kw+y$/
/^w*b(bb)+w*$/
/^(w+)w?(bb?)\2\2\1$/
/^(www|bbb)+$/
/^w+gyw+$/
/^[wg]*y[wg]*$/
/^.*gwg.*gwb.*$/
/^[^g]+g+[^g]+$/
/^y?g+y?g+k?b+$/
/^[w]+g*w[^w]+$/
/^w+g+wg+[^g]+$/
/^w*yw*g+w*$/
/^w*y?g?y?w*$/
(Click on one of these icons to react to this blog post)
You might also enjoy...
Comments
Comments in green were written by me. Comments in blue were not written by me.
Add a Comment