Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Now with text structuring, comments and a set amount of lines
- Input: number of iterations (n)
- Output: n rows Sierpinski Triangle
- , cell 1 is input (number of iterations)
- [ if iterations isn't already 0
- >++++++++++ cell 2 is 10 (ascii for new line)
- >> 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
- >++ move into first cell of first array entry and set it to true
- +++++++++++++++++++++++++++++++.------------------------------- output true as exclamation mark
- <<<< return to number of iterations cell
- - reduce iterations by 1
- [ do until iterations is 0
- >>>> go into first cell of array
- [ until end of array
- >> look at next entry
- ] if end is reached
- << go back into array
- >>+>>+ expand array by two entries which are both false
- <<<< 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
- [ until we reach the empty array entry that marks the beginning of the array
- - if the current array entry is false becomes zero so the following loop won't execute
- [ if the current cell was true
- >>+<< set the array entry that is one entry further to the end of the array to true and return
- - set this cell to 0 so that the loop ends
- ]
- + 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
- << looks at next entry further to the beginning
- ] when the begging of the array is reached
- <.> go into the cell where the code for new line is stored print it and go back
- >> enter the array again
- [ until the end of the array is reached
- - if the current array entry is false becomes zero so the following loop won't execute
- [ if the current was true
- <+> bump calculation cell of previous entry
- >>>+<<< bump calculations cell of next entry
- - sets current cell to zero to end the loop
- ]
- + sets truth value from zero to false the value is lost in the testing process but we won't need it any longer
- >> looks into next cell further to the end
- ] if end is reached
- << enter array again
- [ until start is reached
- > go into calculation cell of current entry
- [ if calculation cell was bumped
- - if the calculation cell of current array entry was bumped only once becomes zero so the following loop won't execute
- [ if the calculation cell was bumped twice
- <-> reduce main cell to 0 so it will become false instead of true
- - set calculation cell to 0 to end the loop and to have it reset
- ]
- <+> set main cell to true if it's 1 and to false if it's 0
- ]
- < go back into main cell
- +++++++++++++++++++++++++++++++.------------------------------- output false as space and true as exclamation mark
- << look at next array entry further to start
- ] if start is reached
- << go into number of iterations cell
- - reduce number of iterations by one
- ] loop
- ] end if
- Here's the version without comments and structuring
- `,[>++++++++++>>>+++++++++++++++++++++++++++++++++.------------------------------
- -<<<<-[>>>>[>>]+>>+<<<<[-[>>+<<-]+<<]<.>>>[-[<+>>>>+<<<-]+>>]<<[>[-[<->-]<+>]<++
- +++++++++++++++++++++++++++++.-------------------------------<<]<<-]]`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement