Mölkky
Mölkky is a Finnish throwing game. The players use a wooden pin (also called "mölkky") to try to knock over wooden pins of almost similar dimensions with the throwing pin, marked with numbers from 1 to 12. The initial position of the pins is as follows:
(07)(09)(08)
(05)(11)(12)(06)
(03)(10)(04)
(01)(02)
This description and the rules below are based on Wikipedia.
Simplified Mölkky rules
Knocking over one pin scores the number of points marked on the pin.
Knocking 2 or more pins scores the number of pins knocked over (e.g., knocking over 3 pins scores 3 points).
The aim of the game is to reach exactly 50 points. Scoring more than 50 is penalized by setting the score back to 25 points.
For the purpose of this challenge, we will make the assumption that the pins are always in the exact order described above. (In a real game, the pins are stood up again after each throw in the location where they landed.)
All other Mölkky rules are ignored and only a single player is considered.
Input
A non-empty list of lists of 12 booleans. Each list of booleans describes the outcome of a throw: 1 if the pin was knocked over and 0 otherwise. The booleans are given in the exact order of the pins, from top left to bottom right: 7, 9, 8, 5, 11, 12, 6, 3, 10, 4, 1, 2.
Output
The score after all throws described in the input, calculated by applying rules 1, 2 and 3.
Detailed example
Let's consider the following input:
// 07 09 08 05 11 12 06 03 10 04 01 02
[ [ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ], // scores 5 (rule #1)
[ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ], // scores 2 (rule #2), total: 7
[ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 ], // scores 7, total: 14
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ], // scores 12, total: 26
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ], // scores 12, total: 38
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ], // scores 11, total: 49
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], // scores 7, total: 56 -> 25 (rule #3)
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ] // scores 2, total: 27
The expected output is 27.
Challenge rules
- You may take input in any reasonable format. Instead of lists of booleans, you can use integers where the most significant bit is the pin #7 and the least significant bit is the pin #2. In this format, the above example would be passed as
[ 256, 2304, 127, 64, 64, 128, 2048, 3072 ]
. - The input list may contain throws where no pin at all is knocked over, in which case the score is let unchanged.
- You don't have anything special to do when the score reaches exactly 50 points. But you can assume that no other throw will follow when it happens.
- This is code-golf, so the shortest answer in bytes wins.
Test cases
Using lists of integers as input:
[ 0 ] --> 0
[ 528 ] --> 2
[ 4095 ] --> 12
[ 64, 0, 3208 ] --> 16
[ 16, 1907, 2048 ] --> 18
[ 2023, 2010, 1, 8 ] --> 29
[ 1726, 128, 35, 3136, 1024 ] --> 34
[ 32, 32, 2924, 2, 256, 16 ] --> 28
[ 64, 64, 2434, 1904, 3251, 32, 256 ] --> 25
[ 3659, 2777, 2211, 3957, 64, 2208, 492, 2815 ] --> 25
[ 2047, 1402, 2, 2599, 4, 1024, 2048, 3266 ] --> 50
[ 256, 2304, 127, 64, 64, 128, 2048, 3072 ] --> 27
[ 16, 8, 128, 1, 2048, 1, 2048, 513, 8, 3206 ] --> 30
You can follow this link to get these test cases in Boolean format.