| Bytes | Lang | Time | Link |
|---|---|---|---|
| 104 | Perl 5 p0 | 250522T183728Z | Xcali |
| 120 | Ruby | 250516T181244Z | Jordan |
| 043 | 05AB1E | 250521T075100Z | Kevin Cr |
| 190 | Maple | 250518T042950Z | dharr |
| 115 | Python | 250517T151219Z | Albert.L |
| 136 | ScoobertyDoo | 250516T200056Z | Tim Scur |
| 034 | Jelly | 250516T130915Z | Jonathan |
| 097 | J | 250516T123617Z | Galen Iv |
| nan | Python3 | 250516T172927Z | ajc2000 |
| 089 | APL+WIN | 250516T153952Z | Graham |
| 323 | Python3 | 250516T012634Z | Ajax1234 |
| 050 | Charcoal | 250516T083304Z | Neil |
| 108 | JavaScript Node.js | 250516T010229Z | l4m2 |
Perl 5 -p0, 104 bytes
map{($i++%2?$l:$r).=oct"0b".y/o /10/r}/...\|/g;$_=(2==grep/$l|$r/,707,555,525,505,421,124,401,104)*y/o//
Ruby, 120 bytes
-11 bytes thanks to Value Ink
Takes an array of arrays of characters as input. Raises an error on invalid inputs.
->a{b=a[1,3].transpose
[1,7].sum{[16,p,68,257,84,273,325,p,341,p,365,455].index(b[_1,3].join.tr(" o","01").to_i 2)/2+1}}
05AB1E, 43 bytes
3L12*2Ýδ+˜D6+‚èðÊDJCU˜O•G¶=ÇZb°7(Ú•žAвXåP*
Input as a multi-line string.
Try it online or verify all test cases.
Explanation:
3L # Push list [1,2,3]
12* # Multiply each by 12: [12,24,36]
2Ý # Push list [0,1,2]
δ # Apply double-vectorized on both lists:
+ # Add them together
˜ # Flatten this list of lists: [12,13,14,24,25,26,36,37,38]
D # Duplicate this list
6+ # Add 6 to each: [18,19,20,30,31,32,42,43,44]
‚ # Pair the two lists together
è # Get the characters at those indices in the (implicit) input-string
ðÊ # != " " on each character (0 if " "; 1 if "o")
D # Duplicate this pair of bit-lists
J # Join the inner lists together in the copy
C # Convert from binary-strings to base-10 integers
U # Pop and store this pair of integers into variable `X`
˜ # Flatten the pair of bit-lists
O # Sum all together
•G¶=ÇZb°7(Ú• # Push compressed integer 76186575295082998979527
žAв # Convert it to base-512 as list: [16,68,84,257,273,325,341,365,455]
X # Push pair `X`
åP # Check that both values of `X` are in this list
* # Multiply that check to the earlier sum
# (after which the result is output implicitly)
See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •G¶=ÇZb°7(Ú• is 76186575295082998979527 and •G¶=ÇZb°7(Ú•žAв is [16,68,84,257,273,325,341,365,455].
Maple, 190 bytes
proc(s)r:=$13..15;L:=[r,r+~12,r+~24];S:=subs("o"=1," "=0,[[seq(s[i],i=L)],[seq(s[i],i=L+~6)]]);`if`({(op@convert)~(S,base,2,512)[]}subset{365,455,341,325,273,84,257,68,16},add(op~(S)),0)end:
Slightly ungolfed:
f:=proc(s)
T:={365,455,341,325,273,84,257,68,16}; # coded valid faces
r:=$13..15; # generate ...
L:=[r,r+~12,r+~24]; # positions of first die
S:=subs("o"=1," "=0,[[seq(s[i],i=L)],[seq(s[i],i=L+~6)]]); # both dice as list of lists of 0s and 1s
`if`({(op@convert)~(S,base,2,512)[]}subset T,add(op~(S)),0) # check valid and add or return 0
end;
Acceptable faces are coded as bit patterns converted to decimal. The locations in the string with the 9 characters of each dice are extracted and converted to a list of lists of 0s and 1s. They are converted to decimal to check validity, and if valid are added; otherwise 0 is returned.
Python, 115 bytes
lambda s:all('o'in(r:=(4*s)[k:~9:12])>r[1]<r[2:]>r[5]<r==r[::-1]!=' 'in r[6::5]+r[5:7]for k in b'HN')*s.count('o')
Python, 116 bytes
lambda s:all('o'in(r:=(3*s)[k:~9:12])>r[1]<r[2:]>r[5]<r==r[::-1]!=' 'in r[6::5]+r[5:7]for k in(13,19))*s.count('o')
Python, 119 bytes
lambda s:all('o'in(r:=(3*s[13:48])[k::12])>r[3]<r[2:]>r[1]<r==r[::-1]!=' 'in r[4::3]+r[3:5]for k in(0,6))*s.count('o')
Scooberty-Doo, 136 bytes
ṣ”ḌÑ4𓏞𓏴𓎝2ŒḌÑ4e“Ñ4ÑḌ𓎛𓅂“4ÑðZ⬤ḌÑ4341 325 [:,3}.27‘[:,𓏵}Ñ4¤ƲƇ§§Äṫ2№ḌSḌÑ4fḌÑ4³I∧υÑ4ḌÑ4;
Jelly, 34 bytes
ṣ”|OḂḊm2ŒœFḄe“Ñ4ÑḌÑ4ÑðZ‘ĤƲƇ§§Äṫ2S
A monadic Link that accepts a list of characters (including the newline characters) and yields the count of pips if valid, otherwise 0.
Try it online! Or see the test-suite.
How?
ṣ”|OḂḊm2ŒœFḄe“...‘ĤƲƇ§§Äṫ2S - Link: list of characters, Dice
ṣ”| - split at '|' characters
O - ordinals
Ḃ - mod two -> 'o' -> 1, ' ' -> 0 (others, don't care)
Ḋ - dequeue
m2 - every other element
Œœ - split into odd and even indexed elements
ƲƇ - keep those for which:
F - flatten
Ḅ - convert from binary -> ID
¤ - nilad followed by link(s) as a nilad:
“...‘ - code-page indices -> [16,52,16,173,16,52,16,24,90]
Ä - cumulative sums -> [16,68,84,257,273,325,341,365,455]
e - {ID} exists in {that}?
§ - sums
§ - sums -> Pip-counts of valid dice
Ä - cumulative sums
ṫ2 - tail from 1-index two
-> [sum(Pip-count)] if both valid, [] otherwise
S - sum -> sum(Pip-count) if both valid, zero otherwise
J, 97 bytes
[:(*@*/*1#.,@#:)365 455 341 325 273 81 257 68 16([+/@:*=/)[:(_9#.\'o'=[:,3}.@|.])@|:'|'-."1~}.@}:
Python3, 177 133 bytes
Updated answer upon realizing the problem states it is acceptable to raise an Exception in the invalid format case.
lambda s:sum({365:6,455:6,341:5,325:4,273:3,84:3,257:2,68:2,16:1}[sum(ord(s[44-i%3-i//3*12-z])%2<<i for i in range(9))]for z in[0,6])
APL+WIN, 89 bytes
Prompts for a 5x11 matrix of the two dice. Outputs the two dice together with the sum of the spots for qualifying dice or zero.
d←⎕⋄d⋄r←3⊥j←+⌿(5 ¯5↑d)='o'⋄l←3⊥i←+⌿(5 5↑d)='o'⋄(+/i,j)×2=+/8>¨(⊂9 30 39 60 69 78 90)⍳¨r l
Python3, 323 bytes
lambda b:all(K:=[V(t)for t in zip(*[[[*map(int,j.replace(' ','0').replace('o','1'))]for j in re.findall('[o ]{3}',k)]for k in b.split('\n')[1:-1]])])and sum(K)
import re
V=lambda b:sum(L:=[sum(j)for j in zip(*b)])*((not(Y:=sum(L))%2 or b[1][1])and(Y<2 or(any(b[0])and any(b[2])))and L==L[::-1]and(L[1]<=L[2]or Y==1)and Y<7)
Charcoal, 50 bytes
F²⊞υ⭆⟦ηζε⟧Φκ⁼⊗ι÷⊖ν³I∧⬤υ№I⪪”)″GG0G¤E-✳?^≦”³⍘ι o№Συo
Try it online! Link is to verbose version of code. Explanation:
F²⊞υ⭆⟦ηζε⟧Φκ⁼⊗ι÷⊖ν³
Extract the pips from the dice.
I∧⬤υ№I⪪...³⍘ι o№Συo
Interpret the pips as binary, check that both results exist in a list of possible pip patterns, and if so output the total count of pips.
JavaScript (Node.js), 108 bytes
a=>(g=p=>[12,1,y=11,13].every(k=>(s+=e=a[p+k]+2^2||y%11%k)<7&&a[y+=e*k,p-k]+2^e,s=a[p]+1^1)*s||+g)(25)+g(31)
a=>(
g=p=>
[12,1,y=11,13].every(
k=>(
s+=e= // 'o'+2^2 = 'o2'^2 = NaN^2 = 2
a[p+k]+2^2 // ' '+2^2 = ' 2'^2 = 2^2 = 0
||y%11%k // If any empty on corner,
)<7&& // then all empty on edge
a[y+=e*k // @k=12 y%11=0; y%11+=e
// @k=1 y%11%k=0; y%11+=e
// @k=11 y%11 shows; y%11+=0
// @k=13 y%11 shows; y%11+=whatever
,p-k]+2^e // Besides, it needs center symmetry
,s=a[p]+1^1 // Initial value
)*s||+g // If failed test or zero, NaNify
)(25)+g(31) // Two centers