| Bytes | Lang | Time | Link |
|---|---|---|---|
| 057 | 05AB1E | 250521T105123Z | Kevin Cr |
| 386 | Maple | 250518T000400Z | dharr |
| 114 | Charcoal | 250517T144500Z | Neil |
| 048 | Jelly | 250516T183332Z | Jonathan |
| 530 | Python3 | 250516T134605Z | Ajax1234 |
05AB1E, 57 bytes
|DSðÊ.āsgä2Fø€ü3}€`ʒ€€нJJC•G¶=ÇZb°7(Ú•žAвså}æ¦ε˜ι`DÙQ*O}à
Multiple lines of input.
Try it online or verify all test cases.
Explanation:
| # Get all lines of input as a list
D # Duplicate this list of lines
S # Convert the copy to a flattened list of characters
ðÊ # != " " check on each character (0 if " "; 1 if "o")
.ā # Pair each bit with its 0-based index
s # Swap to get the list of lines again
g # Pop and push its length (amount of lines)
ä # Split the list of bit+index into that many equal-sized parts
2Fø€ü3} # Get all overlapping 3x3 blocks:
2F } # Loop 2 times:
ø # Zip/transpose; swapping rows/columns
€ # Map over each list:
ü5 # Convert it to an overlapping list of quintets
€` # Flatten this list of lists of 3x3 blocks one level down
ʒ # Filter this list of 3x3 blocks by:
€€ # Nested map:
н # Only keep the first item (the bit)
JJ # Join the bits of this 3x3 block together
C # Convert it from a binary-string to a base-10 integer
•G¶=ÇZb°7(Ú• # Push compressed integer 76186575295082998979527
žAв # Convert it to base-512 as list: [16,68,84,257,273,325,341,365,455]
s # Swap so the integer is at the top
å # Check whether it's in this list
}æ # After the filter: get the powerset of valid dominoes
¦ # Remove the leading empty list
ε # Map over each list of 3x3 blocks of bit+index pairs:
˜ # Flatten it to a single list
ι # Uninterleave into two parts to get a pair of lists,
# one list of all bits, and one list of the indices
` # Pop and push both lists to the stack
DÙQ # Check that all indices are unique:
D # Duplicate the list
Ù # Uniquify the copy
Q # Check that the two lists are still the same
* # Multiply this check to the list of bits
O # Get the sum of this list of bits
}à # After the map: pop and leave the maximum sum
# (which is output implicitly as result)
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, 392 386 bytes
proc(X)M:=Matrix;s:=seq;Q:=M(subs(" "=0,"o"=1,[s]~(StringTools:-Split(X,"\n"))));r,c:=op(1,Q)-~2;max(map(x->add(add~(map2(op,1,x))),select(Z->nops({map(x->op(op(2,x)),Z)[]})=9*nops(Z),combinat:-powerset(select(x->ormap(EqualEntries,map(x->M(3,convert(x,base,2)),[365,455,341,325,273,84,257,68,16]),x[1]),[s(s([Q[(R:=i..i+2),(C:=j..j+2)],{s(s([m,n],m=R),n=C)}],j=1..c),i=1..r)])))))end;
Slightly ungolfed:
proc(X)M:=Matrix;s:=seq; # abbreviate Matrix and seq commands
F:=map(x->M(3,convert(x,base,2)), # make 3x3 matrices of 0s and 1s
[365,455,341,325,273,84,257,68,16]); # from coded allowed faces
Q:=M(subs(" "=0,"o"=1,[s]~(StringTools:-Split(X,"\n")))); # string to Matrix of 0s and 1s
r,c:=op(1,Q)-~2; # numbers of rows and columns minus 2
# next line finds all possible 3x3 blocks and their coordinates (as a set of [i,j] pairs)
B:=[s(s([Q[(R:=i..i+2),(C:=j..j+2)],{s(s([m,n],m=R),n=C)}],j=1..c),i=1..r)];
B:=select(x->ormap(EqualEntries,F,x[1]),B); # filter out bad faces
P:=combinat:-powerset(B); # all subsets of blocks
W:=select(Z->nops({map(x->op(op(2,x)),Z)[]})=9*nops(Z),P); # filter out overlapping blocks
max(map(x->add(add~(map2(op,1,x))),W)) # add block entries to get totals and find maximum
end:
Acceptable faces are coded as bit patterns converted to decimal. After decoding they are stored as 3x3 matrices with 0 or 1 entries.
The string is also converted to an (0,1)-matrix. All 3x3 submatrices are found and checked against the valid faces. Then all possible subsets of the set of remaining submatrices are found. Ones with overlapping coordinates are removed, and then the totals are found and the max taken.
Charcoal, 114 bytes
WS⊞υι≔⟦⟧ηF⁻Lυ²F⁻L貫≔⭆✂υι⁺³ι¹✂λκ⁺³κ¹ζ¿№I⪪”)″GG0G¤E-✳?^≦”³⍘ζ o⊞η⟦ικ№ζo⟧»≔⟦⟦⟧⟧υFυFηF⬤ι⊙…벋²↔⁻ν§κξ⊞υ⁺ι⟦κ⟧I⌈Eυ↨¹Eι§λ²
Try it online! Link is to verbose version of code. Takes a list of newline-terminated equal-length strings as input. Explanation:
WS⊞υι
Input the strings.
≔⟦⟧ηF⁻Lυ²F⁻L貫
Start enumerating dice faces.
≔⭆✂υι⁺³ι¹✂λκ⁺³κ¹ζ
Extract the next potential face.
¿№I⪪”)″GG0G¤E-✳?^≦”³⍘ζ o
If this is a valid face (as per my answer to the related question), then...
⊞η⟦ικ№ζo⟧
... add its position and value to the list.
»≔⟦⟦⟧⟧υFυFη
Start building up permutations of that list.
F⬤ι⊙…벋²↔⁻ν§κξ
If this face does not overlap any of the existing faces in this permutation, then...
⊞υ⁺ι⟦κ⟧
... add a new permutation that includes this face to the list.
I⌈Eυ↨¹Eι§λ²
Output the highest total found.
Jelly, 48 bytes
O%3C×Jṣ0ṡ3Z€ṡ€3ẎŒPFQƑ$Ƈµ>0FḄe“Ñ4ÑḌÑ4ÑðZ‘ĤƲƇFS)Ṁ
A monadic Link that accepts a list of characters (including the newline characters) and yields the maximal pip-count.
Try it online! (Too inefficient for anything much bigger within one minute.)
How?
O%3C×Jṣ0ṡ3Z€ṡ€3ẎŒPFQƑ$Ƈµ>0FḄe“...‘ĤƲƇFS)Ṁ - Link: list of characters, Sheet
O%3C - ordinals, mod three, complemented
×J - multiply by 1-indices
'o' -> +i, ' ' -> -i, '\n' -> 0
ṣ0 - split at zeros
ṡ3 - slices of length three
Z€ - transpose each
ṡ€3 - slices of each of length three
Ẏ - tighten -> list of possible 3×3s
ŒP - powerset -> all selections (including overlaps)
$Ƈ - keep those for which:
F - flatten
QƑ - is invariant when deduplicated
-> all non-overlapping selections
µ ) - for each:
>0 - greater than zero? (i.e. recover isPip values)
ƲƇ - keep those for which:
F - flatten
Ḅ - convert from binary -> ID
¤ - nilad followed by links 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}?
F - flatten
S - sum
Ṁ - maximum
Python3, 530 bytes
R=range
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)
def f(b):
q,s,o=[([],[],0)],[],[]
N,M=len(b),len(b[0])
for t,e,c in q:
F=1
for x in R(N):
for y in R(M):
U={(J,K)for J in R(x,x+3)for K in R(y,y+3)}
if all(not U&u for u in t)and(E:=sorted(e+[(x,y)]))not in o and x+3<=N and y+3<=M and(v:=V([[int(J=='o')for J in j[y:y+3]]for j in b[x:x+3]])):q+=[(t+[U],E,c+v)];F=0;o+=[E]
if F:s+=[c]
return max(s)