#!/usr/bin/perl -w
use strict;
use v5.10;
my $limit = $ENV{QUERY_STRING} || 200;
$limit = 200 if $limit > 200;
my ($a, $b, $c, $d, $e, $f, $g, $h, $attempts);
do {
$attempts++;
($d, $e, $f, $g, $h) = map { int(rand($limit + 1) - $limit / 2) } 1..5;
# d(e + f)(g + h) = deg + deh + dfg + dfh
$a = $d * $e * $g; # Ax²
$b = $d * $e * $h + $d * $f * $g; # Bx
$c = $d * $f * $h; # C
} until (
$a * $b * $c
and abs($a) < $limit
and abs($b) < $limit
and abs($c) < $limit
);
printf<<"EOF", $attempts > 1 ? "s" : "", $b, $c, $f, $h;
Content-Type: text/html; charset=utf-8
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Factorable Polynomial ($attempts attempt%s) - The Almighty Pegasus Epsilon</title>
<link rel="icon" type="image/png" href="/images/favicon.png" />
<link rel="stylesheet" type="text/css" href="/css" />
<meta name="viewport" content="user-scalable=no" />
</head>
<body>
<!--
coefficient limit: $limit.
add ?### to the end of the URL to change the coefficient limit.
limits greater than 200 will be limited to 200.
-->
<div style="font-size: 72pt; text-align: center;">
${a}x²%+dx%+d
</div>
<!-- $d(${e}x%+d)(${g}x%+d) -->
</body>
</html>
EOF