Advertisement
imk0tter

BrainFuck: Integer Display

Apr 6th, 2011
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. push input into cell 0
  2. ,  
  3.            
  4. copy from cell 0 into cell 1 and 2 then move from 2 to 0
  5. [->+>+<<]>>[<<+>>-]>
  6.  
  7. push 10 into cell 3
  8. ++++++++++
  9.  
  10. push 10 into cell 4 and 5
  11. [>++++++++++[>++++++++++
  12.  
  13. push 10 into cell 6 and 7 and multiply giving 100000 in cell 7
  14. [>++++++++++[>++++++++++<-]<-]<-]<-]
  15.  
  16. move data from cell 7 into cell 3
  17. >>>>[<<<<+>>>>-]
  18.  
  19. point to cell 3
  20. <<<<
  21.  
  22. copy data from cell 3 to 4 and 5 then move from 5 to 3 
  23. [->+>+<<]>>[<<+>>-]
  24.  
  25. reserve variable space
  26. >>+>>>>>>>>>>
  27.  
  28. fill cell 20 through 26 with 1s and reserve a 0 at cell 27 for {ref}
  29. >>>+>+>+>+>+>+>+>>
  30.  
  31. push 6 into cell 28 which represents the current power iteration
  32. ++++++
  33.  
  34. start main loop                                    
  35. [
  36.     point to cell 14 and set cell 14 aka baseflag to 1
  37.     <<<<<<<<<<<<<<[-]+
  38.    
  39.     start position loop
  40.     [
  41.  
  42.         point to cell 1 aka v1{2}
  43.         <<<<<<<<<<<<<
  44.  
  45.         copy v1{2} to cell 9 aka v1c
  46.         [->>>>>>>>+<<<<<<<<]
  47.        
  48.         point to cell 4 aka v2{2}
  49.         >>>
  50.        
  51.         copy from v2{2} to cell 10 aka v2c
  52.         [->>>>>>+<<<<<<]
  53.        
  54.         copy v2{1} to v2{2} and cell 5 then move from cell 5 to v2{1}
  55.         <[->+>+<<]>>[<<+>>-]
  56.        
  57.         point to cell 9
  58.         >>>>
  59.        
  60.         if v1c is nonzero enter loop
  61.         [
  62.             if both v1c and v2c are nonzero subtract 1 from v1c and v2c and add 1
  63.             to cell 12 then move then point to cell 11
  64.             >[-<->>>+<]
  65.        
  66.        
  67.             move the pointer back one cell pointing to cell 9 if cell 10 was nonzero
  68.             and pointing to cell 8 otherwise       
  69.             <<
  70.         ]
  71.        
  72.  
  73.         move the pointer back one cell and look for a 1 signaling that the pointer
  74.         is in cell 7 rather than 8 and if so move it ahead to 8 to resynch     
  75.         <[>]                           
  76.                                
  77.         move what's left from v1c to v1{2}                     
  78.         >[-<<<<<<<<+>>>>>>>>]
  79.        
  80.         clear v2c
  81.         >[-]
  82.        
  83.         add 1 to cell 13 aka basebuff which represents the current position tally
  84.         then point to divvbuff
  85.         >>>+<
  86.        
  87.         subtract divbuff from v2{2}
  88.         [-<<<<<<<<->>>>>>>>]
  89.        
  90.         point to divbuff
  91.         <<<<<<<<
  92.        
  93.         if v2{2} isn't empty subtract 1 from basebuff and clear v2{2} and set baseflag to 0
  94.         [[-]>>>>>>>>>->-<<<<<<<<<<]
  95.        
  96.         copy v2{1} to v2{2}                            
  97.         <[->+>+<<]>>[<<+>>-]
  98.        
  99.         if base flag is 0 end loop
  100.         >>>>>>>>>
  101.        
  102.         end position loop
  103.     ]
  104.    
  105.     move basebuff to cell 15 aka basebuffr and cell 16 aka basebuffr2
  106.     <[->>+>+<<<]>>
  107.    
  108.     add 1 to basebuffr
  109.     +
  110.    
  111.    
  112.     [
  113.         subtract 1 from basebuffr and point to cell 26
  114.         ->>>>>>>>>>>
  115.    
  116.         from cell 26 search back to the first empty memory cell which would be
  117.         cell 19 aka r2 on the first iteration and then add 1 to the cell behind it
  118.         being r1 on the first iteration
  119.         [<]<+
  120.    
  121.         move 2 cells ahead of r1 on the first iteration and search ahead to the
  122.         first empty cell which will be cell 27 aka {ref} and then point back to
  123.         cell 15 aka basebuffr
  124.         >>[>]<<<<<<<<<<<<
  125.     ]  
  126.                                        
  127.     point back to cell 26 and search back to find the first empty memory cell
  128.     being r2 on the first iteration and empty the cell infront of it
  129.     >>>>>>>>>>>[<]>[-]
  130.    
  131.     point to the cell ahead of the recently emptied cell and search forward
  132.     for the next empty cell which would be {ref}
  133.     >[>]
  134.    
  135.     point to cell 16 aka basebuffr2
  136.     <<<<<<<<<<<
  137.    
  138.     [
  139.         if cell 16 isn't empty then move to v2{2} and clear it
  140.         -<<<<<<<<<<<<[-]
  141.    
  142.         copy v2{1} to v2{2} and point to v2{2}
  143.         <[->+>+<<]>>[<<+>>-]<
  144.    
  145.         add the contents of v2{2} to cell 17 aka v1neg
  146.         [->>>>>>>>>>>>>+<<<<<<<<<<<<<]
  147.    
  148.         repeat until basebuffr2 is empty
  149.         >>>>>>>>>>>>
  150.        
  151.         end loop and point to cell 17
  152.     ]>
  153.    
  154.     subtract v1neg from v1{1}
  155.     [-<<<<<<<<<<<<<<<<<->>>>>>>>>>>>>>>>>]
  156.    
  157.     clear v1{2}
  158.     <<<<<<<<<<<<<<<<[-]
  159.    
  160.     copy v1{1} to v1{2}
  161.     <[->+>+<<]>>[<<+>>-]>>
  162.    
  163.     subtract 1 from v2{1}
  164.     <-
  165.    
  166.     if v2{1} isn't empty then start the loop
  167.     [
  168.    
  169.         add 1 back to v2{2} and divide it by 10
  170.         +>[-]<[>>++++++++++[-<<->>]<+<]
  171.     ]
  172.    
  173.     copy v2{1} to v2{2}
  174.     >[->+<<+>]>[-<+>]
  175.    
  176.     subtract 1 from cell 28
  177.     >>>>>>>>>>>>>>>>>>>>>>>-
  178. ]
  179.  
  180. point to cell 16 and empty
  181. <<<<<<<<<<<<[-]
  182.  
  183. multiply 6 by 8 into cell 17 and subtract by 1
  184. ++++++[->++++++++<]>-
  185.  
  186. add 47 to r1 through r6
  187. [->+>+>+>+>+>+<<<<<<]
  188.  
  189. print r1 through r6
  190. >.>.>.>.>.>.
  191.  
  192. clear all variables and point back to cell 0
  193. [-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement