Åœʒ23yåP}€œ€`Ùε.¥¦¨}IиI.ÆÙεøyíø‚€€üQOO_P}O
Estoy casi avergonzado de publicar esto, y definitivamente se puede jugar MUCHO con un enfoque diferente, pero como me llevó un tiempo completarlo, decidí publicarlo de todos modos y jugarlo desde aquí. El desafío parece más fácil de lo que es, pero definitivamente estoy usando un enfoque incorrecto aquí y tengo la sensación de que 05AB1E podría hacer alrededor de 25 bytes.
Pruébalo en línea. NOTA: No solo es largo, también es ineficiente, ya que el 9x4
caso de prueba se ejecuta en aproximadamente 40 segundos en TIO.
Explicación:
Ŝ # Get all possible ways to sum to the (first) implicit input
# i.e. 8 → [[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,2],[1,1,1,1,1,3],[1,1,1,1,2,2],[1,1,1,1,4],[1,1,1,2,3],[1,1,1,5],[1,1,2,2,2],[1,1,2,4],[1,1,3,3],[1,1,6],[1,2,2,3],[1,2,5],[1,3,4],[1,7],[2,2,2,2],[2,2,4],[2,3,3],[2,6],[3,5],[4,4],[8]]
ʒ23yåP} # Only leave those consisting of 2s and/or 3s
# → [[2,2,2,2],[2,3,3]]
€œ # For each: get all permutations
€` # Flatten this list of lists once
Ù # And uniquify it (leaving all possible distinct rows of bricks)
# → [[2,2,2,2],[3,3,2],[3,2,3],[2,3,3]]
ε } # For each:
.¥ # Get the cumulative sum
¦¨ # With the leading 0 and trailing first input removed
# → [[2,4,6],[3,6],[3,5],[2,5]]
Iи # Repeat this list the second input amount of times
# i.e. 3 → [[2,4,6],[3,6],[3,5],[2,5],[2,4,6],[3,6],[3,5],[2,5],[2,4,6],[3,6],[3,5],[2,5]]
I.Æ # Get all combinations of lists the size of the second input
Ù # And uniquify the result (leaving all possible distinct walls)
# → [[[2,4,6],[3,6],[3,5]],[[2,4,6],[3,6],[2,5]],[[2,4,6],[3,6],[2,4,6]],[[2,4,6],[3,6],[3,6]],[[2,4,6],[3,5],[2,5]],[[2,4,6],[3,5],[2,4,6]],[[2,4,6],[3,5],[3,6]],[[2,4,6],[3,5],[3,5]],[[2,4,6],[2,5],[2,4,6]],[[2,4,6],[2,5],[3,6]],[[2,4,6],[2,5],[3,5]],[[2,4,6],[2,5],[2,5]],[[2,4,6],[2,4,6],[3,6]],[[2,4,6],[2,4,6],[3,5]],[[2,4,6],[2,4,6],[2,5]],[[2,4,6],[2,4,6],[2,4,6]],[[3,6],[3,5],[2,5]],[[3,6],[3,5],[2,4,6]],[[3,6],[3,5],[3,6]],[[3,6],[3,5],[3,5]],[[3,6],[2,5],[2,4,6]],[[3,6],[2,5],[3,6]],[[3,6],[2,5],[3,5]],[[3,6],[2,5],[2,5]],[[3,6],[2,4,6],[3,6]],[[3,6],[2,4,6],[3,5]],[[3,6],[2,4,6],[2,5]],[[3,6],[2,4,6],[2,4,6]],[[3,6],[3,6],[3,5]],[[3,6],[3,6],[2,5]],[[3,6],[3,6],[2,4,6]],[[3,6],[3,6],[3,6]],[[3,5],[2,5],[2,4,6]],[[3,5],[2,5],[3,6]],[[3,5],[2,5],[3,5]],[[3,5],[2,5],[2,5]],[[3,5],[2,4,6],[3,6]],[[3,5],[2,4,6],[3,5]],[[3,5],[2,4,6],[2,5]],[[3,5],[2,4,6],[2,4,6]],[[3,5],[3,6],[3,5]],[[3,5],[3,6],[2,5]],[[3,5],[3,6],[2,4,6]],[[3,5],[3,6],[3,6]],[[3,5],[3,5],[2,5]],[[3,5],[3,5],[2,4,6]],[[3,5],[3,5],[3,6]],[[3,5],[3,5],[3,5]],[[2,5],[2,4,6],[3,6]],[[2,5],[2,4,6],[3,5]],[[2,5],[2,4,6],[2,5]],[[2,5],[2,4,6],[2,4,6]],[[2,5],[3,6],[3,5]],[[2,5],[3,6],[2,5]],[[2,5],[3,6],[2,4,6]],[[2,5],[3,6],[3,6]],[[2,5],[3,5],[2,5]],[[2,5],[3,5],[2,4,6]],[[2,5],[3,5],[3,6]],[[2,5],[3,5],[3,5]],[[2,5],[2,5],[2,4,6]],[[2,5],[2,5],[3,6]],[[2,5],[2,5],[3,5]],[[2,5],[2,5],[2,5]]]
ε # Map all walls `y` to:
ø # Zip/transpose; swapping rows and columns
yí # Reverse each row in a wall `y`
ø # Also zip/transpose those; swapping rows and columns
‚ # Pair both
€ # For both:
€ # For each column:
ü # For each pair of bricks in a column:
Q # Check if they are equal to each other (1 if truthy; 0 if falsey)
O # Then take the sum of these checked pairs for each column
O # Take the sum of that entire column
_ # Then check which sums are exactly 0 (1 if 0; 0 if anything else)
P # And check for which walls this is only truthy by taking the product
}O # After the map: sum the resulting list
# (and output it implicitly as result)
2x1
o3x1
? ¿También es la salida para4x1
cero?