Another Typo
Another Typo
It was a bit challenging to figure out how to change 2245 to get 165. I finaly found the solution toying around with wolfram alpha (http://www.wolframalpha.com/).
-
- Forum Admin
- Posts: 496
- Joined: Sat May 28, 2011 9:14 am
- Location: Germany
Re: Another Typo
165? Huh? I found the solution after 5 minutes of trying - the previous one, 'Typo', actually took me longerIIMOG wrote:It was a bit challenging to figure out how to change 2245 to get 165.
This challenge is obviously solvable with trial and error, but the (more) logical approach looks like this:
Then this reduces to the problem to make 165 by changing one digit of 2245 into something else.
It was the hard part to find out that 0245 (preceding 0 means octal) = 165.
Code: Select all
13186 = 79 * 2245 + (79 * 2 - 7)
13186 = 79 * 2245 + 151
13035 = 79 * 2245
165 = 2245
It was the hard part to find out that 0245 (preceding 0 means octal) = 165.
-
- Forum Admin
- Posts: 496
- Joined: Sat May 28, 2011 9:14 am
- Location: Germany
- MyNameIsAlreadyTaken
- Posts: 31
- Joined: Sun Oct 17, 2010 10:21 am
- Location: Germany
Re: Another Typo
Same here - I found the solution to this one pretty fast, whereas "Typo" took a whole lot of time.AMindForeverVoyaging wrote:165? Huh? I found the solution after 5 minutes of trying - the previous one, 'Typo', actually took me longer ;)
i used php's eval function....
Code: Select all
<?php
$replacement = array('+','-','*','/',1,2,3,4,5,6,7,8,9,0,'^','%');
$ch = array('*',2,2,4,5,'+','*',2,'-',7);
for ($i = 0; $i < count($ch); $i++) {
$ch = array('*',2,2,4,5,'+','*',2,'-',7);
for ($n = 0; $n < count($replacement); $n++) {
$ch[$i] = $replacement[$n];
$formula = '$x=79'.$ch[0].$ch[1].$ch[2].$ch[3].$ch[4].$ch[5].'(79'.$ch[6].$ch[7].$ch[8].$ch[9].');';
//$formula = '$x'.'= 79'.$op1.'2245'.$op2.'(79'.$op3.'2'.$op4.'7);';
eval($formula);
if( $x == 13186) {
echo($formula.'<br />');
echo $x.'<br />';
echo $replacement[$$n].'<br />';
}
}
}
?>
I used php too, I haven't touched it for about 10 years!
Code: Select all
<?php
// run from terminal using php -f whatevername.php
$original = "echo 79 * 2245 + (79 * 2 - 7);";
echo "string length: " . strlen($original) . "\n";
$replace = range("!","?");
$i = 4;
while ($i < 31) {
$try = $original;
$check = '';
foreach ($replace as $token) {
$try[$i] = $token;
echo "trying: " . $try . "\n";
try {
ob_start();
eval($try);
$check = ob_get_contents();
ob_end_clean();
} catch (Exception $e) {
// ignore exception and continue
}
if ((int)$check === 13186) {
echo "Answer found at position " . $i . " with char " . $token . "\n";
echo $i . "," . $token . "\n";
break 2;
}
}
$i++;
}
?>