[Solution] Facebook Hacker Cup 2012 – Qualification round – Alphabet soup (letters)

Was bored so decided to optimize my solution a little bit more.

You can find the original solution here.

 

$file_content = explode("\n",(fread(fopen("input.txt",'r'), filesize("input.txt")));

$output = fopen("output.txt", 'w');
$hacker = array('h','a','c','k','e','r','u','p');

for ($j = 1; $j <= intval($file_content[0]); $j++){
for ($zzz = 0; $zzz < count($hacker); $zzz++){
$freq[$hacker[$zzz]] = 0;
}
	$word = strtolower(str_replace(" ","",$file_content[$j]));
	$len = strlen($word);
		for ($i=0; $i<$len; $i++) {
		  $letter = $word[$i];
		  if (in_array($letter,$hacker)){
		     if ($letter =="c") {$freq[$letter] +=  0.5;}
		     else {$freq[$letter]++;}
		}
		}
	$stringData = "Case #" . $j . ": " . intval(min($freq)) . "\n";
	fwrite($output, $stringData);
}
fclose($output);

One thought on “[Solution] Facebook Hacker Cup 2012 – Qualification round – Alphabet soup (letters)

  1. Pingback: [Solution] Facebook Hacker Cup 2012 – Qualifying round – Alphabet Soup | just another blog page . . .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>