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]
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. ;)
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 :confused: 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++;
}
?>
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?
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 :confused: 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>
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.
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. :rolleyes: