Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic Examples => Topic started by: Charles Pegge on January 24, 2026, 10:23:15 PM

Title: Factorial Functions F! pling
Post by: Charles Pegge on January 24, 2026, 10:23:15 PM
'24/01/2026
'CP

'stats & pascal's triangle binomials
'inverse probability q = m! / n! * (m-n)!


function f!(float m) as float
=============================
'factorial m!
float t=1
do
  exit when m<2
  t*=m
  m--
loop
return t
end function

function f!(float m, n) as float
================================
'coefficient  m! / (n! * (m-n)!
float t=1, d=1
do
  exit when n<1
  t*=m
  d*=n
  m--
  n--
loop
return t/d
end function

'TESTS
'
'There are 3 red snooker balls concealed in a bag of 8

'3 red balls picked out of 3 red balls in bag of 8
'calulate the inverse probability:

float qq=f!(8,3)
print str(qq,4)

'3 non-red balls picked out of 5 non-red balls in bag of 8
'calulate the inverse probability:
'
float q1=f!(5,3)
float qq=f!(8,3)/q1
print str(qq,4)