matlab怎么删除字符串中的大写字母,从整个字符串中删除所有出现的字符串首字母...

脑干,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

]

>>>[[-]

<<<<

]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值