脑干,219字节
+[+[>+],[>-]>[<]>[-]++++[-]<--<+>+<+>>>+>>+>+<<<<<<>[<>-]<->+<[[-]+[>]<>+<>[>-]]>>[>>+<<>>-[>>.<>>[[-]
(要求使用磁带,该磁带要么允许指针转到负数,要么在尝试时循环到末尾。还要求,在EOF处返回0。以我的经验,大多数解释器默认情况下都满足这些要求。)
事实证明这很容易!如果它是可打高尔夫球的,我不会感到惊讶(我对可能会浪费字节的地方有所了解,但我不确定它是否会成功使用)。尽管如此,让它开始工作并不是真正的挑战。
此代码将ASCII值小于97的所有内容都视为大写字符。如果第一个字符是空格,它将尝试从字符串中删除所有出现的“小写空格”(chr(32+32)即@)。可以,因为只会出现字母和空格。
有评论:
to make comments shorter: everywhere it says "fc" means "first character"
#################################### GET FC ####################################
+[+[>+] shortest way to get 96
any number above 89 and less than 97 would work because this
is only for figuring out if the first character is capital
,[>-] create two copies of the first character
### current tape: | fc | fc | 000 | 096 | ###
### pointer: ^ ###
########################### FIND MAX(FC MINUS 96; 0) ###########################
>[ 96 times:
<< go to the cell with the first char
[->] if not 0: sub one and move right
### current tape: | fc | char being worked on | 000 | 096 | ###
### pointer: ^ OR ^ ###
>[ collapse the wavefunction; sync the branches
-]
### current tape: | fc | fc is lowercase ? nonzero : zero | 000 | 000 | ###
### pointer: ^ ###
############################# GET BOTH CASES OF FC #############################
++++[-] get 32 (add to uppercase character to get lowercase)
<
[-] clear the lowercase flag
----[>-- sub 64 from the cell with 32
+>+<
### current tape: | 000 | fc | other case of fc | ###
### pointer: ^ ###
###################### LOOP THROUGH REMAINING CHARACTERS #######################
[>+>>>+>>+>+<<<<<<
make four copies
(only 3 are strictly needed; 4th will resync a branch)
>> go to the first case of fc
[<>-]<->+<
>[[-]+
>[>]<< go to the other case of fc (and resync branches)
[>>+<>[>-] subtract other case of fc from other copy
] if the result is nonzero set it to 1
>>[
<<<>>+<<>> add results together
- subtract 1
if the character exactly matched either case: 1 plus 0 minus 1 = 0
if the character exactly matched neither case: 1 plus 1 minus 1 = 1
if the character exactly matched both cases: impossible
[ if the result is 1:
>>.<< output character
- set cell to 0 to kill loop
]
>>>[[-]
<<<<
]