Inspired and looted from this dice challenge by Arnauld
Input
You are given a 5x1 or 1x5 (your choice) dice matrix which consist of binary 3x3 sub-matrices.
Goal
Given a valid dice matrix, you are to score it using the rules of 6,5,4 which are as follows:
- If the roll contains 6,5,4, add the other two dice together and that is your score. E.g. 4,X,5,6,Y = X+Y
- Otherwise, the score is 0. E.g. 5,5,5,4,1 = 0
Dice patterns
$$\begin{align} &1:\pmatrix{\color{gray}0,\color{gray}0,\color{gray}0\\\color{gray}0,1,\color{gray}0\\\color{gray}0,\color{gray}0,\color{gray}0} &&2:\pmatrix{1,\color{gray}0,\color{gray}0\\\color{gray}0,\color{gray}0,\color{gray}0\\\color{gray}0,\color{gray}0,1}\text{or}\pmatrix{\color{gray}0,\color{gray}0,1\\\color{gray}0,\color{gray}0,\color{gray}0\\1,\color{gray}0,\color{gray}0}\\ &3:\pmatrix{1,\color{gray}0,\color{gray}0\\\color{gray}0,1,\color{gray}0\\\color{gray}0,\color{gray}0,1}\text{or}\pmatrix{\color{gray}0,\color{gray}0,1\\\color{gray}0,1,\color{gray}0\\1,\color{gray}0,\color{gray}0} &&4:\pmatrix{1,\color{gray}0,1\\\color{gray}0,\color{gray}0,\color{gray}0\\1,\color{gray}0,1}\\ &5:\pmatrix{1,\color{gray}0,1\\\color{gray}0,1,\color{gray}0\\1,\color{gray}0,1} &&6:\pmatrix{1,\color{gray}0,1\\1,\color{gray}0,1\\1,\color{gray}0,1}\text{or}\pmatrix{1,1,1\\\color{gray}0,\color{gray}0,\color{gray}0\\1,1,1} \end{align}$$
Rules
- The matrix is guaranteed to only contain valid faces but will include the 2,3 and 6 permutations. You can also take it in either orientation in whatever way is convenient. Please state the chosen orientation in your answer.
- Output the calculated score
- Standard Loopholes are forbidden
- This is code-golf.
Examples
// 2,5,2,4,6: Output should be: 4
[ [ 0,0,1 ],
[ 0,0,0 ],
[ 1,0,0 ],
[ 1,0,1 ],
[ 0,1,0 ],
[ 1,0,1 ],
[ 0,0,1 ],
[ 0,0,0 ],
[ 1,0,0 ],
[ 1,0,1 ],
[ 0,0,0 ],
[ 1,0,1 ],
[ 1,1,1 ],
[ 0,0,0 ],
[ 1,1,1 ] ]
// 1,6,2,4,6: Output should be: 0
[ [ 0,0,0, 1,0,1, 1,0,0, 1,0,1, 1,1,1 ],
[ 0,1,0, 1,0,1, 0,0,0, 0,0,0, 0,0,0 ],
[ 0,0,0, 1,0,1, 0,0,1, 1,0,1, 1,1,1 ] ]
// 5,6,6,4,6: Output should be: 12
[ [ 1,0,1, 1,0,1, 1,1,1, 1,0,1, 1,1,1 ],
[ 0,1,0, 1,0,1, 0,0,0, 0,0,0, 0,0,0 ],
[ 1,0,1, 1,0,1, 1,1,1, 1,0,1, 1,1,1 ] ]
// 3,3,4,5,6: Output should be: 6
[ [ 0,0,1, 1,0,0, 1,0,1, 1,0,1, 1,1,1 ],
[ 0,1,0, 0,1,0, 0,0,0, 0,1,0, 0,0,0 ],
[ 1,0,0, 0,0,1, 1,0,1, 1,0,1, 1,1,1 ] ]
// 2,5,2,5,6: Output should be: 0
[ [ 0,0,1, 1,0,1, 1,0,0, 1,0,1, 1,1,1 ],
[ 0,0,0, 0,1,0, 0,0,0, 0,1,0, 0,0,0 ],
[ 1,0,0, 1,0,1, 0,0,1, 1,0,1, 1,1,1 ] ]
[2,5,2,5,6]
. My current solution works for all four of your test cases (by using a very bad method of sorting the values and removing the sub-list[4,5,6]
), which of course fails when5
is present two times. \$\endgroup\$ – Kevin Cruijssen Aug 8 '18 at 6:46