Codegolf: Write the shortest code you can

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrRubix
    FFR Player
    • May 2026
    • 8340

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

    I'm coming.

    Patashu, you need to come with me, too.
    https://www.youtube.com/watch?v=0es0Mip1jWY

    Comment

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

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

      bump because more people should play this



      Proud member of Team No

      Comment

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

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

        Also, the IRC channel for this is #anagol at irc.freenode.net



        Proud member of Team No

        Comment

        • Izzy
          Snek
          FFR Simfile Author
          • Jan 2003
          • 9195

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

          So I did the first one just to try it out. How do I possibly make this shorter?

          Code:
          void main(){printf("Hello, world!");}

          Comment

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

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

            You can omit 'void', and you can use puts instead of printf to output an unformatted string.



            Proud member of Team No

            Comment

            • Izzy
              Snek
              FFR Simfile Author
              • Jan 2003
              • 9195

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

              I realized I could get rid of void but that still only got me to 32.

              success!

              size: 32
              time: 0.000192sec
              status: 13
              your output:

              Hello, world!

              I was looking for a different print method but I couldn't find it. Guess I'll use puts.

              Not sure how to do number 2 really short. I thought it would be something interesting like.

              Code:
              main(){puts("%s", gets());}
              Something I don't like about the way the score is calculated is that it is just file size. This has nothing to do with the efficiency of the code at run time. The compile optimizer will make void main and main be exactly the same. Having extra lines in your code doesn't do anything to efficiency because the assembly code will be exactly the same in the end.
              Last edited by Izzy; 12-6-2010, 03:51 PM.

              Comment

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

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

                Hint: If "exec is denied" is not in the option, you are allowed to use system commands.

                btw, you don't have to solve the problems in order.

                EDIT: File size is the sole thing you should care about in codegolf. If for a problem there is a 40-byte solution that runs for 2.97 seconds and a 41-byte solution that runs for 0.0002 seconds, then the 40-byte solution wins.
                Last edited by leonid; 12-6-2010, 03:53 PM.



                Proud member of Team No

                Comment

                • Reincarnate
                  x'); DROP TABLE FFR;--
                  • Nov 2010
                  • 6332

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

                  Originally posted by leonid
                  Hint: If "exec is denied" is not in the option, you are allowed to use system commands.

                  btw, you don't have to solve the problems in order.

                  EDIT: File size is the sole thing you should care about in codegolf. If for a problem there is a 40-byte solution that runs for 2.97 seconds and a 41-byte solution that runs for 0.0002 seconds, then the 40-byte solution wins.
                  Izzy is saying that writing code in a shorter fashion doesn't necessarily mean the code itself is efficient.

                  Nevertheless, code golfing is still a good way to get you to learn a ton of syntax -- which you can then use to write better code in real life. Writing shorter code is almost always a strong suit.

                  It's always a huge pain in the ass to edit/debug someone else's code/your own code when it's like ten times longer than it needs to be.

                  Comment

                  • Izzy
                    Snek
                    FFR Simfile Author
                    • Jan 2003
                    • 9195

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

                    Trying to read/debugg 100+ lines worth of code that is on 1 line is kind of annoying. I would agree that shorter code in general is better, but so is good formatting. I don't believe shorter is always better.

                    I'm kind of curious what the assembly would look like for the shortest hello world compared to a hello word on 3 lines using printf and void main.
                    Last edited by Izzy; 12-6-2010, 04:23 PM.

                    Comment

                    • Matrixdude
                      And She Screams My Name
                      • Jun 2006
                      • 1351

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

                      This thing is awesome, will definitely help in real life coding.

                      Question for all you coders at there: I already know a lot of Java and now I have the option to learn any language I want in an independent study course. What language should I delve into?

                      Comment

                      • Izzy
                        Snek
                        FFR Simfile Author
                        • Jan 2003
                        • 9195

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

                        Right after java I would recommend C and C++. After that maybe php / python. You don't need to learn C# if you are doing JAVA.

                        I can't figure out how to convert a C file into assembly on windows and I don't feel like going all the way to my ubuntu partition just to type GCC -S

                        Comment

                        • trumaestro
                          I don't get no respect
                          FFR Simfile Author
                          • Jun 2006
                          • 1332

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

                          ehhh i'll try some of these in perl and see how it goes..

                          Comment

                          • emerald000
                            the Mathemagician~
                            • Nov 2005
                            • 1320

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

                            For izzy:

                            Code:
                            	.file	"helloworldgolf.c"
                            	.section	.rodata
                            .LC0:
                            	.string	"Hello, world!"
                            	.text
                            .globl main
                            	.type	main, @function
                            main:
                            	pushl	%ebp
                            	movl	%esp, %ebp
                            	andl	$-16, %esp
                            	subl	$16, %esp
                            	movl	$.LC0, (%esp)
                            	call	puts
                            	leave
                            	ret
                            	.size	main, .-main
                            	.ident	"GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5"
                            	.section	.note.GNU-stack,"",@progbits
                            Code:
                            	.file	"helloworldformatted.c"
                            	.section	.rodata
                            .LC0:
                            	.string	"Hello, world!"
                            	.text
                            .globl main
                            	.type	main, @function
                            main:
                            	pushl	%ebp
                            	movl	%esp, %ebp
                            	andl	$-16, %esp
                            	subl	$16, %esp
                            	movl	$.LC0, (%esp)
                            	call	puts
                            	leave
                            	ret
                            	.size	main, .-main
                            	.ident	"GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5"
                            	.section	.note.GNU-stack,"",@progbits
                            Exactly the same.

                            Comment

                            • Izzy
                              Snek
                              FFR Simfile Author
                              • Jan 2003
                              • 9195

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

                              Figured they would be at least 95% of the same, but exactly the same pretty much proves my point. Although shouldn't one of them call printf? Or does printf really get turned into a puts if it doesn't need printf's capabilities?

                              Not that codegolf can't be interesting and amusing, it just doesn't make the code "better" or more efficient.
                              Last edited by Izzy; 12-6-2010, 05:22 PM.

                              Comment

                              • emerald000
                                the Mathemagician~
                                • Nov 2005
                                • 1320

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

                                I actually put puts in both of them. But using printf results in the same thing (with printf instead of puts obviously).

                                And 100 lines of code will usually be a lot easier to work with than 4 nested loops on a single line.

                                Comment

                                Working...
                                  Notice: Function utf8_encode() is deprecated in phar://.../vb/vb.phar/mail/transport/legacy.php on line 2 Notice: Function utf8_encode() is deprecated in phar://.../vb/vb.phar/mail/transport/legacy.php on line 2 Warning: Undefined variable $username in phar://.../vb/vb.phar/mail/transport/legacy.php on line 2 Notice: Function utf8_encode() is deprecated in phar://.../vb/vb.phar/mail/transport/legacy.php on line 2 Notice: utf8_encode(): Passing null to parameter #1 ($string) of type string is deprecated in phar://.../vb/vb.phar/mail/transport/legacy.php on line 2 Notice: Function utf8_encode() is deprecated in phar://.../vb/vb.phar/mail/transport/legacy.php on line 2