Lua,141个字节
n,s=1,'-1 1'function g()repeat n=n+1 until s.find(n,4)==z and n~=13 return n end for i=4,io.read(),2 do s=g()..' '..g().."\n"..s end print(s)
不打高尔夫球
n,s = 1,'-1'1' --n is the current floor number, S is the string to be printed
function g() --This function raises n to the next valid floor
repeat --Same as while loop except it runs the following block before checking the expression
n = n + 1 --Self-explanatory, increases n by one
until --Checks the expression, if it is true, it breaks out of the loop
s.find(n,4) == z --[[Strings have a member :find(X) where it finds the position of
X in the string (X can also be a pattern). However, calling it
by .find(S,X) executes find on S with argument X. I can't
directly do n:find(4) because n is a number. This is a "hack"
(sort of) to cut down some bytes. Also, if X is not a string,
lua tries to (in this case, succeeds) cast X to a
string and then look for it. I check if this is equal to z
because z is nil (because it is undefined), and find returns
nil if X is not found in S.
TL;DR: Checks if 4 is not the last digit.]]
and n ~= 13 --Self-explanatory, checks if n is not 13
return n --Self-explanatory, returns n
end
for i = 4, io.read(), 2 do --[[Start at floor 3 (shows 4 because we're going by target
floor, not by starting floor), continue until we reach
floor io.read() (io.read returns user input), increment by
2 floors per iteration)]]
s = g() .. ' ' .. g() .. "\n" .. s --[[Prepend the next floor, a space, the next floor,
and a newline to s]]
end
print(s) --Self-explanatory, output the string
在线尝试(您需要单击顶部的“执行”,然后单击底部的终端,然后键入输入;我正在寻找一种更好的方法来使用stdin和stdout在线测试lua)