您的目标是在给定的范围内打印数字(也包括给定的值)。
输入将类似于:(int-int, int-int, ...)
...意味着用户可以添加任意数量的int-int。
int-int中的第一个整数总是较小,或相同,然后是int-int中的下一个整数。int-intint-int后面都会有一个逗号和一个空格。(10-13, 11-15, 0-3)10 11 12 13 11 12 13 14 15 0 1 2 3(1-5, 1-15)1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15(1-2, 1-3, 1-3, 1-2)1 2 1 2 3 1 2 3 1 2(4-6, 0-1, 9-9)4 5 6 0 1 9发布于 2015-11-25 07:18:06
qS/{'.,Ser~),>~}%S*Martin Büttner又杀了两个字节,谢谢
在网上试试
q read input
S/ split by space
{…}% transform each string (containing a pair of numbers and some other chars)
'., enumerate all characters smaller than '.'
Ser replace them all with a space in the string
~ evaluate the resulting string, pushing the 2 numbers on the stack
let's call them A and B
), create an array [0 1 … B]
> slice it from A: [A … B]
~ dump it onto the stack
S* join the resulting array with spaces发布于 2015-11-25 07:04:16
s->print((j=join)(map(i->j(i," "),eval(parse(replace(s,"-",":"))))," "))这是一个匿名函数,接受字符串并打印到STDOUT。要叫它,就给它起一个名字,例如f=s->...。
未高尔夫球:
function f(s::AbstractString)
# Replace dashes with colons in the input
c = replace(s, "-", ":")
# Parse as a tuple of UnitRange objects
r = eval(parse(c))
# Join each range with spaces
m = map(i -> join(i, " "), r)
# Join into one string and print
print(join(m, " "))
end发布于 2015-11-25 06:44:57
import re
print' '.join(map(lambda x:' '.join([str(y)for y in x]),eval(re.sub('(\d+)-(\d+)',r'range(\1,\2+1)',raw_input()))))在网上试试
我敢肯定这会是更多的.
https://codegolf.stackexchange.com/questions/64728
复制相似问题