4 ms·
Output from `cr pascal` in GForth: 1 1 1 1 0 1
by kragen 2y ago
Output from `cr pascal` in GForth:
1
1 1
1 0 1
1 1 1 1
1 0 0 0 1
1 1 0 0 1 1
1 0 1 0 1 0 1
1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 1 1
1 0 1 0 0 0 0 0 1 0 1
1 1 1 1 0 0 0 0 1 1 1 1
1 0 0 0 1 0 0 0 1 0 0 0 1
1 1 0 0 1 1 0 0 1 1 0 0 1 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 ok
By changing `4 .r` to `bl + dup dup dup emit emit emit emit` I get this:
!!!!
!!!!!!!!
!!!! !!!!
!!!!!!!!!!!!!!!!
!!!! !!!!
!!!!!!!! !!!!!!!!
!!!! !!!! !!!! !!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! !!!!
!!!!!!!! !!!!!!!!
!!!! !!!! !!!! !!!!
!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!
!!!! !!!! !!!! !!!!
!!!!!!!! !!!!!!!! !!!!!!!! !!!!!!!!
!!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! !!!!
!!!!!!!! !!!!!!!! ok
But this is not using bitwise AND, just the Pascal's triangle approach. (Interestingly, you can reformulate that as a neighborhood-2 2-state 1-dimensional cellular automaton pretty easily; it occurs in a couple of different guises in Wolfram's catalog.)
Here's an ASCII-art version that uses AND as Michał describes:
32 value size : line cr size 0 do dup i and if bl else [char] # then dup emit emit loop drop ;
: pasand size 0 do i line loop ;
Running `pasand` then yields this:
################################################################
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
#### #### #### #### #### #### #### ####
## ## ## ## ## ## ## ##
######## ######## ######## ########
## ## ## ## ## ## ## ##
#### #### #### ####
## ## ## ##
################ ################
## ## ## ## ## ## ## ##
#### #### #### ####
## ## ## ##
######## ########
## ## ## ##
#### ####
## ##
################################
## ## ## ## ## ## ## ##
#### #### #### ####
## ## ## ##
######## ########
## ## ## ##
#### ####
## ##
################
## ## ## ##
#### ####
## ##
########
## ##
####
## ok
- anthk 2y agoStraight from the blog, too, from C to Forth: : sier cr 32 0 do 32 0 do i j and if ." " else ." * " then loop cr loop ; sier Output from eforth/subleq (with do...loop set in the config): * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ok ok
- kragen 2y agoThat looks nicer than my version. But you should put the `cr` before the inner loop, not after it. That way you can remove the `cr` before the outer loop.