Codegolf: Write the shortest code you can

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Patashu
    FFR Simfile Author
    FFR Simfile Author
    • Apr 2006
    • 8609

    #1

    Codegolf: Write the shortest code you can

    Alternate subtitle: Ruby is small, Java is hueg

    Here's the site: http://golf.shinh.org/
    It's pretty simple, write code that produces the correct output for each input and make it as short as possible; your score is equal to the number of bytes in your program and, like golf, the lower the better. It has interpreters for a ridiculous number of languages (c,java,python,ruby,php,even befunge) so if you already know how to code yours is probably supported.

    I've been dabbling in a bit, only know Java though so all my solutions are enormous, haha. I don't mind though because it's all relative, and if I can make things short in Java I'm learning the same type of thinking I'll need for terseness in any language.

    The oldest problems are at the top, the newest are at the bottom. You can submit to any of them but you may as well start with the newest or any that catch your eye.

    You can add your own problems, but for the love of god don't screw up the sample input/output. Also, make sure at least one of the samples requires a large amount of output compared to how much you'll need to write for a valid solution so that an 'embedded' program where the output is hardcoded isn't the shortest way.

    To start things off, here's my definitely-not-optimal solution for 'numof 1 bits in 0 to 255' using java:
    Code:
    class A{public static void main(String[]a){for(int i=0,j,k,l=256;i<l;i++){k=0;for(j=1;j<l;j*=2){if((i&j)>0)k++;}System.out.print(k);}}}
    Patashu makes Chiptunes in Famitracker:
    http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
    http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
    Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
    http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
  • Necamus
    FFR Player
    • Nov 2005
    • 853

    #2
    Re: Codegolf: Write the shortest code you can

    I made yours shorter instead of looking at the site, but only by two characters:

    Code:
    class A{public static void main(String[]a){for(int i=0,j,k,l=256;i<l;i++){k=0;for(j=1;j<l;j*=2)if((i&j)>0)k++;System.out.print(k);}}}
    If a for loop is only executing a single line, you don't need curly brackets around that line.
    www.freerice.com

    Comment

    • Patashu
      FFR Simfile Author
      FFR Simfile Author
      • Apr 2006
      • 8609

      #3
      Re: Codegolf: Write the shortest code you can

      Ooh, thanks.

      EDIT: Also, I undid an earlier attempt that added two bytes (allocating 256 to a variable, l) so now it's at 131:

      Code:
      class A{public static void main(String[]a){for(int i=0,j,k;i<256;i++){k=0;for(j=1;j<256;j*=2)if((i&j)>0)k++;System.out.print(k);}}}
      Last edited by Patashu; 04-22-2009, 03:21 AM.
      Patashu makes Chiptunes in Famitracker:
      http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
      http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
      Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
      http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png

      Comment

      • leonid
        I am leonid
        FFR Simfile Author
        FFR Music Producer
        • Oct 2008
        • 8080

        #4
        Re: Codegolf: Write the shortest code you can

        Dude, that's way too nerdy.



        Proud member of Team No

        Comment

        • funmonkey54
          The Chill Keeper
          • Oct 2007
          • 4127

          #5
          Re: Codegolf: Write the shortest code you can

          Oh wow. This is awesome!

          Comment

          • Patashu
            FFR Simfile Author
            FFR Simfile Author
            • Apr 2006
            • 8609

            #6
            Re: Codegolf: Write the shortest code you can

            it's okay, I teach advanced theory about placing coloured arrows to music and then play them, I already have my nerd quotient filled out
            Patashu makes Chiptunes in Famitracker:
            http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
            http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
            Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
            http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png

            Comment

            • Kekeb
              davai
              • Dec 2006
              • 2765

              #7
              Re: Codegolf: Write the shortest code you can

              Interesting, I'll try my hand at a few later today.
              I will probably end up using C# because I'm a fail boat.

              Comment

              • Tokzic
                FFR Player
                • May 2005
                • 6878

                #8
                Re: Codegolf: Write the shortest code you can

                dammit, miranda isn't supported

                just to show how cheap miranda is for this, the first one is

                Code:
                p="Hello, world!"

                Last edited by Tokzic: Today at 11:59 PM. Reason: wait what

                Comment

                • Flaming_Dingleberry
                  Everybody gets one.
                  • Jul 2006
                  • 1008

                  #9
                  Re: Codegolf: Write the shortest code you can

                  What in the God forsaken hell is this?
                  ~ 2nd Official FFR Gamewhore

                  ~ 1st Official FFR Butthole

                  Comment

                  • AC1speakerbox
                    FFR Player
                    • Jun 2006
                    • 1242

                    #10
                    Re: Codegolf: Write the shortest code you can

                    ^ I lol'd
                    This really is ridiculous

                    Comment

                    • Oni-Paranoia
                      No fucks
                      • Dec 2006
                      • 2440

                      #11
                      Re: Codegolf: Write the shortest code you can

                      I wanna be a nerd!!

                      Code:
                      shutdown -s -t 2 -c "Hi Patashu"
                      I'm pro now right?

                      Comment

                      • AC1speakerbox
                        FFR Player
                        • Jun 2006
                        • 1242

                        #12
                        Re: Codegolf: Write the shortest code you can

                        Code:
                        lol
                        win

                        Comment

                        • PsYcHoZeRoSk8eR
                          Threat Emulation
                          FFR Simfile Author
                          • May 2004
                          • 5184

                          #13
                          Re: Codegolf: Write the shortest code you can

                          This is cool, but I hate programming. After working in assembly, I hope to never have to work with it again.

                          Originally posted by Lightdarkness
                          I'm light f**king darkness

                          Comment

                          • Ruritsu
                            FFR Player
                            • Mar 2008
                            • 479

                            #14
                            Re: Codegolf: Write the shortest code you can

                            Purely awesome, I'll try my hand at it...
                            =__=' My sig was 22 pixels too tall, so this is here instead...

                            Comment

                            • Kekeb
                              davai
                              • Dec 2006
                              • 2765

                              #15
                              Re: Codegolf: Write the shortest code you can

                              I tried my hand at the Hexagon problem, but I finished at 80 lines (not stacked, but rofl massive), and with it being very inefficient.
                              EDIT: How do I shot algorithms.
                              Last edited by Kekeb; 04-22-2009, 05:24 PM.

                              Comment

                              Working...