python coding contest

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Hengel

    #1

    python coding contest

    Hello,
    we are hosting a python coding contest an we even managed to provide a
    price for the winner...



    The contest is coincidentally held during the 22c3 and we will be
    present there.



    Please send me comments, suggestions and ideas.

    Have fun,

    --
    Simon Hengel
  • André

    #2
    Re: python coding contest

    Neat idea!

    I'm far from being a decent Python programmer but I managed (for fun)
    to do it in a one-liner; however, it was definitely longer (in term of
    number of characters) than the more readable multi-line solution.

    André

    Comment

    • Tobias Bell

      #3
      Re: python coding contest

      André schrieb:[color=blue]
      > Neat idea![/color]
      Indeed
      [color=blue]
      >
      > I'm far from being a decent Python programmer but I managed (for fun)
      > to do it in a one-liner; however, it was definitely longer (in term of
      > number of characters) than the more readable multi-line solution.[/color]

      I made a readable version with 352 bytes and a non-readable with 290
      bytes. But it's a really ugly lambda, map, reduce kludge. Looks like Perl.
      [color=blue]
      >
      > André
      >[/color]

      Tobias

      Comment

      • rbt

        #4
        Re: python coding contest

        Simon Hengel wrote:[color=blue]
        > Hello,
        > we are hosting a python coding contest an we even managed to provide a
        > price for the winner...
        >
        > http://pycontest.net/
        >
        > The contest is coincidentally held during the 22c3 and we will be
        > present there.
        >
        > https://events.ccc.de/congress/2005/...coding_contest
        >
        > Please send me comments, suggestions and ideas.
        >
        > Have fun,
        >[/color]

        Does positioning matter? For example, say I give it '123' is it ok to
        output this:

        1
        2
        3

        Or does it have to be 123

        Comment

        • Remi Villatel

          #5
          Re: python coding contest

          rbt wrote:
          [color=blue]
          > Does positioning matter? For example, say I give it '123' is it ok to
          > output this:
          >
          > 1
          > 2
          > 3
          >
          > Or does it have to be 123[/color]

          Download the test suite and you'll see that only 123 on one line passes
          the test. Sorry...

          --
          =============== ===
          Remi Villatel
          maxilys_@_tele2 .fr
          =============== ===

          Comment

          • Bengt Richter

            #6
            Re: python coding contest

            On Sun, 25 Dec 2005 16:39:47 +0100, Simon Hengel <simon@airlange n.de> wrote:
            [color=blue]
            >Hello,
            >we are hosting a python coding contest an we even managed to provide a
            >price for the winner...[/color]
            ^^^^^[color=blue]
            >[/color]
            How much are you going to sell him or her for? ;-)

            Regards,
            Bengt Richter

            Comment

            • Claudio Grondi

              #7
              Re: python coding contest

              Simon Hengel wrote:[color=blue]
              > Hello,
              > we are hosting a python coding contest an we even managed to provide a
              > price for the winner...
              >
              > http://pycontest.net/
              >
              > The contest is coincidentally held during the 22c3 and we will be
              > present there.
              >
              > https://events.ccc.de/congress/2005/...coding_contest
              >
              > Please send me comments, suggestions and ideas.
              >
              > Have fun,
              >[/color]

              A funny thing happened to me.

              The http://www.pycontest.net/ site was down for some minutes because :

              "A problem occurred in a Python script. "

              it seems, that

              'some clever cheat'

              has crashed it.

              Claudio

              Comment

              • Simon Hengel

                #8
                Re: python coding contest

                > A funny thing happened to me.[color=blue]
                >
                > The http://www.pycontest.net/ site was down for some minutes because :
                >
                > "A problem occurred in a Python script. "
                >
                > it seems, that
                >
                > 'some clever cheat'
                >
                > has crashed it.[/color]
                That was me, i broke things while tweaking some stuff.

                Sorry for the inconveniences,

                Simon Hengel

                --
                python coding contest - http://www.pycontest.net/

                Comment

                • Marius Gedminas

                  #9
                  Re: python coding contest

                  I cannot not reach the contest site at since all this morning. :-(

                  Comment

                  • Marius Gedminas

                    #10
                    Re: python coding contest

                    I cannot reach the contest site at since all this morning. :-(

                    Comment

                    • Claudio Grondi

                      #11
                      Re: python coding contest

                      Simon Hengel wrote:[color=blue]
                      > Hello,
                      > we are hosting a python coding contest an we even managed to provide a
                      > price for the winner...
                      >
                      > http://pycontest.net/
                      >
                      > The contest is coincidentally held during the 22c3 and we will be
                      > present there.
                      >
                      > https://events.ccc.de/congress/2005/...coding_contest
                      >
                      > Please send me comments, suggestions and ideas.
                      >
                      > Have fun,
                      >[/color]

                      It seems, that the site had some trouble to stay online and especially
                      to provide the ranking today.

                      I am a bit dissapointed, that my idea of not duplicating, but utilizing
                      the efforts others put into solving the job (titled by the submitter ID
                      'TheParasite') which resulted in a submission of a 15 Bytes large full
                      functional module was evaluated as having a 'syntax error' problem and
                      was placed in the ranking at the position according to the size of the
                      331 byte large .zip archive it was put into along with some necessary
                      installation instructions.

                      By the way: trying to submit along with the module complete installation
                      instructions and comments failed because there is a 345 bytes limit for
                      size of allowed uploads.

                      Claudio

                      Comment

                      • Simon Hengel

                        #12
                        Re: python coding contest

                        > It seems, that the site had some trouble to stay online and especially[color=blue]
                        > to provide the ranking today.[/color]
                        There was a problem with our server, sorry for that.

                        Have fun,

                        Simon Hengel

                        Comment

                        • Paddy

                          #13
                          Re: python coding contest

                          So, testosterone wins again!

                          We get to boast:
                          "Mine's smaller than your's"

                          Lets wait for Pythonic to go to bed, then sneak downstairs, go to that
                          tripple-X rated 'shortest solutions' website, and 'whack-off' some
                          solutions.
                          Unghhh, my solution... its coming!!!

                          Well don't forget to clean up before Pythonic wakes up.

                          Happy new year :-)

                          - Pad.

                          Comment

                          • Claudio Grondi

                            #14
                            Re: python coding contest

                            > Please send me comments, suggestions and ideas.

                            Now, after the contest is over I analysed the outcome of it and have
                            come to the conclusion, that there were two major factors which
                            contributed to squeezing of code:

                            (1). usage of available variants for coding of the same thing
                            (2). sqeezing the size of used numeric and string literals

                            As (1) leads to less readable cryptic code it makes not much sense from
                            my point of view to dig deeper in that direction. As already mentioned
                            in this thread by Tim Peters ( pointing to
                            http://spoj.sphere.pl/problems/KAMIL/ ) it seems, that Pearl is here the
                            proper language of choice for such kind of problems anyway.

                            Trying to improve on (2) belongs in my eyes much more into the area of
                            problems discussed in comp.compressio n than to problems belonging into
                            comp.lang.pytho n .

                            So what is my point? Ok, I will mention it at the end of this post.

                            Before that I want to thank the originators of the contest and
                            especially the participants for providing insight into the techniques
                            they have used. I have learned from the contest what lambda expression
                            is good for and how it works where I failed to grasp it from reading
                            tutorials only.

                            I have detected, that it would be a nice thing to have in Python a
                            function able to convert values from binary string to an integer
                            representation as in my eyes both in case of long integer values are
                            more or less the same thing/object. The only difference is probably in
                            the header not in the representation of the actual value in memory - am
                            I right here? Will it make sense to have a string-integer object which
                            value can be used in both contexts as a binary string and a long integer
                            value?
                            Is there in Python any simple way to do the same as the following two
                            following functions I have put together today:

                            def longIntWithBits OfBinaryString( stringToConvert ):
                            intWithBitsOfBi naryString = 0L
                            for singleChar in stringToConvert :
                            intWithBitsOfBi naryString = (intWithBitsOfB inaryString<<8) +
                            ord(singleChar)
                            #:for
                            return intWithBitsOfBi naryString
                            #:def longIntWithBits OfBinaryString( s)

                            def binaryStringWit hBitsOfLongInt( i):
                            listOfCharsOfSt ringWithThePack edInt = []
                            exponent = 1
                            while i > 256**exponent: exponent+=1
                            for byteNo in range(0,exponen t):
                            noOfBitsToShift = byteNo*8

                            listOfCharsOfSt ringWithThePack edInt.append(ch r(i>>noOfBitsTo Shift&0xFF))
                            #:for
                            # reverse (in place) in order to get the highest bits of the integer
                            as leftmost byte
                            listOfCharsOfSt ringWithThePack edInt.reverse()
                            stringWithThePa ckedInt = ''.join(listOfC harsOfStringWit hThePackedInt)
                            return stringWithThePa ckedInt
                            #:def binaryStringWit hBitsOfLongInt( i)

                            print "longIntWithBit sOfBinaryString ('ABBA') =
                            %i"%longIntWith BitsOfBinaryStr ing('ABBA')
                            print
                            "binaryStringWi thBitsOfLongInt (longIntWithBit sOfBinaryString ('ABBA')) =
                            '%s'"%binaryStr ingWithBitsOfLo ngInt(longIntWi thBitsOfBinaryS tring('ABBA'))

                            which gives:

                            longIntWithBits OfBinaryString( 'ABBA') = 1094861377
                            binaryStringWit hBitsOfLongInt( longIntWithBits OfBinaryString( 'ABBA')) =
                            'ABBA'

                            ?

                            And now my point I have promised to write about:

                            If squeezing code makes it bad code and compressing literals is more or
                            less compression technique and not Python programming, it is maybe a
                            good idea to try to explore what Python distribution provides as data
                            and modules and rewrite the seven_seg module, but with following
                            limitations:

                            1. it is not allowed to use any literals in the provided code
                            2. it is not allowed to misuse the names of the identifiers as a kind of
                            literals providing data
                            3. it is not allowed to use modules or files which doesn't come with the
                            Python distribution.

                            I have no slightest idea if it is possible to program a seven_seg
                            module under such conditions. It could be a sign, that it would be a
                            very interesting challenge worth to get involved into or a sign I have
                            no slightest idea about Python and programming.

                            What do you all think about it?

                            Claudio

                            Comment

                            • Steven D'Aprano

                              #15
                              Re: python coding contest

                              On Sun, 01 Jan 2006 03:34:33 +0100, Claudio Grondi wrote:
                              [color=blue][color=green]
                              >> Please send me comments, suggestions and ideas.[/color]
                              >
                              > Now, after the contest is over I analysed the outcome of it and have
                              > come to the conclusion, that there were two major factors which
                              > contributed to squeezing of code:
                              >
                              > (1). usage of available variants for coding of the same thing
                              > (2). sqeezing the size of used numeric and string literals[/color]

                              [snip]
                              [color=blue]
                              > Is there in Python any simple way to do the same as the following two
                              > following functions I have put together today:[/color]

                              They are already pretty simple. You can make them even more simple by
                              using less complicated names and getting rid of the explicit end block
                              markers. It is sometimes useful to put in explicit end block markers when
                              you have long blocks, but when the block is just a single line, well,
                              I don't see the point.

                              Here is another possibility.
                              [color=blue][color=green][color=darkred]
                              >>> import array
                              >>> A = array.array('b' )
                              >>> n = 1000000
                              >>> while n:[/color][/color][/color]
                              .... A.append(n&255) ; n = n >> 8
                              ....[color=blue][color=green][color=darkred]
                              >>> A.reverse()
                              >>> A[/color][/color][/color]
                              array('b', [15, 66, 64])[color=blue][color=green][color=darkred]
                              >>> 15*256**2 + 66*256 + 64[/color][/color][/color]
                              1000000[color=blue][color=green][color=darkred]
                              >>> A.tostring()[/color][/color][/color]
                              '\x0fB@'

                              The reverse transformation is just as easy:
                              [color=blue][color=green][color=darkred]
                              >>> A = array.array('b' , "\x0fB@") # initialise from a byte string
                              >>> n = 0L
                              >>> for b in A:[/color][/color][/color]
                              .... n = n << 8 | b
                              ....[color=blue][color=green][color=darkred]
                              >>> n[/color][/color][/color]
                              1000000L

                              And of course these can be turned into functions.



                              --
                              Steven.

                              Comment

                              Working...