Another Typo

Discussion of challenges you have already solved
Post Reply
IIMOG
Posts: 9
Joined: Thu Jun 02, 2011 8:35 pm

Another Typo

Post by IIMOG »

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/).
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Re: Another Typo

Post by AMindForeverVoyaging »

IIMOG wrote:It was a bit challenging to figure out how to change 2245 to get 165.
165? Huh? I found the solution after 5 minutes of trying - the previous one, 'Typo', actually took me longer ;)
uws8505
Posts: 32
Joined: Sun Jan 23, 2011 8:57 pm

Post by uws8505 »

This challenge is obviously solvable with trial and error, but the (more) logical approach looks like this:

Code: Select all

13186 = 79 * 2245 + (79 * 2 - 7)
13186 = 79 * 2245 + 151
13035 = 79 * 2245
165 = 2245
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.
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

Ah. So I found the solution rather accidentally. :)
User avatar
MyNameIsAlreadyTaken
Posts: 31
Joined: Sun Oct 17, 2010 10:21 am
Location: Germany

Re: Another Typo

Post by MyNameIsAlreadyTaken »

AMindForeverVoyaging wrote:165? Huh? I found the solution after 5 minutes of trying - the previous one, 'Typo', actually took me longer ;)
Same here - I found the solution to this one pretty fast, whereas "Typo" took a whole lot of time.
gandhi
Posts: 7
Joined: Thu Nov 25, 2010 7:56 pm

Post by gandhi »

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 />';
        }
    }    
}
?>
destiny
Posts: 25
Joined: Thu Jul 03, 2014 4:08 pm
Location: UK

Post by destiny »

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++;
}
?>
Post Reply