Posted By

Scooter on 06/14/08


Tagged

math


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

asifrizvigmailcom


Factorial


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2008/06/factorial.html

  1. <%
  2. ' ASP Mathematics Library - Factorial
  3. '
  4. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  5. '
  6. ' This work is licensed under the Creative Commons Attribution License. To view
  7. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  8. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  9. ' 94305, USA.
  10.  
  11. ' Determine the factorial for a given number
  12. function factorial(x)
  13. dim result
  14.  
  15. result = 1
  16.  
  17. if x > 1 then
  18. for i = 2 to x
  19. result = result * i
  20. next
  21. end if
  22.  
  23. factorial = result
  24. end function
  25.  
  26. ' Returns the number of combinations, without regard to order, of y items that can be made from a pool of x items.
  27. ' Requires factorial()
  28. function combinatorial(x, y)
  29. if (x >= y) and (y > 0) then
  30. combinatorial = factorial(x) / factorial(y) / factorial(x - y)
  31. else
  32. combinatorial = 0
  33. end if
  34. end function
  35.  
  36. ' Returns the number of permutations, with regard to order, of y items that can be made from a pool of x items.
  37. ' Requires factorial()
  38. function permutations(x, y)
  39. permutations = factorial(x) / factorial(x - y)
  40. end function
  41. %>

Report this snippet  

You need to login to post a comment.