[Question]
  [
## Input
A non-empty binary matrix consisting of 3x3 sub-matrices put side by side.
## Task
Your task is to identify valid dice patterns (as described below) among the 3x3 sub-matrices. Each valid pattern is worth the value of the corresponding dice. Invalid patterns are worth 0.
## Output
The sum of the valid dice values.
## 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}$$
## Example
The expected output for the following matrix is **14** because it contains the dice **5**, **6** and **3**, followed by an invalid pattern (from left to right and from top to bottom).
$$\pmatrix{1,0,1,1,1,1\\
0,1,0,0,0,0\\
1,0,1,1,1,1\\
1,0,0,0,0,0\\
0,1,0,0,1,0\\
0,0,1,0,1,0}$$
## Rules
* Both the width and the height of the matrix are guaranteed to be multiples of 3.
* You must ignore sub-matrices that are not properly aligned on the grid (see the 3rd test case). More formally and assuming 0-indexing: the coordinates of the top-left cell of each sub-matrix to be considered are of the form \$(3x, 3y)\$.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'").
## Test cases
```
// 0
[ [ 1,0,0 ],
  [ 0,0,1 ],
  [ 1,0,0 ] ]
// 2
[ [ 0,0,1 ],
  [ 0,0,0 ],
  [ 1,0,0 ] ]
// 0 (0 + 0)
[ [ 0,0,1,0,1,0 ],
  [ 0,0,0,1,0,0 ],
  [ 0,0,1,0,1,0 ] ]
// 9 (3 + 3 + 3)
[ [ 1,0,0,0,0,1,1,0,0 ],
  [ 0,1,0,0,1,0,0,1,0 ],
  [ 0,0,1,1,0,0,0,0,1 ] ]
// 6 (6 + 0)
[ [ 1,0,1 ],
  [ 1,0,1 ],
  [ 1,0,1 ],
  [ 1,0,1 ],
  [ 1,0,0 ],
  [ 1,0,1 ] ]
// 14 (5 + 6 + 3 + 0)
[ [ 1,0,1,1,1,1 ],
  [ 0,1,0,0,0,0 ],
  [ 1,0,1,1,1,1 ],
  [ 1,0,0,0,0,0 ],
  [ 0,1,0,0,1,0 ],
  [ 0,0,1,0,1,0 ] ]
// 16 (1 + 2 + 3 + 4 + 0 + 6)
[ [ 0,0,0,1,0,0,1,0,0 ],
  [ 0,1,0,0,0,0,0,1,0 ],
  [ 0,0,0,0,0,1,0,0,1 ],
  [ 1,0,1,1,1,1,1,0,1 ],
  [ 0,0,0,1,0,1,1,0,1 ],
  [ 1,0,1,1,1,1,1,0,1 ] ]
```
  
[Answer]
# [Python 3](https://docs.python.org/3/), ~~195~~ 189 bytes
*-6 bytes thanks to @Jo King*
```
lambda m:sum({16:1,257:2,68:2,273:3,84:3,325:4,341:5,455:6,365:6}.get(int(''.join(str(e)for c in m[3*i:][:3]for e in c[3*j:][:3]),2),0)for i in range(len(m)//3)for j in range(len(m[0])//3))
```
[Try it online! (189)](https://tio.run/##jVLLboMwELzzFXuLqVaJjYFElvIlrg80dVJQMBHQQ1X126nNowkGRRVi5d2ZHXbN3L7aj8rw7nx87a5Z@faeQSmaz5J8s1QwjJK9iDA92BDtueB4iG3gUSJi5DETCcZJIlLkqY0/24tuSW5astlsiyo3pGlrosNzVcMJcgOl5C@5UFJw5Wra1U62Vgy1EKMQaU/PHVRn5qLJVRtShrsd74HCAyRVPRZ2rW7aBo4gAwkSGFKkoDAAm9gjsikZEZdKH6OPXWvE4Z3RcfmpiTW19oyR67HZXcJXHrk4TvgoNlvmnwn1kJne8Phj@U1z1n26tX2eXgidb70UoGsys66VwZAt/iWyv4t81gFKBc5dzkPOYL2XhGUD3Gpn6DNxJeuyXw "Python 3 – Try It Online")
[~~Try it online! (195)~~](https://tio.run/##jVLLboMwELzzFXuLaVeJjYFElvIlLgeamgQUTAT0UFX9dmrzaIJBUYW8Ymdmh12zt6/2UmneZce37pqW7x8plKL5LMk3iwXDINqLAOODCcGeC46H0AQeRCJEHjIRYRhFIkYem/izPauW5Lolm822qHJNmrYmyoesquEEuYZS8pdcmPPKkx5VFj0ZtDBoYVAfAx/pUJJbsk71WZGr0qT0dzs@MIXDSJr0pN@1qmkbOIL0JEhgSJFCgh6YxLwim5KRsal0OfpYtSYczkyOy09Nqqm0V4xaR83uFq7zqMWxw0ez2TD/TKjDzPyGx23LLZqr7t2tzfP0Quh86qUBXbOZVa00hmzxL5H9XeSzCkgSz26X3SG7YP0uCaMGuNV2rTNiIbNlvw "Python 3 – Try It Online")
### Human readable version:
```
# 3x3 part matrix to dice, beginning at coordinates 3*i, 3*j
def single_matrix_to_dice(matrix, i, j):
    # Example: matrix = [[0, 0, 0], [0, 1, 0], [0, 0, 0]], i=0, j=0 (result is 1)
    matrix_string = ''.join(
        str(e) for column in matrix[3*i:3*i+3] 
        for entry in column[3*j:3*j+3]
    ) # Slicing the matrix so that only the valid entries remain, here '000010000'
    # Interpreting the matrix string as binary number, here 16
    binary_number = int(matrix_string,2)
    # binary representations of all valid dice rolls
    dct = {16:1,257:2,68:2,273:3,84:3,325:4,341:5,455:6,365:6}
    return dct.get(binary_number, 0)
def f(matrix):
    return sum(
        single_matrix_to_dice(matrix, i, j) for i in range(len(m)//3) 
        for j in range(len(m[0])//3))
    ) # len(m)/3 would generate a float, so len(m)//3 is used
```
[Answer]
# [R](https://www.r-project.org/), 134 bytes
```
function(m,d=dim(m)/3-1){for(a in 0:d)for(b in 0:d[2])F=F+sum(y<-m[1:3+a*3,1:3+b*3])*sum(y*2^(8:0))%in%utf8ToInt("āDđTŅŕǇŭ");F}
```
[Try it online!](https://tio.run/##jVLNTuMwEL7nxCOMQCgzrcvaDVtBl2gvbKW9onJKs1JKHYjUJChxpSLgwAFx3gOPwVtQ8VjFaU1okwihyHYcz/c3Trbcgys5vZYZhLPkQkVpAiqFS6kgDlQWzSHM0hiUzBVcBLnMrXgOJ52yGNVc0a0FoNfi@2U@G6ONo5FHd3r29Qx0x/C3OxolZDPbZrqSab2pOzw7/0MaGuQHay3MZDA5UMF4KlHJuXKL0lxeuxpHZN1bobsshWM2cSdRjDH9cDqCbsM0wwCiBHh/QsVmbDZe16eBO2jnsxhvTjqxJ/pOO2g5rFjHLcen1uqo1f2HR31OtB8l@zMVHg3Tv4nC3Z3Xh9PX/8PF4@L57Wnxsku/Bve6a9wKUTcDbQ88EIwzDj7TaTzQr0x8bMwJ@EUCaw@6BmatcFulfJOkiuOAHNrAaVN2BV@PLRJW9/NRVRIeAzqacDWolsWwVHjEJ3lV09Qyk6iU6QH2ar5FtUPf3PDKSakiDgF/apmeSdQgt36qWaqc21WfkZqa8HV/hU4utJWusXRY2Cos1m5wq68NBpsueAPV4J@J2n/FRHlJXyGM/eU7 "R – Try It Online")
I noticed I had the same idea of @Heteira
History :
* ~~171~~ : -10 bytes thanks to @JayCe !
* ~~161~~ : -3 bytes thanks to @Giuseppe !
* ~~158~~ : -13 bytes saved !
* ~~145~~ : -2 bytes thanks to @Giuseppe!
* ~~143~~ : -6 bytes saved !
* ~~137~~ : -3 bytes thanks to @JayCe!
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~113 105 97~~ 94 bytes
```
{sum (|@_[*;^3+3*$_]for ^@_[0]).rotor(9).map:{"@āđŅŕǇ@@DT@@ŭ".ords.first(:2[$_],:k)%7}}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwv7q4NFdBo8YhPlrLOs5Y21hLJT42Lb9IIQ4oYhCrqVeUX5JfpGGpqZebWGBVreQgcKTxyMSjrUenHm93cHAJcXA4ulZJL78opVgvLbOouETDyigaaIKOVbamqnlt7f/ixEqFNI1ohWgFQx0DHQOFWB0uBSAHyNQxhHGgMgqxmtZcXAgNKGoMkHXj0wDBKNp0MK2GqUI3AqwSqgdNlyHCKHQboGp1oC7GZiiKZ4nkGKDJYDUXAtGdia4ZVRXCtdj8R1RAGaCGBqZBBtiMQ9GFxYE6hhhxrmMID2B8OsDu@w8A "Perl 6 – Try It Online")
Splits up the matrix into sub matrices of 3x3, converts the nine 1s and 0s to base 2 and then indexes it into a list of integers for the value.
### Explanation:
```
{  #Start anonymous code block
  sum   # Sum of all
     (|@_[*;^3+3*$_]   # Get the n*3 to n*3+3th elements in every sub-list
           for ^@_[0]) # For n in the range 0 to width (divide by 3 to avoid warnings)
     .rotor(9)  # Split this list into groups of 9 (split the dice up)
     .map:{     # And map each die to 
        "@āđŅŕǇ@@DT@@ŭ".ords  # In the list of integers
           .first(      # The first appearance of 
               :2[$_],  # The dice converted from a list of 0s and 1s to base 2
                 :k     # Returning the index
             )%7        # And modulo by 7 to get the alternate versions of 2, 3 and 6
          }
}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~29~~ 28 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-1 thanks to Mr. Xcoder (use `Ṁ` to replace `ṢṪ`)
```
s€3ZẎs3µZU,ƊṀṙ1FḄ“°€⁼-Ḍ?‘i)S
```
A monadic link.
**[Try it online!](https://tio.run/##y0rNyan8/7/4UdMa46iHu/qKjQ9tjQrVOdb1cGfDw50zDd0e7mh51DDn0AaggkeNe3Qf7uixf9QwI1Mz@P///9EK0QoGOiBoiCAVYnW4FMASEEG4AoQEkiCIhEkYgoVgEEkCoRpNAosOhVgA "Jelly – Try It Online")** Or [run the tests](https://tio.run/##y0rNyan8/7/4UdMa46iHu/qKjQ9tjQrVOdb1cGfDw50zDd0e7mh51DDn0AaggkeNe3Qf7uixf9QwI1Mz@P/hdqDY///RXNEK0QqGOgY6BgqxOlwKQA6QqWMI40BlFGK5dMAqUSQNkLVhVQnBKOp1MC2DqYLrBSuBKkZTbogwA91oqFodqBtRTEPxEJEcAzQZVAMhEN1h6LpQVSHch81H@MPEANXjmCYYYDMHRRcWl@kYYkSojiE8LPHpADosFgA "Jelly – Try It Online").
### How?
```
s€3ZẎs3µZU,ƊṀṙ1FḄ“°€⁼-Ḍ?‘i)S - Link: list of lists of 1s and 0s
s€3                          - split each into threes
   Z                         - transpose
    Ẏ                        - tighten
     s3                      - split into threes -> the sub-matrices in column-major order
       µ                  )  - for each sub-matrix, say D:
           Ɗ                 -   last three links as a monad:
        Z                    -     transpose D
         U                   -     reverse each -> D rotated a quarter turn clockwise
          ,                  -     pair with D
            Ṁ                -   get the maximum of the two orientations
             ṙ1              -   rotate left by one (to ensure FḄ will yield integers <256 for all non-zero valued D)
               F             -   flatten
                Ḅ            -   convert from binary
                         i   -   first 1-based index in (0 if not found):
                 “°€⁼-Ḍ?‘    -     code-page indices list = [128,12,140,45,173,63]
                           S - sum
```
For example when a sub-matrix is:
```
[[1,0,1],
 [1,0,1],
 [1,0,1]]
```
Then `ZU,Ɗ` yields:
```
[[[1, 1, 1],
  [0, 0, 0],
  [1, 1, 1]],   ...which has maximum (Ṁ):    ...and after ṙ1:
 [[1, 0, 1],                   [[1, 1, 1],         [[0, 0, 0],
  [1, 0, 1],                    [0, 0, 0],          [1, 1, 1],
  [1, 0, 1]]]                   [1, 1, 1]]          [1, 1, 1]]
```
...which flattens to `[0, 0, 0, 1, 1, 1, 1, 1, 1]`, which, converting from binary, is `63` which is the sixth entry in the code-page index list `“°€⁼-Ḍ?‘` (`?` being byte `3F` in [Jelly's code-page](https://github.com/DennisMitchell/jelly/wiki/Code-page))
[Answer]
# [Japt](https://github.com/ETHproductions/japt) `-x`, 36 bytes
*Now it's getting interesting. I'm sure can be golfed down even more*
```
ò3 ®®ò3Ãy f@"0ıtŵġdťƍǧ"øºXm¬¬Í+H)d
c
```
[Try it online!](https://tio.run/##y0osKPn///AmY4VD6w6tA9KHmysV0hyUDI5sLDm69cjClKNLj/UeX650eMehXRG5h9YcWnO4V9tDM4Ur@f//aIVoBQMdEDREkAqxOlwKYAmIIFwBQgJJEETCJAzBQjCIJIFQjSaBRQcQ6lYAAA "Japt – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 90 bytes
```
+`(...)(.+¶)(...)(.+¶)(...)
$1¶$3¶$5¶$2$4
¶
M!`.{9}
G`111000111|(101){3}|(.)0(.0).0\3\2
1
```
[Try it online!](https://tio.run/##XYq7DcJAEETz7QLpgl1ZWs34IKACInfg4AgISAgQme22roBr7FhbRATz5qN5Pz7P1733oai7m/rQqv1HSWw15dAlNKaztCoynYov101uhSSA4KoEbcnbqm5QhznmPI/C3rkfKNivkF87Co6RYQHiCw "Retina 0.8.2 – Try It Online") Explanation:
```
+`(...)(.+¶)(...)(.+¶)(...)
$1¶$3¶$5¶$2$4
```
Repeatedly remove \$3\times 3\$ blocks from each \$3\times n\$ row until all rows have 3 columns.
```
¶
M!`.{9}
```
Join all the blocks together and then split back up into rows of 9 columns.
```
G`111000111|(101){3}|(.)0(.0).0\3\2
```
Only keep valid dice patterns (two patterns for `6`, then one matches any number from `0` to `5`, although `0` of course will not contribute to the count below.)
```
1
```
Count the pips on the valid dice.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `d`, 34 bytes
```
3ẇƛƛ3ẇ;ÞTvf;f9ẇ'†B»@uS∨∪ċ#»b9ẇvB$c
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=d&code=3%E1%BA%87%C6%9B%C6%9B3%E1%BA%87%3B%C3%9ETvf%3Bf9%E1%BA%87%27%E2%80%A0B%C2%BB%40uS%E2%88%A8%E2%88%AA%C4%8B%23%C2%BBb9%E1%BA%87vB%24c&inputs=%5B%20%5B0%2C0%2C0%2C0%2C0%2C1%5D%2C%20%5B0%2C1%2C0%2C0%2C0%2C0%5D%2C%20%5B0%2C0%2C0%2C1%2C0%2C0%5D%2C%5B0%2C0%2C1%2C1%2C0%2C1%5D%2C%20%5B0%2C1%2C0%2C0%2C0%2C0%5D%2C%5B1%2C0%2C0%2C1%2C0%2C1%5D%20%5D&header=&footer=)
A mess.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 151 bytes
```
->m{m.each_slice(3).flat_map{|r|r.transpose.each_slice(3).map{|d|" \x10āđŅŕǇ  DT  ŭ".chars.map(&:ord).index(d.flatten.join.to_i 2)&.%7}-[p]}.sum}
```
[Try it online!](https://tio.run/##jVPdasIwFL7vUxwck5TFkKhzbOCu9gi760rp2ood9ocmgsP2Yhdj17vYY@wtlD1WbWs0NhYZIZCTfN93vpOTZMvX93I2LQeP0ToigevNHb4IvQCNTDJbuMKJ3HSdZ3lGRObGPE14oKEagJ/34GXF6OZj87393P78fQE8PQNsf3vEm7sZr2Go/5BkvknC2A9WyG/0RRCTtySMiUicEIZmn1zfFQMrtQvCl1FRioALx3N5wGEKlnEF1LDAAoYppmBjA6qgWmJ2CORJHVboYYNuAegptY2mgCjcADUVaz9bXHye/ICSOveARpVOM03lV5I1OlOaeiqJxdK/VJ8AmiiXTC/@nwHVTqQ4GwO6rdQn0v9plv3QnetSbZQqoKvkS5fIqjpZ5WAonYxrN7Uz1Z3W5XX46mreCavDNmZnTwWzYycuMcA2bMNQz7X5Jev8uJFDuhQcZtZxx4ai3AE "Ruby – Try It Online")
A lambda accepting a 2d array of ints (or strings, I guess). Takes inspiration from [Jo King's answer](https://codegolf.stackexchange.com/questions/169919/how-much-is-my-dice-matrix-worth/169926#169926). I feel like slicing the dice out of the input matrix took a lot of space, so I may well be outgolfed. Fortunately, dealing with nils only cost me a handful of bytes.
Ungolfed:
```
->m{
  m.each_slice(3).flat_map{|r|             # Split into groups of 3 rows
    r.transpose.each_slice(3).map{|d|      # Split into groups of 3 columns
      " \x10āđŅŕǇ  DT  ŭ".chars.map(&:ord) # [0,16,257,273,325,341,455,0,0,68,84,0,0,365]
        .index(                            # Find in that array
          d.flatten.join.to_i 2            #   the die flattened into a bitstring (nil if not found)
        )&.%7                              # Safe-modulo 7 (leaves nils as nil)
    }-[p]                                  # Remove nils
  }.sum                                    # Add 'em up
}
```
[Answer]
## Clojure, 197 bytes
```
#(apply +(for[R[range]i(R 0(count %)3)j(R 0(count(% 0))3)](case(apply +(map *(iterate(partial * 2)1)(for[x(R 3)y(R 3)]((%(+ i x))(+ j y)))))16 1 257 2 68 2 273 3 84 3 325 4 3 4 1 5 455 6 365 6 0)))
```
I should have come up with something smarter.
[Answer]
# [Python 2](https://docs.python.org/2/), 159 bytes
```
f=lambda a:a>[]and sum(u'ȀāDđTŅȀŕȀǇŭ'.find(unichr(int(J(J(map(str,r[i:i+3]))for r in a[:3]),2)))/2+1for i in range(0,len(a[0]),3))+f(a[3:])
J=''.join
```
[Try it online!](https://tio.run/##jVI9b8IwEJ2bqT/hJIbYikt9CUVtJCohdWLuFmVwgYArMCgkQzc6VJ079Gf0X4DKv6IOmI8kFqoiS8@@e@/e3WX@lo1nyt82oD8bSDUKIc@Sm/tt0pmI6ctAgAjFYxQLNYBFPiW5e71Zrt6fVl/P64/Ncv29Wf5@rn/cZiLVgORK9scpkSojPf1NxZwsspSlkQylF8SUJrMUUpAKRBTqO/Mppbe@h8W7LN5ToUZDwtlkqIiIuE4JKPUSjYMwpk6v47rN15lU2i935qmuBAmJIAJknHGImQP6oiHDw8VEQNOdBvglVimRn0uUWRwIBw84rbP3p6TB6mYOWUbvAUig9XaH1vswIhUZPGlXS5pcZvoxVdpA2nXXWB3OPy@8EjFFsAXkTldpm35s1fZftZOqZDnr1JBtBJeGi7pv1E5846hVuCoc1rdXGqrFn225ZyyLfYa1X4rhcUOXGDv3TrcTwVW04@nUAuER7d80xLPwOUIL2kfRTsaLZKyQrwy2ieNJ3Eavhe0ILdrFmxM7x9116Xb7Bw "Python 2 – Try It Online")
Hat tip to [Jonathan Frech](https://codegolf.stackexchange.com/users/73111/jonathan-frech) for the unicode encoding approach.
]