+2Rṫ-4>Ðḟ⁹1;;QµI’a3R”.ṁ⁸żẎ
Ị¬;n“¢©ỵY“¡&ç»ẋ"W€jçLÐfKṣ⁸j⁸WŒṘ¤
完整程序*将结果打印到STDOUT。接受参数current
和total
该命令。
在线尝试!或查看测试套件。
怎么样?
+2Rṫ-4>Ðḟ⁹1;;QµI’a3R”.ṁ⁸żẎ - Link 1, numbers and ellipses: current, total
- e.g. 52, 173
2 - literal two 2
+ - add to current 54
R - range [1,2,3,...,53,54]
-4 - literal minus four -4
ṫ - tail from index (i.e. right five) [50,51,52,53,54]
⁹ - chain's right argument, total 173
Ðḟ - filter discard if:
> - greater than? [50,51,52,53,54]
1 - literal one 1
; - concatenate [1,50,51,52,53,54]
; - concatenate (implicit right = total) [1,50,51,52,53,54,173]
Q - unique (remove excess 1 and/or total) [1,50,51,52,53,54,173]
µ - new monadic chain, call that X
I - incremental differences [49,1,1,1,1,119]
’ - decrement (vectorises) [48,0,0,0,0,118]
3 - literal three 3
a - logical and (vectorises) [3,0,0,0,0,3]
R - range (vectorises) [[1,2,3],[],[],[],[],[1,2,3]]
”. - literal '.' character '.'
ṁ - mould like that [['.','.','.'],[],[],[],[],['.','.','.']]
⁸ - chain's left argument, X [1,50,51,52,53,54,173]
ż - zip with that [[1,['.', '.', '.']],[50,[]],[51,[]],[52,[]],[53,[]],[54,['.','.','.']],[173]]
Ẏ - tighten [1,['.', '.', '.'],50,[],51,[],52,[],53,[],54,['.','.','.'],173]
Ị¬;n“¢©ỵY“¡&ç»ẋ"W€jçLÐfKṣ⁸j⁸WŒṘ¤ - Main link: current, total e.g. 52, 173
Ị - insignificant? (abs(current)<=1) 0
¬ - logical not 1
n - not equal (current != total) 1
; - concatenate [1,1]
“¢©ỵY“¡&ç» - list of compressed strings [['p','r','e','v'], ['n','e','x','t']]
" - zip with:
ẋ - repeat (zeros -> empty lists) [['p','r','e','v'], ['n','e','x','t']]
W€ - wrap €ach (prep for the join) [[['p','r','e','v']], [['n','e','x','t']]]
ç - call last link (1) as a dyad [1,['.', '.', '.'],50,[],51,[],52,[],53,[],54,['.','.','.'],173]
j - join [['p','r','e','v'],1,['.','.','.'],50,[],51,[],52,[],53,[],54,['.','.','.'],173,['n','e','x','t']]
Ðf - filter keep if:
L - length (removes empty lists) [['p','r','e','v'],1,['.','.','.'],50,51,52,53,54,['.','.','.'],173,['n','e','x','t']]
K - join with spaces ['p','r','e','v',' ',1,' ','.','.','.',' ',50,' ',51,' ',52,' ',53,' ',54,' ','.','.','.',' ',173,' ','n','e','x','t']
⁸ - chain's left argument, current 52
ṣ - split at that [['p','r','e','v',' ',1,' ','.','.','.',' ',50,' ',51,' ',],[,' ',53,' ',54,' ','.','.','.',' ',173,' ','n','e','x','t']]
¤ - nilad followed by link(s) as a nilad:
⁸ - chain's left argument, current 52
W - wrap [52]
ŒṘ - Python string representation ['[','5','2',']']
j - join ['p','r','e','v',' ',1,' ','.','.','.',' ',50,' ',51,' ','[','5','2',']',' ',53,' ',54,' ','.','.','.',' ',173,' ','n','e','x','t']
- implicit print prev 1 ... 50 51 [52] 53 54 ... 173 next
*作为current
左右total
两边的二元链接,它返回一个包含字符和整数的列表;此列表包括空格。但是K
不能简单地删除字节以遵守规范,因为结果将放在括号中并current
作为单独的字符(如[...'[','5','2',']'...]
),因此“将每个项目转换为字符串并以单个空格将它们连接”将无法产生所需的结果)
4 , 6
作为测试用例。与3, 6
情况类似,但要确保点未添加到左侧。