One liner & Code Golf | Contest
I invite everyone to the contest, which will take place on August 1, 2023 at 15:00UTC
Contest Rules:
In this contest, you need to write one-line solutions for problems.
The solution is scored by the length of the code (Code Golf). No penalties.
Only Python.
Contest info:
Number of problems: 8
Duration: 3 hours
Link to the platform: https://cpython.uz/competitions/contests/
P.S. Registration on the platform only via Gmail/Github. The submit button is in the right bottom corner.
UPD
Contest is finished
Best solutions:
A. One Line | Divisible
B. One Line | List
C. One Line | Coordinate plane
D. One Line | Triple sort
E. One Line | Next year
F. One Line | Team Competition
G. One Line | Remaining at 7
H. One Line | Number of components
Are you allowed to zip up your code with exec and bytes to reduce size?
I forgot about additional conditions for each problem: The := and ; operators must not be present in the code and it is forbidden to use exec function.
eval
andcompile
should be disabled as well.They are practically useless in such contests.
Fun!
Are the others' solutions viewable after the contest?
Of course, Paid only))
Idk. Assuming you were rank #2 (I squeezed out rank #1 by clutching up on problem F), I'm very curious to see how to do G / H? Also the best solution to E must be amazing :eyes:
I fell asleep, so you won :xD
Oh lol, I guess you were #2, my bad. Apparently I don't know how to read usernames. How did you solve G/H?
If you have KEPCOIN, you can see other attempts. Admin can also provide shortest solutions
Welp, I'm a cheapskate, so I guess I'll hope the admin provides them in this blog :) (or you just post your codes for free :P )
Wait a while. I'll post the best solutions here.
No, I'm in place 4-5 (didn't solve H).
My main interest in others' solutions is the "common knowledge" regarding one-line code in Python by the given rules. For example, how do people use imports, assign variables, etc, and make it short. I'm sure missing some of that.
Pretty much just make sure you are comfortable with comprehensions, ternary expressions, unpacking, using
open(0)
for input, using__import__
for imports, using__setitem__
in lists, and a million nested lambdasThanks! Of these, I didn't know to use
open(0)
, and__setitem__
-ed only in dictionaries. My typical solution looked likeprint((lambda _,a:...)(input(),input().split()))
or some such.It's amazing how you solved E without using the datetime module
It's just this formula: https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week, section "Gauss's algorithm" (the full link doesn't work).
By then, I did not learn to use imports :) .
sir, your link not work.
Wow, I didn't find / wasn't aware of that formula. I spammed the datetime module:
BTW your solution has an obvious improvement:
[i+1 for
can be shortened to[i+1for
Yeah, and maybe
open(0)
can save a few bytes too.Following the format of my code,
works in 97 characters, a 12 character improvement over the original. Essentially, I use the trick that
.index()
takes in an additional argument where you can specify a certain suffix to search in. The arguments' order have to be reversed though, so I read in the input into a list, reverse it, and use the unpacking operator.