Åœʒ23yåP}€œ€`Ùε.¥¦¨}IиI.ÆÙεøyíø‚€€üQOO_P}O
Ich schäme mich fast, dies zu posten, und es kann definitiv von VIELEN mit einer anderen Herangehensweise golfen werden, aber da es eine Weile gedauert hat, habe ich beschlossen, es trotzdem zu posten und von hier aus zu golfen. Die Herausforderung sieht einfacher aus als es imo ist, aber ich gehe hier definitiv falsch vor und habe das Gefühl, dass 05AB1E ungefähr 25 Bytes schaffen könnte.
Probieren Sie es online aus. HINWEIS: Es ist nicht nur lang, sondern auch ineffizient, da der 9x4
Testfall unter TIO in etwa 40 Sekunden ausgeführt wird.
Erläuterung:
Ŝ # 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
oder3x1
? Ist auch die Ausgabe für4x1
Null?