Åœʒ23yåP}€œ€`Ùε.¥¦¨}IиI.ÆÙεøyíø‚€€üQOO_P}O
Estou quase com vergonha de postar isso, e ele definitivamente pode ser muito jogado de golfe com uma abordagem diferente, mas, como demorou um pouco para ser concluído, decidi publicá-lo de qualquer maneira e jogá-lo daqui. O desafio parece mais fácil do que é imo, mas definitivamente estou usando uma abordagem errada aqui e tenho a sensação de que 05AB1E poderia fazer cerca de 25 bytes.
Experimente online. NOTA: Além de longo, também é ineficiente, pois o 9x4
caso de teste é executado em cerca de 40 segundos no TIO.
Explicação:
Ŝ # 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
ou3x1
? Também é a saída para4x1
zero?