We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hi! Your improvement got me thinking, how to combine those statements into one, and this seems to work? Rather than wrap your statement inside of another string and format, I wrapped the exec with a lambda, and applied it to the input. There's a copy online to play with.
I also tried to use "+s+" instead of {1} and ,s, but both use five characters, so there's not a big improvement.
=====
That got me thinking though... what about using another nested lambda instead of format and exec? I tweaked it again, and got a new version. Cool. But what about the import statement? With a little syntactic trickery, we can turn sqrt into n**0.5, and I learned you can replicate the ceil function by doing -(-n//1) instead. Finally! A single statement.
# This is all one line, I swear. Only three spaces total. (lambdas:(lambdar:print(' '.join(map(lambdax:s[x::r],range(r)))))(int(-(-(len(s)**0.5)//1))))(input().strip())
# Here's the statement blown up to make things clearer. Maybe. (lambdas:(lambdar:print(' '.join(map(lambdax:s[x::r],range(r)))))(int(-(-(len(s)**0.5)//1))))(input().strip())
# And here's that second parameter, blown up too. int(-(-(len(s)**0.5)//1))
I hope some one gets a kick out of that like I did. ;) It's not great code golf, but it is satisfying to put it all together on one line. Especially since it's, well, python, hehe.
Encryption
You are viewing a single comment's thread. Return to all comments →
Hi! Your improvement got me thinking, how to combine those statements into one, and this seems to work? Rather than wrap your statement inside of another string and format, I wrapped the exec with a lambda, and applied it to the input. There's a copy online to play with.
I also tried to use
"+s+"
instead of{1}
and,s
, but both use five characters, so there's not a big improvement.=====
That got me thinking though... what about using another nested lambda instead of format and exec? I tweaked it again, and got a new version. Cool. But what about the import statement? With a little syntactic trickery, we can turn
sqrt
inton**0.5
, and I learned you can replicate theceil
function by doing-(-n//1)
instead. Finally! A single statement.I hope some one gets a kick out of that like I did. ;) It's not great code golf, but it is satisfying to put it all together on one line. Especially since it's, well, python, hehe.
References: Python grammar, Ceiling function.