˜ʒ©¹ε®å_}¹ζʒ®å_}ζ‚ζ€€OPOIQ
不排序也不统一结果。
仅在旧版中有效(目前),因为当部分内部列表是整数而其他内部列表时,sum-each似乎在做一些奇怪的事情。
在线尝试或验证所有测试用例。
说明:
˜ # Flatten the (implicit) matrix-input
# i.e. [[6,1,5],[1,2,8],[9,8,5],[6,0,4]] → [6,1,5,1,2,8,9,8,5,6,0,4]
ʒ # Filter this list by:
© # Store the current value in a register-variable
¹ # Take the matrix-input
ε } # Map it to:
®å_ # 0 if the current number is in this row, 1 if not
# i.e. [[6,1,5],[1,2,8],[9,8,5],[6,0,4]] and 6 → [0,1,1,0]
¹ # Take the matrix-input again
ζ # Swap its rows and columns
# i.e. [[6,1,5],[1,2,8],[9,8,5],[6,0,4]] → [[6,1,9,6],[1,2,8,0],[5,8,5,4]]
ʒ } # Filter it by:
®å_ # Only keep the inner lists that does not contain the current number
# i.e. [[6,1,9,6],[1,2,8,0],[5,8,5,4]] and 6 → [[1,2,8,0],[5,8,5,4]]
# i.e. [[1,2,2],[1,0,0],[0,0,1],[1,2,0]] and 1 → []
ζ # After filtering, swap it's rows and columns back again
# i.e. [[1,2,8,0],[5,8,5,4]] → [[1,5],[2,8],[8,5],[0,4]]
‚ζ # Pair both lists together and zip them
# i.e. [0,1,1,0] and [[1,5],[2,8],[8,5],[0,4]]
# → [[0,[1,5]],[1,[2,8]],[1,[8,5]],[0,[0,4]]]
# i.e. [0,1,0] and [] → [[0,' '],[1,' '],[0,' ']]
€ # Map each inner list / value to:
€O # Sum each
# i.e. [[0,[1,5]],[1,[2,8]],[1,[8,5]],[0,[0,4]]]
# → [[0,6],[1,10],[1,13],[0,4]]
# i.e. [[0,' '],[1,' '],[0,' ']]
# → [[0,0],[1,0],[0,0]]
# (NOTE: For most test cases just `O` instead of `€€O` would be enough,
# but not if we removed ALL zipped inner lists for a number, like the
# second example above with input [[1,1,0,1],[2,0,0,2],[2,0,1,0]] and 1)
P # Now take the product of each inner list
# i.e. [[0,6],[1,10],[1,13],[0,4]] → [0,10,13,0]
O # Then take the sum of those
# i.e. [0,10,13,0] → 23
IQ # And only keep those that are equal to the number-input
# i.e. 23 and 9 → 0 (falsey), so it's removed from the flattened input
[[1,5],[1],[5],[]]
对于第一个测试用例)是否是一种有效的输出方式?