Background
Numeric Mahjong is a hypothetical variation of Japanese Mahjong, played with nonnegative integers instead of Mahjong tiles. Given a list of nonnegative integers, it is a winning hand if it satisfies the following:
- its length is \$3n+2\$ for some nonnegative integer \$n\$, and
- it can be partitioned into \$n\$ triples and a pair so that
- each triple consists of three identical numbers \$(x,x,x)\$ or three consecutive numbers \$(x,x+1,x+2)\$, and
- the pair consists of two identical numbers \$(x,x)\$.
Challenge
Write a program or function that tests if a given a list of nonnegative integers is a winning hand in Numeric Mahjong. As this is a self-validating challenge, your source code (when converted to a list of integers) must be a winning hand. For example, print(1)
is not a valid answer even if it implements the task, but the following may be:
print(1)###*11ios
whose ASCII values in sorted order is [35, 35, 35, 40, 41, 42, 49, 49, 49, 105, 105, 110, 111, 112, 114, 115, 116]
, which can be partitioned to five triples [35, 35, 35], [40, 41, 42], [49, 49, 49], [110, 111, 112], [114, 115, 116]
and a pair [105, 105]
.
When converting the source code to integers, you may choose between
- Unicode codepoints of each char (when the source code is a sequence of Unicode characters),
- one of your language's fixed-width encodings, or
- a raw byte sequence (when the source code has an integral number of bytes).
If there are other sensible conversions, please leave a comment.
For output, you can choose to
- output truthy/falsy using your language's convention (swapping is allowed), or
- use two distinct, fixed values to represent true (affirmative) or false (negative) respectively.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
Truthy
[0, 0]
[999, 999, 999, 1234, 1234]
[1, 2, 2, 2, 3]
[1, 4, 7, 2, 5, 5, 5, 8, 3, 6, 9]
[1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7]
[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3]
[0, 0, 0, 0, 0, 0, 0, 0]
Falsy
[]
[1]
[1, 3, 5, 7, 9]
[1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64]
[1,2,3,4,5]
\$\endgroup\$