• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Improved Sierpinski Triangle

a guest Nov 2nd, 2019 180 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Now with text structuring, comments and a set amount of lines
2.
3.    Input: number of iterations (n)
4.    Output: n rows Sierpinski Triangle
5.    , cell 1 is input (number of iterations)
6.    [ if iterations isn't already 0
7.      >++++++++++ cell 2 is 10 (ascii for new line)
8.      >> start of array  first cell of array entry is 0 for start/end 1 for false or 2 for true  second cell is used for calculations
9.      >++ move into first cell of first array entry and set it to true
10.
11. +++++++++++++++++++++++++++++++.------------------------------- output true as exclamation mark
13.      - reduce iterations by 1
14.      [ do until iterations is 0
15.        >>>> go into first cell of array
16.        [ until end of array
17.          >> look at next entry
18.        ] if end is reached
19.          << go back into array
20.          >>+>>+ expand array by two entries which are both false
21.          <<<< we are about to search each array entry for true and to safe program running time we won't look at values that we already know are false
22.        [ until we reach the empty array entry that marks the beginning of the array
23.          - if the current array entry is false becomes zero so the following loop won't execute
24.          [ if the current cell was true
25.            >>+<< set the array entry that is one entry further to the end of the array to true and return
26.            - set this cell to 0 so that the loop ends
27.          ]
28.          + if the cell was false it becomes false again  if it was true it will now become false as it has been moved one position further to the end
29.          << looks at next entry further to the beginning
30.        ] when the begging of the array is reached
31.        <.> go into the cell where the code for new line is stored print it and go back
32.        >> enter the array again
33.        [ until the end of the array is reached
34.          - if the current array entry is false becomes zero so the following loop won't execute
35.          [ if the current was true
36.            <+> bump calculation cell of previous entry
37.            >>>+<<< bump calculations cell of next entry
38.            - sets current cell to zero to end the loop
39.          ]
40.          + sets truth value from zero to false  the value is lost in the testing process but we won't need it any longer
41.          >> looks into next cell further to the end
42.        ] if end is reached
43.        << enter array again
44.        [ until start is reached
45.          > go into calculation cell of current entry
46.          [ if calculation cell was bumped
47.            - if the calculation cell of current array entry was bumped only once becomes zero so the following loop won't execute
48.            [ if the calculation cell was bumped twice
49.              <-> reduce main cell to 0 so it will become false instead of true
50.              - set calculation cell to 0 to end the loop and to have it reset
51.            ]
52.            <+> set main cell to true if it's 1 and to false if it's 0
53.          ]
54.          < go back into main cell
55.
56.    +++++++++++++++++++++++++++++++.------------------------------- output false as space and true as exclamation mark
57.          << look at next array entry further to start
58.        ] if start is reached
59.        << go into number of iterations cell
60.        - reduce number of iterations by one
61.      ] loop
62.    ] end if
63.
64.
65. Here's the version without comments and structuring
66.
67. `,[>++++++++++>>>+++++++++++++++++++++++++++++++++.------------------------------
68. -<<<<-[>>>>[>>]+>>+<<<<[-[>>+<<-]+<<]<.>>>[-[<+>>>>+<<<-]+>>]<<[>[-[<->-]<+>]<++
69. +++++++++++++++++++++++++++++.-------------------------------<<]<<-]]`
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top