Fast Triangular Numbers


/ Published in: PHP
Save to your folder(s)

Explanation of the method used here in the URL.


Copy this code and paste it in your HTML
  1. <?php
  2. /*
  3.  * Due to being a simple piece of mathematics, my triangular number function is likely
  4.  * exempt from copyright, but just in case I eschew all copyright and give it entirely
  5.  * to the public domain.
  6.  * --Joey Sabey
  7.  */
  8.  
  9. function triangularNumber($_x) {
  10. return (($_x / 2) + 0.5) * $_x;
  11. }
  12.  
  13. ?>

URL: http://www.curiousmath.com/index.php?name=News&file=article&sid=95

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.