Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $upto = 2000000;
- // change the value of THIS specific variable to graph up to some value (originally 2000000).
- // also, don't try any lower than 26000. there wouldn't be even a single point.
- function collatz($x) {
- if ($x % 2 == 0) {
- return $x/2;
- } else {
- return 3*$x+1;
- }
- }
- $t = 0;
- $x = 0;
- $f = "";
- for ($i = 1; $i <= $upto; $i++) { // $i is basically the variable x the plot is based upon.
- $j = $i;
- while ($j > 1) {
- $j = collatz($j);
- if ($j == 5) {
- $t += 1; // t at $i = x is N(x).
- }
- }
- $x += $t/$i; // the ratio N(x)/x.
- print "($i) " . ($x/$i) . "\n"; // you can remove this line, this only displays every single value of N(x)/x.
- if ($i % 1000 == 0) { // this would take too long to graph otherwise, but you can remove it if you're an absolute madman.
- $f .= "<div style='position: absolute; left: " . ($i/1000) . "px; bottom: " .
- ($x/$i*((10-900)/(0.93701840707864 - 0.93766121527656))+(10-0.93701840707864*((10-900)/(0.93701840707864 - 0.93766121527656))))
- // zooms such that the local minimum of the curve falls at 10px from the bottom and the maximum at 900px from it.
- // you can, of course, replace 900 by something else if your screen resolution is different.
- . "px'>.</div>\n";
- }
- }
- file_put_contents("full.html", $f); // the graph will be exported into "full.html" in the same folder as where this file is.
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement