Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,156,771 members, 7,831,478 topics. Date: Friday, 17 May 2024 at 07:24 PM

Simple PHP Challenge (3) - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Simple PHP Challenge (3) (552 Views)

How To Create A Simple PHP Website With PBNL Anybody Can Do It! (naijazoom.com) / What Is Wrong With This Simple PHP - MYSQL Script / Another Simple Php/python/asp/etc Challenge (2) (3) (4)

(1) (Reply) (Go Down)

Simple PHP Challenge (3) by elvis10ten(m): 5:17pm On Jul 15, 2013
Write a program that prints the gcf(greatest common factor, that is the greatest number in the common factor of the numbers) of two numbers, If there is no gcf return "1 as the highest gcf". Example the gcf of 15 and 30 is 15, the gcf of 10 and 3 is 1.
RULES
1)Run your code on www.ideone.com or post it here if you can't.
2)The shortest a fastest code wins.
3)Your code should be robust and work with any cpu.
4)Your code should be able to run properly on a poor cpu/hardware. Good luck
Re: Simple PHP Challenge (3) by funkymedina: 6:35pm On Jul 15, 2013
Good to see you active on the forum.
Re: Simple PHP Challenge (3) by elvis10ten(m): 6:47pm On Jul 15, 2013
funky medina: Good to see you active on the forum.
Ok.
Re: Simple PHP Challenge (3) by Z8(m): 8:33am On Jul 16, 2013
//first number
$number = array($i,$j,)
//Determine the lowest of the numbers
asort($number);
//Lowest of the numbers
$lower_limit = $number[0];
//get all the factors of all the numbers,
For($g=0; $g<=$lower_limit; $g++){
For($h=0;$h<=count($number)-1;$h++){
If(fmod($number[$h],$g) == 0){
$factors[$number[$h]][] = $number[$h]/$g;
}
}
}
// all common factors
$c_factor = array_intersect($factors[0],$factors[1]);
//highest common factor
$g_c_factor = max($c_factor);

echo $g_c_factor;
Re: Simple PHP Challenge (3) by Z8(m): 8:42am On Jul 16, 2013
Z8: //first number
$number = array($i,$j,)
//Determine the lowest of the numbers
asort($number);
//Lowest of the numbers
$lower_limit = $number[0];
//get all the factors of all the numbers,
For($g=0; $g<=$lower_limit; $g++){
For($h=0;$h<=count($number)-1;$h++){
If(fmod($number[$h],$g) == 0){
$factors[$number[$h]][] = $number[$h]/$g;
}
}
}
// all common factors
$c_factor = array_intersect($factors[0],$factors[1]);
//highest common factor
$g_c_factor = max($c_factor);

echo $g_c_factor;


ideone.com/wjMeL2
That's the link in the site ran in 0.01 seconds but can't see the output to confirm its error free. Though am sure its good
Re: Simple PHP Challenge (3) by Nobody: 1:57pm On Jul 16, 2013
http://ideone.com/vyBw4v

  function phpChallenge($int1,$int2){
$bool = true;
while($bool){
if($int1 == $int2) return $int2;
($int1 > $int2 ? $int1 -=$int2 : $int2 -= $int1);
}
}


time: 0.01s memory: 20520 kB
Re: Simple PHP Challenge (3) by elvis10ten(m): 2:40pm On Jul 16, 2013
Z8:


ideone.com/wjMeL2
That's the link in the site ran in 0.01 seconds but can't see the output to confirm its error free. Though am sure its good
Where is your <?php and ?>. I didn't really look at your code tho, i just noticed those at first. Please correct and try again
Re: Simple PHP Challenge (3) by elvis10ten(m): 2:56pm On Jul 16, 2013
Judinho59: http://ideone.com/vyBw4v

  function phpChallenge($int1,$int2){
$bool = true;
while($bool){
if($int1 == $int2) return $int2;
($int1 > $int2 ? $int1 -=$int2 : $int2 -= $int1);
}
}


purely wrong solution. Your code will only work with some gcf and not all, so it isn't robust. The rule states so. Here is your solution at work http://ideone.com/dofcYO
Re: Simple PHP Challenge (3) by Nobody: 3:56pm On Jul 16, 2013
cry

http://ideone.com/nwRmVf

function phpChallenge($int1, $int2){
while($int2 != 0){
$rem = $int1 % $int2;
$int1 = $int2;
$int2 = $rem;
}
return (empty($int1) ? '1' : $int1);
}
Re: Simple PHP Challenge (3) by Z8(m): 4:16pm On Jul 16, 2013
elvis10ten: Where is your <?php and ?>. I didn't really look at your code tho, i just noticed those at first. Please correct and try again

Haha u right taken for granted...please ignore the mistake and check if the code is valid
Re: Simple PHP Challenge (3) by elvis10ten(m): 4:32pm On Jul 16, 2013
Z8:

Haha u right taken for granted...please ignore the mistake and check if the code is valid
organise the code yourself and run it. Lets see.
Re: Simple PHP Challenge (3) by Z8(m): 11:41pm On Jul 16, 2013
ideone.com/tHKAbQ
Re: Simple PHP Challenge (3) by Z8(m): 11:43pm On Jul 16, 2013
Z8: ideone.com/tHKAbQ
Organized and running

(1) (Reply)

Teach Myself Web Designing / Pls Help Me With Search Engine Uptimization Codes, I Need To Integrate It / Naijaflirt

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.