Please read the new rule regarding the restriction on the use of AI tools. ×

NaZaR.IO's blog

By NaZaR.IO, 14 months ago, In English

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
  • Vote: I like it
  • +31
  • Vote: I do not like it

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Are you allowed to zip up your code with exec and bytes to reduce size?

  • »
    »
    14 months ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    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.

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      eval and compile should be disabled as well.

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        They are practically useless in such contests.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Fun!

Are the others' solutions viewable after the contest?

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Of course, Paid only))

  • »
    »
    14 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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:

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I fell asleep, so you won :xD

      • »
        »
        »
        »
        14 months ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        Oh lol, I guess you were #2, my bad. Apparently I don't know how to read usernames. How did you solve G/H?

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      If you have KEPCOIN, you can see other attempts. Admin can also provide shortest solutions

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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 )

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Wait a while. I'll post the best solutions here.

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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.

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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 lambdas

        • »
          »
          »
          »
          »
          14 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Thanks! Of these, I didn't know to use open(0), and __setitem__-ed only in dictionaries. My typical solution looked like
          print((lambda _,a:...)(input(),input().split())) or some such.

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it +6 Vote: I do not like it

        It's amazing how you solved E without using the datetime module

        • »
          »
          »
          »
          »
          14 months ago, # ^ |
          Rev. 3   Vote: I like it +6 Vote: I do not like it

          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 :) .

          • »
            »
            »
            »
            »
            »
            14 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            sir, your link not work.

          • »
            »
            »
            »
            »
            »
            14 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Wow, I didn't find / wasn't aware of that formula. I spammed the datetime module:

            print([__import__('datetime').date(i,1,1).weekday()+1for i in range(1,4000)].index(*[int(input())for i in'  '][::-1])+1)
            

            BTW your solution has an obvious improvement: [i+1 for can be shortened to [i+1for

            • »
              »
              »
              »
              »
              »
              »
              14 months ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Yeah, and maybe open(0) can save a few bytes too.

              • »
                »
                »
                »
                »
                »
                »
                »
                14 months ago, # ^ |
                Rev. 3   Vote: I like it 0 Vote: I do not like it

                Following the format of my code,

                print([1+(i%4*5+i%100*4-i%400)%7for i in range(4000)].index(*[int(input())for i in'  '][::-1])+1)
                

                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.