From 7d7033cd615b0c1320e00ce8efb619532d40afe2 Mon Sep 17 00:00:00 2001 From: Kaputchino <61330453+Kaputchino@users.noreply.github.com> Date: Wed, 25 May 2022 18:56:07 +0200 Subject: [PATCH] add functions --- ZSharp/ZS.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/ZSharp/ZS.h b/ZSharp/ZS.h index 175beef..c5956e8 100644 --- a/ZSharp/ZS.h +++ b/ZSharp/ZS.h @@ -142,5 +142,64 @@ func GetKey(keyName) //{ // ZS.System.SplitThread(function) //} + +//Function made by Kaputchino + +//return the number of combinaison + +func Comb(n, r) +{ + return Perm(n ,r) / Fac(r) +} +//return the number of permutation + +func Perm(n, r) +{ + if n < 0 + { + ZS.System.PrintLine("n muss be superior or equal to 0") + return -1 + } + if r < 0 + { + ZS.System.PrintLine("r muss be superior or equal to 0") + return -1 + } + if r > n + { + ZS.System.PrintLine("r muss be inferor or equal to n") + return -1 + } + return Fac(n) / Fac(n - r) +} +//return the factorial of a number + +func Fac(x) +{ + int r = 1 + while x > 1 + { + r = r * x + x = x - 1 + } + return r +} +//return exp(x) by using the taylor method, not extremly accurate + +func TaylorExp(x) +{ + float sum = 0 + float term = 1 + int i = 1 + float sumterm = 1 + while sum != sumterm + { + sum = sumterm + term = term * x / i + i = i + 1 + sumterm = sumterm + term + } + return sum +} )" -; \ No newline at end of file +;