PHP Classes

PHP Math Progressions: Calculate math progressions of several types

Recommend this page to a friend!
  Info   View files Example   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-10 (2 months ago) RSS 2.0 feedStarStarStarStar 60%Total: 141 All time: 9,176 This week: 75Up
Version License PHP version Categories
awesome-progressions 1.9The PHP License5.3PHP 5, Math
Description 

Author

This class can calculate math progressions of several types.

It provides several functions that take an initial number and the number of iteratuons to compute math progressions.

Currently it can compute math progressions of types: fibonacci, collatz,
cauchy, conway, generic arithmetic, and arithmetic progression using U(n+1) = U(n) + p.

Innovation Award
PHP Programming Innovation award nominee
February 2015
Number 7


Prize: One downloadable e-book of choice by O'Reilly
Progressions are sequences of numbers that are calculated based on the values of previous numbers in the sequence.

There are several types of math progressions. This class can compute the values of sequence numbers of several types of progressions.

Manuel Lemos
Picture of Ghali Ahmed
  Performance   Level  
Name: Ghali Ahmed <contact>
Classes: 5 packages by
Country: Tunisia Tunisia
Age: 40
All time rank: 22628 in Tunisia Tunisia
Week rank: 312 Up2 in Tunisia Tunisia Up
Innovation award
Innovation award
Nominee: 3x

Example

<script src="../p5/p5.js"></script>

<?php

include('../AwesomeProgression.php');
$awesomeProgression = new AwesomeProgression();

$fibonachi = json_encode($awesomeProgression->fibonnaci(isset($_GET['i'])?$_GET['i']:10, true));
?>

<form style="position: absolute; right:0; top:0; background: white; padding: 3px;">
<input name="i" type="text"/> <button type="submit">Update</button>
</form>

<script>
    var data = <?php echo $fibonachi ?>;
   
    var unite = 10;
    var canvasW = 1200;
    var canvasH = 700;
   
    function drawTile()
    {
        stroke(50);
        for (var i=0; i<canvasW; i += 2 * unite) {
            line(i, 0, i, canvasH);
        }

        for (var i=0; i<canvasH ; i += 2 * unite) {
            line(0, i, canvasW , i);
        }
    }

    function setup() {
        createCanvas(canvasW, canvasH);
        background(0);
        noSmooth();
        drawTile();
        var x0 = canvasW/4;
        var y0 = canvasH/4;
        var x = x0;
        var y = y0;
        j = 0;
        for (n=1; n<data.length; n++) {
            var width = height = data[n] * unite;
            if (n>2) {
                if (j == 4) {
                    p = -data[n-2];
                    k = -data[n];
                    j = 0;
                }
                else if (j == 3) {
                    p = data[n-1];
                    k = -data[n-2];
                }
                else if (j == 2) {
                    p = 0;
                    k = data[n-1];
                }
                else if (j == 1) {
                    p = -data[n];
                    k = 0;
                }
                else if (j == 0) {
                    p = -data[n-2];
                    k = -data[n];
                }

                translate(
                    p * unite,
                    k * unite
                );

                j++;
            } else {
                translate((n * width) - width, 0);
            }

            fill(alpha(color(0, 126, 255, (n+1) * 10)));
            stroke(10);

            rect(x0, y0, width, height);
            stroke(255);
            var fontsize = data[n] * 2;
            textSize(fontsize);
            text("" + data[n], x0 + width/2 - fontsize/2, y0 + height/2 + fontsize/2);
        }
    }

</script>


Details

Usage & debug

<pre> $math = new AwesomeProgression();

$math->debug('fibonnaci 4 = 3', $math->fibonnaci(4, true)); $math->debug('fibonnaci 8 = 21', $math->fibonnaci(8, true)); </pre>

Tests

phpunit --verbose AwesomeProgressionTest.php


  Files folder image Files  
File Role Description
Files folder imagedemo (1 file)
Files folder imagep5 (2 files, 2 directories)
Plain text file AwesomeProgression.php Class Class source
Accessible without login Plain text file AwesomeProgressionTest.php Test Unit test script
Accessible without login Plain text file Readme.md Data Auxiliary data

  Files folder image Files  /  demo  
File Role Description
  Accessible without login Plain text file fibonnaci.php Example Example script

  Files folder image Files  /  p5  
File Role Description
Files folder imageaddons (3 files)
Files folder imageempty-example (2 files)
  Accessible without login Plain text file p5.js Data Auxiliary data
  Accessible without login Plain text file p5.min.js Data Auxiliary data

  Files folder image Files  /  p5  /  addons  
File Role Description
  Accessible without login Plain text file p5.dom.js Data Auxiliary data
  Accessible without login Plain text file p5.sound.js Data Auxiliary data
  Accessible without login Plain text file p5.sound.min.js Data Auxiliary data

  Files folder image Files  /  p5  /  empty-example  
File Role Description
  Accessible without login Plain text file index.html Data Documentation
  Accessible without login Plain text file sketch.js Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:141
This week:0
All time:9,176
This week:75Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:75%StarStarStarStar
Documentation:-
Examples:75%StarStarStarStar
Tests:75%StarStarStarStar
Videos:-
Overall:60%StarStarStarStar
Rank:1215