Skip to content

Instantly share code, notes, and snippets.

@agudulin
Created June 11, 2012 16:31
Show Gist options
  • Save agudulin/2911104 to your computer and use it in GitHub Desktop.
Save agudulin/2911104 to your computer and use it in GitHub Desktop.
Brainfuck: The first experience
*
* * The First BrainFuck Experience
* * ==============================
* * Tried to build house
* * But
********* Stopped at this place
* *
* *
* *
* *
* *
*********
###############################################################
++++++++++ ; c0v/10 ; c0 := width
>>>>>>>>>>>>> ; c13
+++++++++++++ ; c13v/13 ; c13 := ENTER2
>++++++++++ ; c14v/10 ; c14 := ENTER1
<<<<<<<<<<<<<< ; c0
; copy from c0 to c1
[ ; move c0 to c2
>>+ ; c2v/1
<<- ; c0v\1
]
>> ; c2
[ ; move c2 to c1 and c0
<+ ; c1v/1
<+ ; c0v/1
>>- ; c2v\1
]
; end of copy c0 to c1
<+ ; c1v/1 ; c1 = width/1
; divide c1 by 2
[ ; divide c1 by 2 and move it to c2
>+ ; c2v/1
<-- ; c1v\2
]
> ; c2
[ ; move c2 to c1
<+ ; c1v/1
>- ; c2v\1
]
; end of divide c1 by 2
<- ; c1 ; c1 = ((width/1) div 2) \1 := roof_height
; copy from c1 to c2
[ ; move c1 to c3
>>+ ; c3v/1
<<- ; c1v\1
]
>> ; c3
[ ; move c3 to c2 and c1
<+ ; c2v/1
<+ ; c1v/1
>>- ; c3v\1
]
; end of copy c1 to c2
<- ; c2v\1 ; c2 = roof_height\1 := spaces_to_begin
>+ ; c3v1 ; c3 := spaces_after_first_star
>>++++++++ ; c5v8
[<++++>-] ; c4v32 ; c4 := ' '
>+++++++ ; c6v7
[<++++++>-] ; c5v42 ; c5 := '*'
< ; c5
; current cells situation (x == necessary)
######################################################################################
# 0 | 1 | 2 | 3 | 4 | 5 | | 13 | 14 |
# width | roof_height | spaces2begin | spaces_after_star | ' ' | '*' | | ENTER |
# x | x | x | x | x | x | | x |
######################################################################################
<<<< ; c1
; make copy of roof_height
; copy from c1 to c6
[ ; move c1 to c7
>>>>>>+ ; c7v/1
<<<<<<- ; c1v\1
]
>>>>>> ; c7
[ ; move c7 to c6 and c1
<+ ; c6v/1
<<<<<+ ; c1v/1
>>>>>>- ; c7v\1
]
; end of copy c1 to c6
< ; c6 ; c6 := copy of roof_height
; end of making copy of roof_height
; print a star from top of the house
[
<<. ; c4 ; print ' '
>>- ; c6v\1
]
<. ; c5 ; print '*'
; end of print
<<<< ; c1
>>>>>>>>>>>>>.<. ; c13 ; print ENTER
<<<<<<<<<<<< ; c1
; make copy of roof_height
; copy from c1 to c6
[ ; move c1 to c7
>>>>>>+ ; c7v/1
<<<<<<- ; c1v\1
]
>>>>>> ; c7
[ ; move c7 to c6 and c1
<+ ; c6v/1
<<<<<+ ; c1v/1
>>>>>>- ; c7v\1
]
; end of copy c1 to c6
< ; c6 ; c6 := copy of roof_height
; end of making copy of roof_height
; loop: print roof
[
<<<< ; c2
; make copy of spaces_to_begin
; copy from c2 to c7
[ ; move c2 to c8
>>>>>>+ ; c8v/1
<<<<<<- ; c2v\1
]
>>>>>> ; c8
[ ; move c8 to c7 and c2
<+ ; c7v/1
<<<<<+ ; c2v/1
>>>>>>- ; c8v\1
]
; end of copy c2 to c7
< ; c7 ; c7 := copy of spaces_to_begin
; end of making copy of spaces_to_begin
<<<< ; c3
; make copy of spaces_after_first_star
; copy from c3 to c8
[ ; move c3 to c9
>>>>>>+ ; c9v/1
<<<<<<- ; c3v\1
]
>>>>>> ; c9
[ ; move c9 to c8 and c3
<+ ; c8v/1
<<<<<+ ; c3v/1
>>>>>>- ; c9v\1
]
; end of copy c3 to c8
< ; c8 ; c8 := copy of spaces_after_first_star
; end of making copy of spaces_after_first_star
< ; c7
[ ; loop: print spaces
<<<. ; c4 ; print ' '
>>>- ; c7v\1
]
<<. ; c5 ; print '*'
>>> ; c8
[ ; loop: print spaces
<<<<. ; c4 ; print ' '
>>>>- ; c8v\1
]
<<<. ; c5 ; print '*'
<<<- ; c2v\1
>++ ; c3v/2
>>>>>>>>>>>.<. ; c13 ; print ENTER
<<<<<<<- ; c6\1
]
; end of loop of printing roof
; current cells situation (x == necessary)
######################################################################################
# 0 | 1 | 2 | 3 | 4 | 5 | | 13 | 14 |
# width | roof_height | spaces2begin | spaces_after_star | ' ' | '*' | | ENTER |
# x | x | | | x | x | | x |
######################################################################################
<<<<[+] ; c2 = 0
<+ ; c1
[
>++ ; c2v/2
<- ; c1v\1
]
> ; c2
[
<+ ; c1v/1
>- ; c2v\1
]
<- ; c1
[
>>>>. ; c5 ; print '*'
<<<<- ; c1v\1
]
>>>>>>>>>>>>>.<. ; c13 ; print ENTER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment