'############################################
'# ASCII Sierpinski Triangle By Ashish #
'# Fractal is generated with the help of #
'# Pascal Triangle. #
'# 23 Oct, 2019 #
'# B+ mod of nCr function allows for more. #
'# Oh, hey try Johnno's idea! #
'############################################
CONST xmax
= 800, ymax
= 800 _TITLE "ASCII Sierpinski Triangle" x
= (_WIDTH / 8) / 2 'start from the centre of the screen d$ = " "
c$
= _TRIM$(STR$(nCr
(i
, j
))) 'calculate the number value of the triangle d$ = d$ + c$ + " "
'PRINT
x = x - 1 'shift each step towards left as the triangle row move down.
' B+ alt way to calculate nCr, generalized 2019-10-23
'Note: I am using notes from a successful calc to generalize this method.
' How many hands of 13 from a deck?
' Formula for Combination of N items taken R at a time = N!/(R! * (N-R)!) so we need
' 52! / (39! * 13!) = 52 * 51 * 50 * 49 * ... * 40 / 13 * 12 * 11 * ... * 1
a = n - r
IF a
< r
THEN r
= a
'results are symmteric for r and n-r so use smaller of 2 a = n - r
' DIM a52_39(1 TO 13) AS INTEGER, a13(1 TO 13) AS INTEGER
numer(i) = a + i ' = 40, 41, 42, 43, ... 52 numerator multipliers
denom(i) = i ' = 1, 2, 3, 4, ... 13 denominator multipliers
' To keep the numerator from getting too big reduce numerator terms by demoinator terms that divide evenly
found = 0
FOR j
= 1 TO r
'is the array item divisible by i IF found
= 1 THEN denom
(i
) = 1
' multiply whats left in numerator and denomiator
numerator = 1: denomenator = 1
numerator = numerator * numer(i) 'multiple numerators left
denomenator = denomenator * denom(i) 'multiply denominators left
nCr~&& = numerator \ denomenator