挑战
按字符计数显示的最短代码,它将输出与Excel列字符串等效的数值。
例如,A
列是1,B
是2,依此类推。点击Z
后,下一列变为AA
,然后是AB
,依此类推。
测试用例:
A: 1
B: 2
AD: 30
ABC: 731
WTF: 16074
ROFL: 326676
代码计数包括输入/输出(即完整程序)。
发布于 2010-04-14 17:11:52
Excel,9个字符:)
使用合适的工具来完成工作:
=COLUMN()
发布于 2010-04-15 03:02:41
Brainf*ck,81个字符(无空格)
,[>>>[->>+++++[-<+++++>]<+<]>[-<+>]<<++++++++[<++++++++>-]<[<->-]<[>>>+<<<-],]>>>
解释
,[ // get character input into p[0], enter loop if it isn't null (0)
>>>[->>+++++[-<+++++>]<+<] // take what's in p[3] and multiply by 26, storing it in p[4]
>[-<+>] // copy p[4] back to p[3]
<<++++++++[<++++++++>-]< // store 64 in p[1]
[<->-]< // subtract p[1], which is 64, from the input char to get it's alphabetical index
[>>>+<<<-] // add p[0] to p[3]
,] // get another character and repeat
>>> // move to p[3], where our final result is stored
所以你会注意到我实际上并没有将数值转换成ascii字符串来打印。这很可能会毁了乐趣。但我把指针移动到结果所在的单元格上,这样至少对机器有用。
嘿你知道吗我打败了C#!
发布于 2010-04-15 11:21:20
APL
13个字符
将值放入x
x←'WTF'
然后用以下公式计算:
26⊥(⎕aV⍳x)-65
J打败我的唯一原因是因为括号。我在想,应该有一些方法来重新安排它,以避免需要它们,但这是漫长的一天。想法?
(嘿,你们这些使用30+字符解决方案的perl程序员太可爱了!)
https://stackoverflow.com/questions/2634427
复制相似问题