Factorial

About advanced scenes, and the Thyme scripting language used in Algodoo.

Factorial

Postby Skrubs » Mon May 21, 2018 12:35 am

Is there a way to calculate factorials in thyme ? if yes say how.
Skrubs
 
Posts: 16
Joined: Tue Mar 06, 2018 7:36 pm

Re: Factorial

Postby Xray » Tue May 29, 2018 11:01 pm

As far as I know there is no single operator in Thyme which will calculate factorials. So, I think the best way to handle it is to create a function which calculates the factorial, and simply call the function like a subroutine with a single argument. In case you didn't know, factorial is calculated as follows:

n!=n×(n−1)×(n−2)...×2×1

where, n is a positive integer.
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Factorial

Postby FRA32 » Tue Jun 05, 2018 6:25 pm

press f10 to open the console, then type this:

scene.my.factorial = (n)=>{
n>2 ? {
n*scene.my.factorial(n-1)
} : {
2
}
}

then you can use factorials in that scene by typing scene.my.factorial(number).
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 9 guests

cron