在这个挑战中,你将写一篇文章,如果从两个不同的角度看,就会产生两个不同的程序。
从上面查看的字符串必须只包含字符ASCII 10、32-126并输出从上面查看的字符串。此外,当从左侧查看程序时,必须使用一个字符串,其中只包含字符ASCII 10、32-126,并按从左侧查看的方式输出它。
从上面查看的字符串将是字符串的每个列中的第一个非空格字符,如果不存在这样的字符,则按列的顺序排列为空格。
下面是一个Haskell程序,它实现了以下功能:
stitchZip (' ' : b) (c : d) = c : stitchZip b d
stitchZip (a : b) (c : d) = a : stitchZip b d
stitchZip [] x = x
stitchZip x [] = x
main = getContents >>= (putStr . foldr1 stitchZip . lines)从左边查看的字符串将是字符串的每一行中的第一个非空格字符,如果不存在这样的字符,则按行的相反顺序显示空格。我们颠倒了行的顺序,因为我们的左手将朝向字符串的底部。
下面是一个Haskell程序,它实现了以下功能:
stitch ' ' y = y
stitch x y = x
main = getContents >>= (putStr . reverse . map (foldl stitch ' ') . lines)您的程序可能在ASCII范围之外使用字符,但就布局而言,所有字符(换行符除外)都被认为宽度为1。作为视图工作方式的一个副作用,您的程序不能在其中包含新行(尽管字符串几乎肯定会)。
您的分数将是提交的非空格字符的数量加上两个程序中出现的空格字符的数量。
例如,如果您的程序是:
sc e ex mp e
g
a
r
d
l
o您将得到16分,因为提交中有14个非空格字符,而且每个程序(score example和old rags)都有一个空格。
你的目标是尽可能低分。
发布于 2019-10-15 17:14:59
Z
⁶
€
ɗ
o
Ḣ
ḟ
Ṛ
Ỵ自上而下:
ỴZḟḢoɗ€⁶从侧面:
ỴṚḟḢoɗ€⁶ZỴ Z|Ṛ ḟḢoɗ€⁶ [Z] - Link list of characters:
Ỵ - split at newline characters
Z - | top: transpose to get columns
Ṛ - | side: reverse the lines
⁶ - set the right argument to a literal space character
€ - for each (x = column (top) OR line (side)):
ɗ - last three links as a dyad - i.e. f(x, space)
ḟ - filter discard (spaces from x)
Ḣ - pop & yield the head (first remaining character or 0 if none left)
o - logical OR (with space character) (replace a 0 with a space)
- | top: no code remaining
Z - | side: transpose (at this point a no-op since we have a flat list)发布于 2019-10-15 15:53:02
发布于 2019-10-16 06:57:57
&
)
#
@
/
]
&
2
#
>
-
"
"
.
/
#
[
d
l
o
F
(
@
e
s
r
e
v
e
R自上而下:
Fold[#/." "->#2&]/@(#)&从侧面:
Reverse@(Fold[#/." "->#2&]/@#)&接受一个字符矩阵作为输入。如果不能保证行长度相等,则通过用18+2\times2=22替换#来添加另一个(PadRight@#/. 0->" ")。
如果输入必须是字符串列表,则通过用11替换#来添加Characters@#
如果输入必须是单个字符串,则通过用29替换#来添加Characters[#~StringSplit~"\n"]。
在这些情况下,如果不能保证行长度相等,则通过用15替换Characters来添加一个额外的Characters@StringPadRight,而不是22。
https://codegolf.stackexchange.com/questions/194296
复制相似问题