Skip to content

Instantly share code, notes, and snippets.

@crablab
Created May 10, 2018 20:06
Show Gist options
  • Select an option

  • Save crablab/ae17f34f4e473ee70f45ca5b780b774b to your computer and use it in GitHub Desktop.

Select an option

Save crablab/ae17f34f4e473ee70f45ca5b780b774b to your computer and use it in GitHub Desktop.
A solution for a coding challenge
<?php
/*
Uses: https://gist.github.com/ircmaxell/1232629
*/
require_once 'Math.php';
$math = new Math();
$html = file_get_contents("http://sphinx.mythic-beasts.com/cgi-bin/job.pl");
preg_match("/.+?(?=,)/", $html, $find_equation);
$find_equation[0] = preg_replace("/^(<p>Evaluate)\s+/", "", $find_equation[0]);
$answer = $math->evaluate($find_equation[0]);
echo($find_equation[0] . " = " . $answer . "\n");
preg_match("/(?<=(name=\"id\" value=\"))[0-9 a-z A-Z]*/", $html, $id);
$params=['answer'=>$answer, 'id'=>$id[0], 'submit'=>'submit'];
$defaults = array(
CURLOPT_URL => 'http://sphinx.mythic-beasts.com/cgi-bin/job.pl',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params,
CURLOPT_VERBOSE => true,
);
$ch = curl_init();
curl_setopt_array($ch, $defaults);
$result = curl_exec($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment