PHP Script to Find Missing Gadget

Posted
Comments 0

My friend told me that his gadget was missing. He asked me a help to find it. As a programmer I had to say “almost nothing impossible”. That jargon meant I would find an algorithm to solve any problem. But the result might be accepted or rejected. I have to try..

“Well, okay. You are programmer, aren’t you?” I asked to know his background.
“Yes, I am. I know much PHP,” he answered.
“Okay, I’ll send you an email this night,” I promised.

Then.. At the middle of the night I wrote a short script to help him, as follows:

// Dear friend,
// Try this script. It might work :)

<?php

function is_near($p, $q){
  $r = sqrt(($q[0]-$p[0])**2 + ($q[1]-$p[1])**2);
  return $r < 1;
}

function find_my_gadet($location){
  $x = rand();
  $y = rand();

  if (is_near(explode(",",$location), [$x, $y])){
    echo "play horay.mp3";
    return true;
  }
  if (SavingAccount::balance > 3e6){
    $h = new Gadget();
    return $h;
  }
  return new Hope("interval 1 year");
}

if (isset($_GET['location'])){
  $location = explode(",", $_GET['location']);
  $result = find_my_gadget($location);
  print_r($result);
} else {
  echo "Location must be set!";
}
?>

I sent him as an email attachment as I promised, but never received his comment. :)

Author
Categories PHP

Comments

There are currently no comments on this article.

Comment

Enter your comment below. Fields marked * are required. You must preview your comment before submitting it.






Comments

There are currently no comments on this article.

Comment

Enter your comment below. Fields marked * are required. You must preview your comment before submitting it.