Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 736 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

05AB1E, 7257 bytes

¶.ø.Bðδ.øDSðÊ|DSðÊ.āsgä2Fø€ü5āsgä2Fø€ü3}€`ε¦ ̈ε¦ ̈]ʒ€€нJJC•G¶=ÇZb°7€`ʒ€€нJJC•G¶=ÇZb°7(Ú•žAвså}æ¦ε ̃ι`DÙQ*O}à

Input as a multi-line stringMultiple lines of input.

Try it online Try it online or verify all test cases verify all test cases.

¶.ø # Surround the (implicit) input-string with newline characters
.B # Box it; add trailing spaces to each line to make them equal lengths,
 # and then split by newlines
| δ # Map over each line:
 ð .ø  #Get all Surroundlines theof lineinput withas leading/trailinga spacelist
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ø€ü52Fø€ü3} # Get all overlapping 5x53x3 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 5x53x3 blocks one level down
ε¦ ̈ε¦ ̈] # Only leave the inner 3x3 block of each 5x5 block:
ε # Map over each 5x5 block:
 ¦ ̈ # Remove the first/last rows
 ε # Inner map over each inner line:
 ¦ ̈ # Remove the first/last items
 ] # Close the nested map
ʒ # 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)

05AB1E, 72 bytes

¶.ø.Bðδ.øDSðÊ.āsgä2Fø€ü5}€`ε¦ ̈ε¦ ̈]ʒ€€нJJC•G¶=ÇZb°7(Ú•žAвså}æ¦ε ̃ι`DÙQ*O}à

Input as a multi-line string.

Try it online or verify all test cases.

¶.ø # Surround the (implicit) input-string with newline characters
.B # Box it; add trailing spaces to each line to make them equal lengths,
 # and then split by newlines
 δ # Map over each line:
 ð .ø  # Surround the line with leading/trailing space
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ø€ü5} # Get all overlapping 5x5 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 5x5 blocks one level down
ε¦ ̈ε¦ ̈] # Only leave the inner 3x3 block of each 5x5 block:
ε # Map over each 5x5 block:
 ¦ ̈ # Remove the first/last rows
 ε # Inner map over each inner line:
 ¦ ̈ # Remove the first/last items
 ] # Close the nested map
ʒ # 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)

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.

| # 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)
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

05AB1E, 72 bytes

¶.ø.Bðδ.øDSðÊ.āsgä2Fø€ü5}€`ε¦ ̈ε¦ ̈]ʒ€€нJJC•G¶=ÇZb°7(Ú•žAвså}æ¦ε ̃ι`DÙQ*O}à

Input as a multi-line string.

Try it online or verify all test cases.

Explanation:

¶.ø # Surround the (implicit) input-string with newline characters
.B # Box it; add trailing spaces to each line to make them equal lengths,
 # and then split by newlines
 δ # Map over each line:
 ð .ø # Surround the line with leading/trailing space
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ø€ü5} # Get all overlapping 5x5 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 5x5 blocks one level down
ε¦ ̈ε¦ ̈] # Only leave the inner 3x3 block of each 5x5 block:
ε # Map over each 5x5 block:
 ¦ ̈ # Remove the first/last rows
 ε # Inner map over each inner line:
 ¦ ̈ # Remove the first/last items
 ] # Close the nested map
ʒ # 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].

AltStyle によって変換されたページ (->オリジナル) /