CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Coder speed challenge

    Hey,

    I have an idea for a game. Here are the rules

    1. The current Game Master states a simple programming problem.
    2. The players post their solutions for the problem in any language that they desire.
    2A. If someone intends to take part in a given round but cannot post a solution right away, he should post a message so the others would know and the GM would wait for him.
    3. 24 hours later the GM selects the solution he likes best and its author becomes the new GM
    4. goto 1

    So. Yes, there is not a rule which determines whether the fastest, the smalles or the most obfuscated solution will win. The criteria for the winner depends entirely on the Game Master's taste. And yes, there is no limit to the problems' complexity but we are encouraged to use simple ones, because we usually don't have a lot of free time. I wouldn't ask a problem or try to solve one if I think the solution will take more than an hour.

    So let me start and with that give you an example of a simple problem:

    Problem 1

    The input is a number. You must split this number in prime (and consider '1' to be prime for this one) parts in any possible way. Here is some sample I/O:

    I: 1234567 O: 1 2 3 4567; 1 23 4567

    I: 111 O: 1 1 1; 11 1; 1 11;

    I: 34 O:

    I: 7 O: 7

    34 cannot be split into prime parts so no output is generated.
    I think it should take no more than 30 minutes of thinkig and writing alltogether.

    Hope you like the idea and good luck.
    Last edited by SeventhStar; April 10th, 2007 at 01:07 PM.
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Coder speed challenge

    One additional suggestion. People who want to play should Post a message for a given round, so that we know if this is going to take off. Right now, there could be 1000 players or just me....

    [I'm IN]
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Re: Coder speed challenge

    Quote Originally Posted by TheCPUWizard
    One additional suggestion. People who want to play should Post a message for a given round, so that we know if this is going to take off. Right now, there could be 1000 players or just me....

    [I'm IN]
    Sounds fair.
    Rules updated.
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Coder speed challenge

    1234567 has a lot more prime numbers than you have for it. It should have...

    1 3 5 7 23 67 4567

    I guess that I am by your problem. What do you mean by split every way possible? The following finds all prime numbers possible by combinations (not rearranging the characters) of the string.

    PHP Code:
    <?php
    function chk_prime($int){
      for(
    $i 2$i $int$i++){
        if(
    $int $i == 0){return false;}
      }
      return 
    true;
    }

    $str "1234567"// 1  3  5  7  23  67  4567

    $pos 0;
    for(
    $total_chars 1$total_chars <= strlen($str); $total_chars++){
      for(
    $cur_pos 0$cur_pos strlen($str) - $pos$cur_pos++){
        
    $cur_str substr($str$cur_pos$total_chars);
        if(
    chk_prime($cur_str)){
          echo 
    $cur_str ' ';
        }
      }
      
    $pos++;
    }
    ?>
    Last edited by PeejAvery; April 10th, 2007 at 01:38 PM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Coder speed challenge

    PeejAvery,

    So was I at first... The idea is to NOT look at it as a number at all, but rather as a string of digits. Find the combination of splits such that each split represents a prime number

    711 can be split
    7-11
    71-1
    7-1-1
    Identify those splits where each of the parts are prime numbers [items #1,#3 definately qualify, not sure if 71 is prime....]

    Get it?
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Re: Coder speed challenge

    Quote Originally Posted by PeejAvery
    1234567 has a lot more prime numbers than you have for it. It should have...

    1 3 5 7 23 67 4567

    I guess that I am by your problem. What do you mean by split every way possible? The following finds all prime numbers possible by combinations (not rearranging the characters) of the string.
    ...
    Take another look at the problem and at the sample i/o By 'split' I meant a pure geometrical split. Inserting spaces in the appropriate places if you like

    1234567 can only be split in two ways
    1 2 3 4567
    and
    1 23 4567

    Any other way would either be not composed entirely of prime numbers or won't give the input number if you remove the spaces. Look at how 34 gives no output. It's because 34 is not prime and "3, 4" are not two prime numbers.

    <edit> and what TheCPUWizard said in his reply </edit>
    Last edited by SeventhStar; April 10th, 2007 at 01:50 PM.
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: Coder speed challenge

    Well, in that case I will have to bow/fall/stumble/drop out. I now understand what you are attempting to do, but I don't have that much time.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Re: Coder speed challenge

    Well it seems noone, except TheCPUWizard is willing to participate. I suggest we give it another day or so and maybe someone else will post something.

    It seemed like a nice idea, though.
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured