对于今天的挑战,您必须编写一个程序或函数来交替字符串的情况。但是,您必须忽略非字母字符.这意味着每个字母字符必须有一个与前面和后面的字母字符不同的大小写。例如,这比每一个字母都要复杂一些。如果您使用字符串,如
hello world将所有其他字符转换为大写,您将得到:
hElLo wOrLd如您所见,小写o后面跟着小写w。这是无效的。相反,您必须忽略这个空间,给出以下结果:
hElLo WoRlD所有非字母字符必须保持不变。只要输出始终交替,输出可以从大写或小写开始。这意味着以下也是可以接受的产出:
HeLlO wOrLd无论输入的情况如何,您的程序都应该工作。
输入字符串将只包含可打印ASCII,因此不必担心不可打印的字符、换行符或unicode。您的提交既可以是一个完整的程序,也可以是一个函数,您可以以任何合理的格式接受输入和输出。例如,函数参数/返回值、STDIN/STDOUT、读/写文件等。
ASCII -> AsCiI
42 -> 42
#include <iostream> -> #InClUdE <iOsTrEaM>
LEAVE_my_symbols#!#&^%_ALONE!!! -> lEaVe_My_SyMbOlS#!#&^%_aLoNe!!!
PPCG Rocks!!! For realz. -> PpCg RoCkS!!! fOr ReAlZ.
This example will start with lowercase -> tHiS eXaMpLe WiLl StArT wItH lOwErCaSe
This example will start with uppercase -> ThIs ExAmPlE wIlL sTaRt WiTh UpPeRcAsE
A1B2 -> A1b2因为这是密码-高尔夫,标准的漏洞会被应用,以字节为单位的最短答案将获胜!
发布于 2017-05-25 17:35:30
发布于 2017-05-25 17:21:39
nŒsTm2
ŒlŒuǦŒlŒsǦ Main link. Argument: s (string)
Œl Cast to lowercase.
Ǧ At indices returned by the helper link...
Œu apply uppercase.
nŒsTm2 Helper link. Argument: s (string)
Œs Apply swapcase to s.
n Perform vectorizing not-equal comparison.
T Compute the truthy indices.
m2 Select every other one, starting with the first.发布于 2017-05-27 04:56:03
/olZlYuN
@iy.u..//这个程序遵循一个不太为人所知的奇数长度程序模板,它完全以序数模式运行.此代码的线性化版本是:
il.l.uN.YuZyo@对守则的解释:
i - push input onto stack ["Hello world!"]
l - convert to lowercase ["hello world!"]
. - duplicate ["hello world!", "hello world!"]
l - convert to lowercase (should be no-op, but avoids what seems to be a bug in the TIO implementation)
. - duplicate again ["hello world!", "hello world!", "hello world!"]
u - convert to uppercase ["hello world!", "hello world!", "HELLO WORLD!"]
N - difference between sets ["hello world!", "helloworld"]
. - duplicate reduced string ["hello world!", "helloworld", "helloworld"]
Y - unzip (extract even positions) ["hello world!", "helloworld", "hlool", "elwrd"]
u - convert to uppercase ["hello world!", "helloworld", "hlool", "ELWRD"]
Z - zip evens back into string ["hello world!", "helloworld", "hElLoWoRlD"]
y - perform substitution ["hElLo WoRlD!"]
o - output []
@ - terminate如果在复制时不使用l,则N后面的堆栈将是["helloworld", "helloworld"]。我强烈怀疑这是个窃听器。
https://codegolf.stackexchange.com/questions/122783
复制相似问题