Ḣị“+-“| ”ị@
1;+\Ṭ
Ç€,€/Ñ€Y
在TryItOnline上进行测试
怎么样?
输入的输入是两个列表的列表,[vertical, horizontal]并且使用了递增选项
-因此示例3将[[3,2,1,1], [2,1,4,1,3,1]]
每个参数转换为分别指示rowType或rowCharacterType的布尔数组,例如[[1,0,0,1,0,1,1,1], [1,0,1,1,0,0,0,1,1,0,0,1,1]]
,通过将行从由rowType和rowCharacterType组合标识的字符-即rowType标识"+-"或,"| "而rowCharacterType标识这两个字符之一。
Ḣị“+-“| ”ị@ - Link 1, create a row: [rowType, [rowCharaterTypes]]
Ḣ - head - get the rowType
“+-“| ” - list of strings ["+-", "| "]
ị - index into (if rowType is 1 "+-"; if rowType is 0 "| ")
ị@ - index into with reversed operands (index into that from rowCharaterTypes)
(replace each 1 in rowCharaters with "+" or "|" and each 0 with "-" or " ")
1;+\Ṭ - Link 2, create the Type lists from the inputs: int[] nCharacters
1; - 1 concatenated with the input
+\ - reduce with addition (accumulation provides the indices)
Ṭ - boolean array with 1s at those indices
As an example take the vertical of example 3:
[3,2,1,1] -> [1,3,2,1,1] -> [1,4,6,7,8] -> [1,0,0,1,0,1,1,1]
each of which will be passed as a rowType for Link 1
Ç€,€/Ñ€Y - Main link, takes one argument: [Vertical, Horizontal] (incremented option)
Ç€ - call the last link (2) for each of the two lists in the input
,€/ - pair each and reduce (making a list of [rowtype [rowCharacterTypes]])
Ñ€ - call the next link (1) for each
Y - join on line feeds