20L25ª3Lâ¨Ðʒθ<}Uã«XâXìε˜2ô}ʒPOQ}εε`…TSDsèì
相当慢。输出为列表列表,如果无法完成则输出为空列表。我的公牛是S25
和D25
; 如果不允许这样做,我可以更改它。
在线尝试或一次验证一些测试用例。
说明:
有几个步骤:
1)创建所有可能的单,双和三镖的列表:
20L # Create a list in the range [1,20]
25ª # Append 25 to this list
3L # Create a list in the range [1,3]
â # Create all possible pairs of these two lists
¨ # Remove the last pair (which is the Triple Bull)
# Now we have a list of all possible darts:
# [[1,1],[1,2],[1,3],[2,1],...,[20,3],[25,1],[25,2]]
2)获取所有可能的最多3支飞镖的修整器(以双结束):
Ð # Triplicate this list
ʒ } # Filter the top copy by:
θ # Where the last value
< # Decremented by 1 is truthy (==1), so all doubles
U # Pop this filtered list of doubles, and store it in variable `X`
ã # Create all possible pairs of the list of darts with itself
« # Merge it with the list of darts
# We now have a list containing all possible variations for 1 or 2 darts
Xâ # Then create all possible pairs of these with the doubles from variable `X`
Xì # And prepend the doubles themselves as well
# Now we have all possible variations of 1 double; 1 dart + 1 double;
# or 2 darts + 1 double
ε } # Map each to:
˜ # Deep-flatten the list
2ô # And split it into parts of size 2
# (this is to convert for example a 2 darts + 1 double from
# [[[20,3],[5,1]],[1,2]] to [[20,3],[5,1],[1,2]])
# Now we have a list of all possible finishers of up to 3 darts
3)只保留总分等于输入整数的那些分数:
ʒ } # Filter this list by:
P # Get the product of each inner-most lists
# i.e. [[20,3],[5,1],[1,2]] → [60,5,2]
O # Take the sum of those
# i.e. [60,5,2] → 67
Q # Check if this value is equal to the (implicit) input-integer
# Now we only have the finishers left with a total value equal to the input
4)将数据转换为漂亮的结果列表(即[[20,3],[5,1],[1,2]]
成为["T20","S5","D2"]
):
ε # Map each of the remaining finishers of up to 3 darts to:
ε # Map each inner list to:
` # Push both values separately to the stack ([20,3] → 20 and 3)
…TSD # Push string "TSD"
s # Swap to get the integer for single/double/triple at the top of the stack
è # Use it to index into the string
# NOTE: 05AB1E has 0-based indexing with automatic wraparound,
# so the triple 3 will wrap around to index 0 for character "T"
ì # Prepend this character in front of the dart-value
# (after which the result is output implicitly as result)