Skip to content

Instantly share code, notes, and snippets.

@kittinan
Created March 12, 2015 06:14
Show Gist options
  • Save kittinan/ae3286ed4924a6b30226 to your computer and use it in GitHub Desktop.
Save kittinan/ae3286ed4924a6b30226 to your computer and use it in GitHub Desktop.
Codejam Qualification Round 2012 - Speaking in Tongues
<?php
$filename = 'A-small-practice.in';
$lines = file($filename);
$input_size = trim($lines[0]);
$map = array(
'a' => 'y',
'b' => 'h',
'c' => 'e',
'd' => 's',
'e' => 'o',
'f' => 'c',
'g' => 'v',
'h' => 'x',
'i' => 'd',
'j' => 'u',
'k' => 'i',
'l' => 'g',
'm' => 'l',
'n' => 'b',
'o' => 'k',
'p' => 'r',
'q' => 'z',
'r' => 't',
's' => 'n',
't' => 'w',
'u' => 'j',
'v' => 'p',
'w' => 'f',
'x' => 'm',
'y' => 'a',
'z' => 'q',
);
$line_decodes = array();
for ($i = 1; $i <= $input_size; $i++) {
$line = trim($lines[$i]);
$line_length = strlen($line);
$line_decode = 'Case #' . $i . ': ';
for ($j = 0; $j < $line_length; $j++) {
if ($line[$j] == ' ') {
$line_decode .= ' ';
continue;
}
$line_decode .= $map[$line[$j]];
}
$line_decodes[] = $line_decode;
}
file_put_contents($filename.'.output.txt', implode("\n", $line_decodes));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment