Aliens Among Us
#1
I just saw a video and hey they are right here in this!
Code: (Select All)
_Title "Pascal Triangle display exercise 2018-01-13 bplus"
'2018-01-13 Pascal Triangle.txt for JB 2015-10-31 MGA/B+

_Define A-Z As _INTEGER64

Const xmax = 1200
Const ymax = 400

Screen _NewImage(xmax, ymax, 32)
_ScreenMove 100, 60

printline = 2
For row = 0 To 20
    build$ = ""
    printline = printline + 1
    For column = 0 To row
        build$ = build$ + Right$(Space$(7) + Str$(binom(row, column)), 7)
    Next
    Locate printline, (150 - Len(build$)) / 2
    Print build$
Next
Sleep

Function binom (n, m)
    binom = fac(n) / (fac(m) * fac((n - m)))
End Function

Function fac (n)
    f = 1
    For i = 1 To n
        f = f * i
    Next
    fac = f
End Function

To be continued... as soon as I get it coded  ;-))

Meanwhile wonder WTH?

Oh better yet, try to anticipate where I am going with this.
b = b + ...
Reply
#2
Finally got the code to match a couple other forums but only a few really look like aliens.

Wait... how would I know what aliens look like?
b = b + ...
Reply
#3
You have me intrigued.
Reply
#4
I better not build it up too much. I saw it here, 55 secs to 1:15 secs, https://www.youtube.com/watch?v=o1eLKODSCqw

I checked to see if done anywhere else, ie in code, no but I found this too,  
https://www.reddit.com/r/visualizedmath/...in_binary/

And here is code that draws out the "aliens":
Code: (Select All)
_Title "Pascal Triangle Aliens Among Us" '2022-10-10 bplus

_Define A-Z As _INTEGER64
Screen _NewImage(500, 500, 32)
_ScreenMove 350, 100

For row = 0 To 20 ' level on pyramind 0 is 1, 1 is 1,1  2 is 1,2,1...
    Print "Row"; row
    For col = 0 To row
        b$ = Dec2Bin$(binom(row, col))
        'Print b$; ",";
        h = (1 + Len(b$)) * 20
        For y = 1 To Len(b$)
            If Mid$(b$, y, 1) = "1" Then Line (250 - 10 * row + col * 20, 500 - h + y * 20)-Step(20, 20), _RGB32(0, 180, 0), BF
        Next
    Next
    Sleep
    Cls
Next

Function binom (n, m)
    binom = fac(n) / (fac(m) * fac((n - m)))
End Function

Function fac (n)
    f = 1
    For i = 1 To n
        f = f * i
    Next
    fac = f
End Function

Function Dec2Bin$ (integerBase10 As _Integer64) 'no more &B because easier to add than to remove
    Dim j As Integer, b$
    If integerBase10 = 0 Then Dec2Bin$ = "0": Exit Function
    While 2 ^ j <= integerBase10
        If (integerBase10 And 2 ^ j) > 0 Then b$ = "1" + b$ Else b$ = "0" + b$
        j = j + 1
    Wend
    Dec2Bin$ = b$
End Function

The coefficients are converted from decimal to binary and 1's draw green square, 0's stay black and squares stacked from highest power of 2 to 2^0 times 1 or 0 each column is a coefficient on the given row ie (a + b) ^ row

Marvin, Headphones, Janus, L-afant, and Humph!


Attached Files Image(s)
                   
b = b + ...
Reply
#5
Oh, so that's the other use of Pascal's Triangle! Who'd-a-thunk?

Pete Big Grin
Reply




Users browsing this thread: 1 Guest(s)