# Do you win a Numeric Mahjong?

## 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:

The triples are:  ,  , $$, $$$, &&&, (((, ))), ,,,, ..., ///, :::, >>>, ???, ___, ___, aaa, bbb, eee, ggg, kkk, sss, uuu, uuu, {{{, {{{, |||, }}}, }}} • The length of the code has to be 2 mod three, so this must be invalid. Looking at the character distribution, you seem to have one ) too many, and no pair (only triples) Commented Sep 26, 2023 at 3:26 • @CommandMaster Thanks for the catch. The answer has been revised. – Sean Commented Sep 26, 2023 at 15:00 # Ruby, 116 92 bytes Brute force solution checking all permutations until it finds one that matches. Times out on medium inputs, so verification was done using the program below since it doesn't time out as easily. Recursive approach saving 24 bytes by G B. e=->a{a[2]?a.permutation.any?{_,o,z,*i=_1;_-o==(o-=z)&&o**2<2&&e[i]}:a!=a|a}#"')).11@@A[]ass  Attempt This Online! ## Ruby, 137 bytes Count the number of occurrences of each element. Then, for each element, removes a pair from the count (if possible), then checks if everything else is sequences or triplets. ->a{a.any?{t=a.tally;(t[_1]-=2)>=0&&a.sort.all?{|e|t[e]>=0&&((0...t[e]%=3).all?{(e..e+2).all?{|i|t[i]=t[i]&.-1}})}}}#$&*++3;;??\\__lmtty|


Attempt This Online!

• By using recursion: 85 bytes + padding f=->a{a[2]?a.permutation.any?{x,y,z,*a=_1;(x==y&&y==z||(x-y)*(y-z)==1)&&f[a]}:a!=a|a}
– G B
Commented Sep 27, 2023 at 10:52
• And save on padding if you call the function e
– G B
Commented Sep 27, 2023 at 11:14
• 89 bytes including padding: e=->a{a[2]?a.permutation.any?{_,o,z,*i=_1;_-o==(o-=z)&&o**2<2&&e[i]}:a!=a|a}#"')).11@@A[]ass
– G B
Commented Sep 27, 2023 at 13:20