Wednesday, 20 July 2011

Factorials in Q

I want to compute a binomial coefficient for a program I am working on for helping poker players during play and noticed that a factorial function is not built into the Q language and would have thought that "!" would have been overloaded to support factorials so I decided to write my own one:

.q.fctrl:{prd 1+til x}

Voila; now you have a factorial function that takes a scalar and computes its factorial

q)fctrl 5
120

No comments:

Post a Comment