Thread: May Monthly Contest Results

  1. #16
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Code:
    You have no howMany() function
    Let's not be pedantic sang-drax. Ok it doesn't have a 'howmany' and it don't return an int. But it does the job so it's hardly something to moan about. I guess it would only matter if you were cut n pasting the function directly into your program.



    Let's leave it at that.

  2. #17
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    OK, the name of the function really doesn't matter. The reason I remarked on your code was that most compliers won't be able to compile it. I saw an error and I made a comment. It's no big deal.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #18
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Oh,

    I never realised, thanx for pointing that out.

    It works on my version of Dev-shed, but what should I be doing different so that it works with every compiler within reason?

    I'm unaware of the different syntax's for different compilers. I'd be grateful if you could enlighten me so that I may know for next time.

  4. #19
    Registered User
    Join Date
    Mar 2005
    Posts
    38
    [troll-mode]

    Quote Originally Posted by Alvaro
    Code:
    int howMany2(int n){
      const int MEMORY_SIZE=26;
      static int memory[MEMORY_SIZE]={1,1,2,0};
    howMany2(0) == 1?
    [/troll-mode]


    I could have guessed you would participate here.

    [edit]
    Huh? Why is quoted code in italics?
    Last edited by Togra; 05-25-2005 at 06:57 AM. Reason: bug?

  5. #20
    Registered User
    Join Date
    Jul 2004
    Posts
    17
    It doesn't matter that its set to that. Look at PJYelton's code for it, he hasn't bothered to change that line either. Cause the loops start at i=1 so it never looks for the first index of the array...

    Pete

  6. #21
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by treenef
    It works on my version of Dev-shed, but what should I be doing different so that it works with every compiler within reason?
    If you declare a function returning int, it should return an int.

    Here are two possible changes to fix your code:
    Code:
    void  catalan(int n)
    {
        char array[81][81]={"1","2","5","14","42","132","429","1430","4862",
        "16796","58786","208012","742900","2674440","9694845",
        "35357670","129644790","477638700","1767263190"};
        cout<<array[n-1];
    }
    Code:
    int catalan(int n)
    {
        //Store the numbers as INTEGERS, not strings!
        //Numbers should be stored as numbers
        int array[81]={1,2,5,14,42,132,429,1430,4862,
        16796,58786,208012,742900,2674440,9694845,
        35357670,129644790,477638700,1767263190};
        cout<<array[n-1];
        return array[n-1];
    }
    Last edited by Sang-drax; 05-26-2005 at 02:55 AM. Reason: As pointed out by quzah

  7. #22
    Registered User
    Join Date
    May 2005
    Posts
    1
    Quote Originally Posted by Togra
    [troll-mode]

    howMany2(0) == 1?
    [/troll-mode]
    Actually, yes. There is a single binary tree with zero nodes, the empty tree, and it happens to satisfy the condition that we were looking for. Think about it.

    I could have guessed you would participate here.
    Well, you kind of invited me...

  8. #23
    Registered User
    Join Date
    Mar 2005
    Posts
    38
    Hmm, I see the point. Whoops!

  9. #24
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Sang-drax
    Here are two possible changes to fix your code:
    Code:
    int catalan(int n)
    {
        char array[81][81]={"1","2","5","14","42","132","429","1430","4862",
        "16796","58786","208012","742900","2674440","9694845",
        "35357670","129644790","477638700","1767263190"};
        cout<<array[n-1];
        return array[n-1];
    }
    How does this fix their code? You're returning an array instead of an integer. Even if you could return the array correctly, it would be wrong, because it's a string and not an integer.

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

  10. #25
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I hope you don't declare everyone winner again so easily... Not that I don't want to share credit , it just makes the contest a lesser contest.
    Yeah, I hated to do that and don't worry it won't happen again, I'll be sure to choose problems that don't allow it. I tried hard to decide what better fit my criteria, a quick hard coded problem, one that used a nifty formula, or one that actually used an algorithm. Couldn't do it, so I chickened out

    And yes, there is one tree that has zero nodes, although it really doesn't matter since I stated that nodes would be between 1 and 19 (or 25).

    I admit I got a little lax with the rules, like for example Togra's which prints the results instead of returns it. A good point of discussion for everyone is if this is ok or not. Personally I only care about the algorithm and the rest is just fluff, but I also understand if others want more structure that must be adhered to.

  11. #26
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by quzah
    How does this fix their code?
    What?
    See the International Standard ISO/IEC 14882 First edition 1998-09-01 "Programming languages — C++" 8.3.4 paragraph 1. That should answer everything.

    *Hopes that quzah doesn't own a copy of the standard*
    Last edited by Sang-drax; 05-26-2005 at 02:54 AM.

  12. #27
    Registered User
    Join Date
    Mar 2005
    Posts
    38
    Quote Originally Posted by PJYelton
    I admit I got a little lax with the rules, like for example Togra's which prints the results instead of returns it. A good point of discussion for everyone is if this is ok or not. Personally I only care about the algorithm and the rest is just fluff, but I also understand if others want more structure that must be adhered to.
    What did I do wrong :S?

    You set the rules, participants should obey them imo. If breaking the rules goes unpunished, it's not very fair to the other contestants... Furthermore, as a contest host I would require strict obediance of the rules so it's easier to automatically test all submissions.

    [edit]
    Ok, above is a bit over the top . Freaky perhaps.
    Last edited by Togra; 05-26-2005 at 12:24 PM.

  13. #28
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    >>What did I do wrong :S?<<

    Heh, I'm sorry, I meant treenef not Togra.

    >>If breaking the rules goes unpunished, it's not very fair to the other contestants...<<

    I dunno, I see where in some cases rule breaking is unfair but to grade someone down on formatting like they didn't return a value or didn't put their function in a class even though they got the answer correct seems kind of anal to me. Obviously strict adherance to the rules would be expected for contests where the whole point are the special rules like shortest code or obfuscation. I agree about the testing if we had a high turnout but when I have to test less than ten entries, the extra minute or two of setting up isn't a problem for me.
    Last edited by PJYelton; 05-26-2005 at 11:35 AM.

  14. #29
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    To an extent I agree,

    For example, if you say the program should return something, then perhaps the contestant's program should adhere to those rules.
    After all you are the host.

    However, let's say, taking the hard 1 problem as an example, you have asked to return the answer as an integer to main. In my case I have done neither. I output the solution directly from the function and the solution is of a *char* type. Now does this necessarily make this wrong? Remember it would only make a difference if you were doing something with that integer afterwards. In this case the user is merely viewing it, so what type it is hardly matters.

    Secondly, let's say the host decides the contestant must write a function - but that function has only one variable that passes into it. However, the contestant decides one more variable is needed so that his program may run smoothly. Should this be penalised?

    However, having said all that, I understand why the rules are there. It's there to make marking a lot easier.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Contest Results - Snake Numbers
    By pianorain in forum Contests Board
    Replies: 4
    Last Post: 06-22-2006, 09:14 AM
  2. Results of March Monthly Contest
    By PJYelton in forum Contests Board
    Replies: 23
    Last Post: 04-17-2005, 09:46 AM
  3. New Monthly Contest!
    By PJYelton in forum Contests Board
    Replies: 50
    Last Post: 03-22-2005, 08:27 PM
  4. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  5. Results for *easy* contest:
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-27-2002, 11:35 AM