8
1
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 ] ]
Suggested test case: One where the value 5 is present two times, like
[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. – Kevin Cruijssen – 2018-08-08T06:46:37.4706
The core idea is good, however the way it has been drafted strikes me as falling under one of our categories of things to avoid when writing challenges, namely "adding unnecessary fluff". Parsing the dice does not seem to be the main part of the challenge, but it may well take half the code.
– Jonathan Allan – 2018-08-08T07:09:57.563@KevinCruijssen added – Veskah – 2018-08-09T20:09:36.087
1@JonathanAllan It's a game about dice so I gave them dice. I do agree that making them validate faces would be fluffy hence it's not part of the challenge. Dice matrices also allow for interesting solutions because just scoring 654 with integers is not very hard or all that unique. – Veskah – 2018-08-09T20:15:57.397
@Veskah and yet all 12 answers split or mould and sum to get the integers and then use those as if they were provided. – Jonathan Allan – 2018-08-09T20:24:31.747
1@JonathanAllan I'll keep it in mind for the future but won't change the specs now. – Veskah – 2018-08-09T20:34:56.317
1@Veskah yes definitely don't change the specs now! Here's to many more fun challenges :) – Jonathan Allan – 2018-08-09T20:36:11.780