Thread: Almost Daily Contest #2

  1. #1
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897

    Almost Daily Contest #2

    Almost Daily Contest #2

    Now that I know what to expect, let's get on with it. Expect a less chaotic contest this time.

    Submission Rules: Please send submissions by email to [email protected] so that I can accurately judge who sent what before whom. It would be most helpful if the entries were in plain text format so that I can easily cut and paste, and named appropriately including the adc you're submitting for, your name and the difficulty level (ex. adc2_prelude_advanced.txt).

    Beginner:
    Most numbers have an interesting trait. If you continually reverse the number and add the result to the original number, you'll have a palindromic number. A palindromic number is a number whose digits are the same both forward and backward, for example, 2002, 121, and any single digit number.

    Your mission, should you choose to accept it, is to write a function in C or C++:

    int palNum(int n);

    that returns the first palindromic number with n as the original. This function should be able to correctly print the first 50 values of n. For example:

    for (int i = 0; i <= 20; i++)
    cout<< palNum(i) <<endl;

    This should print

    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    11
    11
    33
    44
    55
    66
    77
    88
    99
    121
    22


    Intermediate:
    Create a type that works in both C and C++ (no classes, sorry). This type will be called Integer, and has the following interface:

    Integer a = makeInteger("12345");
    Integer b = makeInteger("54321");

    printf("%s\n", toString(addInteger(a, b)));
    printf("%s\n", toString(subInteger(a, b)));

    Your task is to create an integer type of arbitrary length and implement addition and subtraction. The internal workings of Integer are irrelevant as long as the interface is as above. All of the functions in the interface must run in a reasonable amount of time for very large numbers. Integer must be able to handle negative numbers as well as positive numbers and all combinations of the two.

    Speed and elegance are of primary importance, though you will be graded on correctness and portability.


    Advanced:
    Your task is the same as for the Intermediate task with two (quite major) differences. You advanced people must implement multiplication and division that runs in a reasonable amount of time. The interface is the same except addInteger and subInteger become mulInteger and divInteger:

    printf("%s\n", toString(mulInteger(a, b)));
    printf("%s\n", toString(divInteger(a, b)));

    Speed is very important.


    Contest End: Saturday, August 9, 2003


    Notes:
    For the Intermediate and Advanced tasks, entries will be tested against each other. The fastest implementation with correct answers will probably be the winner, but exceptionally elegant solutions may take the prize.

    In the Beginner task, speed isn't a primary concern, though the function shouldn't take an exceptionally long time to print the first 50 palindromic numbers. Keep in mind past contests when working up an implementation for this problem.


    Test ideas:
    In order to improve the contests so that everyone may participate and have fun, I'll try new things as we move along. This time I'm going to see if I can't even the playing field for the beginner task. If you've submitted an entry to the advanced task and the beginner task, you will automatically be docked 3 points for every category in the beginner task. If you've submitted an entry to the intermediate and beginner tasks, you will be automatically docked 1 point for every category in the beginner task. This is just a test, depending on how things go I may decide to change the amount of points removed or eliminate the rule completely during the course of this contest.

    If you have comments, questions or suggestions, please PM me so that we can work to improve the ADC.
    My best code is written with the delete key.

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    not that it is the biggest deal in the world, but I must voice a slight objection to the C-only requirement here. I'll do it that way of course, but still... I object (not that it matters)
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I'd have to second that, plus with so many people nowadays only learning C++ and not C, it kind of leaves them out of the picture.

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    It says C or C++, just no classes... although classes would be nice.
    Away.

  5. #5
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Yeah, but it says that it must run in C which means you must know C. I could be wrong when I say this, but I assume that for it to run in C then for all intents and purposes it really has to be written as though it is C.
    Last edited by PJYelton; 08-05-2003 at 11:11 AM.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >but I must voice a slight objection to the C-only requirement here.
    Low level C++ is still C++. You just can't use any of the C++ specific features that would make the task simpler.

    >plus with so many people nowadays only learning C++ and not C, it kind of leaves them out of the picture.
    The last I checked, almost nobody was learning C++ before the C subset. Once again, low level C++ is still C++, even if you don't use classes and OOP.

    I have my reasons for requiring that this work when compiled as both C and C++. Please note that several of these contests will be connected. It gives me more breathing room for these connections if I don't have to worry about C and C++ compatibility. Granted, there will be a few strictly C or strictly C++ tasks, but not yet. You guys are getting ahead of me, be patient and you'll see what I'm doing.
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    Perhaps you should dock points relative to how well you place in the higher contest. Like if your a beginner, and submit something for the intermediate, but dont place so well, you shouldnt be docked for your beginner submission.
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  8. #8
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    so does addInteger() have to return an "Integer"? toString() has to accept an integer and return a char *? So then we are requiring global buffers then. Great. ok global people. I suppose I should stick some gotos in there too. pffffhhh.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >> The last I checked, almost nobody was learning C++ before the C subset

    not that im trying to get you to change the contest or anything but... I just finished my second year of Comp. Sci. and we learned straight OOP C++, no C. In our first year we did all OOP Java. They dont teach much non-OOP anymore (at least not around here) guess its been a while since you've checked

    *note: They do teach straight C in third year for an OS course, but thats after everyone has had a full year with C++.

  10. #10
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    Originally posted by Perspective
    >> The last I checked, almost nobody was learning C++ before the C subset

    not that im trying to get you to change the contest or anything but... I just finished my second year of Comp. Sci. and we learned straight OOP C++, no C. In our first year we did all OOP Java. They dont teach much non-OOP anymore (at least not around here) guess its been a while since you've checked

    *note: They do teach straight C in third year for an OS course, but thats after everyone has had a full year with C++.
    It's not that different. Where you could say
    Code:
    struct Integer {
      int x;
    };
    in C++, you would now say
    Code:
    typedef struct {
      int x;
    } Integer;

  11. #11
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    I have submitted all 3 entries.. NO OOPS.. Thats really bad.. Since i was acustomed to it.. solving the 2nd and 3rd problem became unstructures.. With OOPS the code looks clean and easy to understand.. I wish we were allowed to program in OOPS which seems to be the standard now...


    and the problem could have been a little more complex.. like say buiding our own number type using 2 or more ints.. Like addition of verry big numbers like "54445454365464413623152132132" which can be broken into pieces and represented using 3 ints.. and manipulation on this type would have been fun...

    The present contest is some how a mess of converting chars to int and int to chars..(hope i did not give a clue)..
    Last edited by vasanth; 08-06-2003 at 06:22 AM.

  12. #12
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Are you sure those palimdronic numbers are in order the way you posted them? Because I think the 22 belongs where the *second* 11 is. Which then again, why are there two 11. I think you messed up.

  13. #13
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Originally posted by Speedy5
    Are you sure those palimdronic numbers are in order the way you posted them? Because I think the 22 belongs where the *second* 11 is. Which then again, why are there two 11. I think you messed up.

    The example is completely right.. I think you did not understanding it properly... Go through it and notice the 22 after 121 and you will know how the program needs to run...

    And i think no more clue should be given as it would be unfair...

  14. #14
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Just out of curiousity... are templates a C++ only feature ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  15. #15
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Originally posted by nvoigt
    Just out of curiousity... are templates a C++ only feature ?
    Hmm i am afraid so... But why do u require templates to solve the above problems...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Almost Daily Contest Details
    By dagdarian in forum Contests Board
    Replies: 4
    Last Post: 01-25-2005, 05:03 AM
  2. Almost Daily Contest Details
    By Prelude in forum Contests Board
    Replies: 29
    Last Post: 09-19-2004, 10:32 PM
  3. Almost Daily Contest #4
    By Prelude in forum Contests Board
    Replies: 35
    Last Post: 08-25-2003, 08:54 AM
  4. Almost Daily Contest #3
    By Prelude in forum Contests Board
    Replies: 29
    Last Post: 08-16-2003, 08:48 PM
  5. Almost Daily Contest #1
    By Prelude in forum Contests Board
    Replies: 32
    Last Post: 08-05-2003, 08:34 AM