Åœʒ23yåP}€œ€`Ùε.¥¦¨}IиI.ÆÙεøyíø‚€€üQOO_P}O
Jestem prawie zbyt zawstydzony, aby to opublikować, i zdecydowanie może grać w golfa przez LOT z innym podejściem, ale ponieważ zajęło to trochę czasu, postanowiłem opublikować to i odtąd grać w golfa. Wyzwanie wygląda na łatwiejsze niż jest na Imo, ale zdecydowanie używam tutaj niewłaściwego podejścia i mam wrażenie, że 05AB1E może zrobić około 25 bajtów ..
Wypróbuj online. UWAGA: Jest nie tylko długi, ale także nieefektywny, ponieważ 9x4
przypadek testowy działa na TIO w około 40 sekund.
Wyjaśnienie:
Ŝ # 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
czy3x1
? Czy jest również wyjście dla4x1
zera?