]> git.mxchange.org Git - core.git/commitdiff
Added calculation scripts (I know, they might be wrong) + moved some files and
authorRoland Haeder <roland@mxchange.org>
Thu, 14 May 2015 17:37:26 +0000 (19:37 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 14 May 2015 17:37:26 +0000 (19:37 +0200)
all these scripts are provided AS IS AND WITHOUT ANY WARRANTY.

Signed-off-by: Roland Häder <roland@mxchange.org>
contrib/LICENSE [new file with mode: 0644]
contrib/chash/LICENSE [deleted file]
contrib/exp/exp1.php [new file with mode: 0644]
contrib/exp/exp2.php [new file with mode: 0644]
contrib/fib.php [deleted file]
contrib/fib/fib.php [new file with mode: 0644]

diff --git a/contrib/LICENSE b/contrib/LICENSE
new file mode 100644 (file)
index 0000000..74f55a9
--- /dev/null
@@ -0,0 +1,2 @@
+These contributed codes, mostly by myself, are for testing/experimenting
+purposes only and are provided "AS IS" and "WITHOUT ANY WARRANTY".
\ No newline at end of file
diff --git a/contrib/chash/LICENSE b/contrib/chash/LICENSE
deleted file mode 100644 (file)
index 74f55a9..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-These contributed codes, mostly by myself, are for testing/experimenting
-purposes only and are provided "AS IS" and "WITHOUT ANY WARRANTY".
\ No newline at end of file
diff --git a/contrib/exp/exp1.php b/contrib/exp/exp1.php
new file mode 100644 (file)
index 0000000..6ffd1a0
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+error_reporting(E_ALL | E_STRICT);
+
+print 'Eat 1 apple at the first day and next day eat twice!' . PHP_EOL;
+
+$years = 100;
+$m = $years / 4;
+
+$totalDays = ($years * 365 + $m);
+
+$x = 1; $y = 0;
+for ($i = 1; $i <= $totalDays; $i++) {
+       $x = bcmul($x, 2);
+       $y = bcadd($y, $x);
+} // END - foreach
+
+print 'After ' . $totalDays . ' days (' . $years . ' years) you have eaten ' . $y . ' fruits.' . PHP_EOL;
+print 'Length:' . strlen($y) . PHP_EOL;
+
+?>
diff --git a/contrib/exp/exp2.php b/contrib/exp/exp2.php
new file mode 100644 (file)
index 0000000..22e985d
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+error_reporting(E_ALL | E_STRICT);
+
+bcscale(20);
+
+$balance = 1;
+$years = 100;
+$rate = 0.05;
+
+$totalMonths = $years * 12;
+
+print 'Invest ' . $balance . ' EUR and come back later.' . PHP_EOL;
+
+for ($i = 1; $i <= $totalMonths; $i++) {
+       if ($i % 12 == 0) {
+               $rate = bcdiv($rate, 1.01);
+       } // END - if
+
+       $interest = bcmul($balance, $rate);
+       $balance = bcadd($balance, $interest);
+
+       print 'Month ' . $i . ': rate=' . bcmul($rate, 100) . '%,interest=' . $interest . ',balance=' . $balance . PHP_EOL;
+} // END - foreach
+
+print 'After ' . $totalMonths . ' months (' . $years . ' years) you have ' . $balance . ' EUR back.' . PHP_EOL;
+//print 'Length:' . strlen($balance) . PHP_EOL;
+
+?>
diff --git a/contrib/fib.php b/contrib/fib.php
deleted file mode 100644 (file)
index 554557f..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-error_reporting(E_ALL | E_STRICT);
-
-$prev = 1;
-$fib = 1;
-
-for ($idx = 0; $idx < 100000; $idx++) {
-       $diff = bcdiv($fib, $prev, 500);
-
-       print 'idx=' . $idx . PHP_EOL;
-       print 'fib=' . $fib . PHP_EOL;
-       print 'prev=' . $prev . PHP_EOL;
-       print 'diff=' . $diff . PHP_EOL;
-
-       $sum  = bcadd($prev, $fib);
-       $prev = $fib;
-       $fib  = $sum;
-}
-
-?>
diff --git a/contrib/fib/fib.php b/contrib/fib/fib.php
new file mode 100644 (file)
index 0000000..554557f
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+error_reporting(E_ALL | E_STRICT);
+
+$prev = 1;
+$fib = 1;
+
+for ($idx = 0; $idx < 100000; $idx++) {
+       $diff = bcdiv($fib, $prev, 500);
+
+       print 'idx=' . $idx . PHP_EOL;
+       print 'fib=' . $fib . PHP_EOL;
+       print 'prev=' . $prev . PHP_EOL;
+       print 'diff=' . $diff . PHP_EOL;
+
+       $sum  = bcadd($prev, $fib);
+       $prev = $fib;
+       $fib  = $sum;
+}
+
+?>