Egocentric Code Competition

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aurélien Géron

    Egocentric Code Competition

    Hi all,

    As a newly converted Python lover, I am impressed at how concise Python code
    actually is. But really... how concise can it GET?

    As an experiment to find out the very limits of Python, I'm generously
    offering a free smiley as well as my utmost and sincere admiration to
    whoever can come up with the shortest python module which can print itself
    (no file reading allowed).

    I tried:
    print "print"
    But found out I got it wrong when it just displayed:
    print

    Duh... (I thought). So I tried:
    print "print \"print\""
    But I was stunned to find that this just printed:
    print "print"

    Hang on, this could last forever, like the "GNU" thingy! I'm sure you can
    do better than that!

    BTW, maybe this is a well-known problem. Anybody heard of it before? Looks
    like some problem out of "Goedel, Escher, Bach" (Hofstadter), although I
    frankly never got to the end of that book (something in it got you back to
    chapter one just when you thought you had reached chapter two)...

    Maybe we should try to do the same with C, Java, Lisp, Smalltalk, Prolog...
    and check the size difference. How fun!

    I smile in your general direction,
    Aurélien

    ps: hope this sort of post is allowed in this newsgroup... maybe there's a
    geek.lang.pytho n newsgroup somewhere which would be more appropriate?


  • David Eppstein

    #2
    Re: Egocentric Code Competition

    In article <bdpt0u$ci6$1@b iggoron.nerim.n et>,
    "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote:
    [color=blue]
    > BTW, maybe this is a well-known problem.[/color]

    Maybe...


    --
    David Eppstein http://www.ics.uci.edu/~eppstein/
    Univ. of California, Irvine, School of Information & Computer Science

    Comment

    • Aurélien Géron

      #3
      Re: Egocentric Code Competition

      Aaaaaaand we have WINNER !!!

      I guess the rules of my little competition should lead me to sending my
      smiley to Sean B. Palmer but I think you fully deserve it!
      Picasso once said something like "Good Designers Copy, Great Designers
      Steal".
      I guess the same should be said about programmers!

      So here it is, the prize you've all been waiting for, your very own 22 karat
      smiley:

      :-)

      Amazingly valuable, as you can see (won't be too many people answering my
      quizzes next time around).

      Thanks!
      Aurélien

      "David Eppstein" <eppstein@ics.u ci.edu> a écrit dans le message de
      news:eppstein-650D46.10570830 062003@news.ser vice.uci.edu...[color=blue]
      > In article <bdpt0u$ci6$1@b iggoron.nerim.n et>,
      > "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote:
      >[color=green]
      > > BTW, maybe this is a well-known problem.[/color]
      >
      > Maybe...
      > http://www.google.com/search?q=python+quine
      >
      > --
      > David Eppstein http://www.ics.uci.edu/~eppstein/
      > Univ. of California, Irvine, School of Information & Computer Science[/color]


      Comment

      • Sean Ross

        #4
        Re: Egocentric Code Competition

        It's called a "quine":



        _='_=%r;print _%%_';print _%_


        Comment

        • Aurélien Géron

          #5
          Re: Egocentric Code Competition

          Hey, I just found this in "A page about quines" at


          "I also dedicate this page to Douglas R. Hofstadter, who coined the name (in
          his justly famous book Gödel, Escher, Bach) and who so clearly explained
          quines' importance and their relation with Gödel's incompleteness theorem."

          Amazing, I really should have finished this book after all ! ;-)

          Cheers,
          Aurélien

          "David Eppstein" <eppstein@ics.u ci.edu> a écrit dans le message de
          news:eppstein-650D46.10570830 062003@news.ser vice.uci.edu...[color=blue]
          > In article <bdpt0u$ci6$1@b iggoron.nerim.n et>,
          > "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote:
          >[color=green]
          > > BTW, maybe this is a well-known problem.[/color]
          >
          > Maybe...
          > http://www.google.com/search?q=python+quine
          >
          > --
          > David Eppstein http://www.ics.uci.edu/~eppstein/
          > Univ. of California, Irvine, School of Information & Computer Science[/color]


          Comment

          • Aurélien Géron

            #6
            Re: Egocentric Code Competition

            Thanks !


            "Sean Ross" <sross@connectm ail.carleton.ca > a écrit dans le message de
            news:A6%La.1697 $eF3.221717@new s20.bellglobal. com...[color=blue]
            > You may find this interesting:
            > http://www.nyx.net/~gthompso/quine.htm
            >
            >[/color]


            Comment

            • Terry Reedy

              #7
              Re: Egocentric Code Competition

              > As an experiment to find out the very limits of Python, I'm
              generously[color=blue]
              > offering a free smiley as well as my utmost and sincere admiration[/color]
              to[color=blue]
              > whoever can come up with the shortest python module which can print[/color]
              itself[color=blue]
              > (no file reading allowed).[/color]

              There was a thread on this several years ago in which I participated.
              Something like Shortest Self-Reproducing Programs. Should be findable
              through Google.

              Terry J. Reedy


              Comment

              • Roy Smith

                #8
                Re: Egocentric Code Competition

                David Eppstein <eppstein@ics.u ci.edu> wrote:[color=blue]
                >In article <bdpt0u$ci6$1@b iggoron.nerim.n et>,
                > "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote:
                >[color=green]
                >> BTW, maybe this is a well-known problem.[/color]
                >
                >Maybe...
                >http://www.google.com/search?q=python+quine
                >
                >--
                >David Eppstein http://www.ics.uci.edu/~eppstein/
                >Univ. of California, Irvine, School of Information & Computer Science[/color]


                I guess it depends on how you define "shortest possible", but observe
                the following:

                bash-2.05b$ cp /dev/null zero.py
                bash-2.05b$ python zero.py > zero2.py
                bash-2.05b$ cmp zero.py zero2.py

                I therefore submit that an empty file is the shortest possible Python
                program which reproduces itself on output.

                Comment

                • Aurélien Géron

                  #9
                  Re: Egocentric Code Competition

                  Thanks Terry !

                  Apparently this is more like the third or fourth instance of this
                  discussion!!!

                  Check out:


                  If this link does not work, go to:

                  and search "self replicating group:comp.lang .python.*"

                  I should have lived in the stone age, when people could actually be the
                  first ones to discover something at all.
                  Nothing is original anymore. Even "Nothing is original anymore" gives 150
                  hits on Google.
                  How sad. How pathetic.

                  Hey wait! Did anyone ever try to find english language quines? "Repeat this
                  sentence" is my first shot at it. Maybe one can go shorter like "Repeat
                  this". Or something like "Whazaaa" usually triggers repetition. While
                  you're at it, "Hi" seems pretty efficient. Most certainly a world record.
                  Apparently those quines don't appear in G. Thompson's (excellent) list of
                  quines: http://www.nyx.net/~gthompso/quine.htm . Maybe I should submit them!

                  ;-)
                  Aurélien


                  "Terry Reedy" <tjreedy@udel.e du> a écrit dans le message de
                  news:e6acnUzb2r T3EZ2iXTWJjg@co mcast.com...[color=blue][color=green]
                  > > As an experiment to find out the very limits of Python, I'm[/color]
                  > generously[color=green]
                  > > offering a free smiley as well as my utmost and sincere admiration[/color]
                  > to[color=green]
                  > > whoever can come up with the shortest python module which can print[/color]
                  > itself[color=green]
                  > > (no file reading allowed).[/color]
                  >
                  > There was a thread on this several years ago in which I participated.
                  > Something like Shortest Self-Reproducing Programs. Should be findable
                  > through Google.
                  >
                  > Terry J. Reedy
                  >
                  >[/color]


                  Comment

                  • Aurélien Géron

                    #10
                    Re: Egocentric Code Competition

                    Argh !

                    You got me.

                    After deliberation, the jury decides that you deserve a smiley too.

                    ;-)

                    Congratulations !
                    Aurélien

                    "Roy Smith" <roy@panix.co m> a écrit dans le message de
                    news:bdq32j$89t $1@panix2.panix .com...[color=blue]
                    > David Eppstein <eppstein@ics.u ci.edu> wrote:[color=green]
                    > >In article <bdpt0u$ci6$1@b iggoron.nerim.n et>,
                    > > "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote:
                    > >[color=darkred]
                    > >> BTW, maybe this is a well-known problem.[/color]
                    > >
                    > >Maybe...
                    > >http://www.google.com/search?q=python+quine
                    > >
                    > >--
                    > >David Eppstein http://www.ics.uci.edu/~eppstein/
                    > >Univ. of California, Irvine, School of Information & Computer Science[/color]
                    >
                    >
                    > I guess it depends on how you define "shortest possible", but observe
                    > the following:
                    >
                    > bash-2.05b$ cp /dev/null zero.py
                    > bash-2.05b$ python zero.py > zero2.py
                    > bash-2.05b$ cmp zero.py zero2.py
                    >
                    > I therefore submit that an empty file is the shortest possible Python
                    > program which reproduces itself on output.[/color]


                    Comment

                    Working...