Thread: shorter code

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    2

    shorter code

    Hello.

    Code:
    main(a){while(scanf("%d",&a)^-1)printf("%d\n",a*a+a>>1);}
    My code have 58 symbols. Is somebody who can to find a shorter code? I know that in C can go up to 53 symbols.
    Last edited by czarny020; 02-12-2011 at 02:36 PM.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ummm... what on earth are you talking abourt?

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    2
    I searching a shorter code in C

  4. #4
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    what??? explain yourself better, and maybe better code example.
    And there 's no such thing as
    Code:
    main(a)
    "All that we see or seem
    Is but a dream within a dream." - Poe

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Code:
    int main(){}
    Win!
    You never said the program had to do anything.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    And there 's no such thing as
    Code:
    void foo(a,b,c)      /* defaults to
     int a,b,c;              */
    {
    
    }

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    15
    The program counts a sum of arithmetic progression starting from 1 to the input number and should stop on invalid input. There is a mistake in czarny020's code: when you enter text, it loops infinitely. My variant fixes the bug and has 54 symbols.
    Code:
    main(a){while(scanf("%d",&a))printf("%d\n",a*a+a>>1);}
    Last edited by modwind; 02-13-2011 at 03:37 AM.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    I will admit, I see little value in using deprecated and (worse) implementation-defined features to minimise the number of characters in a source file.

    iMalc's example aside, the code snippets shown as "solutions" in this thread - at best - will trigger warnings from modern compilers and are also not guaranteed to produce the intended result.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Why bother with short source code? Your compiler will just give you a hard time (spamming warnings) and then (hopefully) compile it to the same machine code anyway. What you should really be looking at is the effectiveness of your algorithm.

    Please remember: Shorter source code DOES NOT mean the resulting program will be smaller or faster!

    LT

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by modwind View Post
    My variant fixes the bug and has 54 symbols.
    Your version may or may not compile, since the functions you call are not prototyped anywhere, and you don't include any headers for them.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User
    Join Date
    Dec 2010
    Posts
    15
    Why so serious? It was just a game to make shorter code. Everyone understands it is not an example for real life. Like assembler demos 256 bytes or 64k long.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code style/formatting/organizing
    By nair in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2011, 11:31 AM
  2. How can I improve this code or make it shorter?
    By abh!shek in forum C++ Programming
    Replies: 27
    Last Post: 01-13-2008, 01:07 PM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM