Advertisement
imk0tter

BrainFuck: Integer Display

Apr 7th, 2011
251
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 10000000 into cell 3
  8. add a plus to the second set of pluses to increase the accuracy by 1 digit
  9. +>>+++++++[<<[>++<-]>[<+++++>-]>-]<<
  10.  
  11. copy data from cell 3 to 4 and 5 then move from 5 to 3
  12. [->+>+<<]>>[<<+>>-]
  13.  
  14. put 1 into cell 7 and point to cell 3
  15. >>+<<<<
  16.                                                                    
  17. [
  18.        point to cell 14 and set cell 14 aka baseflag to 1
  19.        >>>>>>>>>>>[-]+
  20.      
  21.        start position loop
  22.        [
  23.  
  24.                point to cell 1 aka v1{2}
  25.                <<<<<<<<<<<<<
  26.  
  27.                copy v1{2} to cell 9 aka v1c
  28.                [->>>>>>>>+<<<<<<<<]
  29.              
  30.                point to cell 4 aka v2{2}
  31.                >>>  
  32.              
  33.                copy from v2{2} to cell 10 aka v2c
  34.                [->>>>>>+<<<<<<]
  35.              
  36.                copy v2{1} to v2{2} and cell 5 then move from cell 5 to v2{1}
  37.                <[->+>+<<]>>[<<+>>-]
  38.              
  39.                point to cell 9
  40.                >>>>
  41.              
  42.                if v1c is nonzero enter loop
  43.                [
  44.                        if both v1c and v2c are nonzero subtract 1 from v1c and v2c and add 1
  45.                        to cell 12 then move then point to cell 11
  46.                        >[-<->>>+<]
  47.              
  48.                        move the pointer back one cell pointing to cell 9 if cell 10 was nonzero
  49.                        and pointing to cell 8 otherwise              
  50.                        <<
  51.                ]
  52.  
  53.                move the pointer back one cell and look for a 1 signaling that the pointer
  54.                is in cell 7 rather than 8 and if so move it ahead to 8 to resynch            
  55.                <[>]                                                  
  56.                                                              
  57.                move what's left from v1c to v1{2}                                            
  58.                >[-<<<<<<<<+>>>>>>>>]
  59.              
  60.                clear v2c
  61.                >[-]
  62.              
  63.                add 1 to cell 13 aka basebuff which represents the current position tally
  64.                then point to divvbuff
  65.                >>>+<
  66.              
  67.                subtract divbuff from v2{2}
  68.                [-<<<<<<<<->>>>>>>>]
  69.              
  70.                point to divbuff
  71.                <<<<<<<<
  72.              
  73.                if v2{2} isn't empty subtract 1 from basebuff and clear v2{2} and set baseflag to 0
  74.                [[-]>>>>>>>>>->-<<<<<<<<<<]
  75.              
  76.                copy v2{1} to v2{2}                                                          
  77.                <[->+>+<<]>>[<<+>>-]
  78.              
  79.                if base flag is 0 end loop
  80.                >>>>>>>>>
  81.              
  82.                end position loop
  83.        ]
  84.      
  85.        move basebuff to cell 15 aka basebuffr and cell 16 aka basebuffr2
  86.        <[->>+>+<<<]
  87.        
  88.         add 48 to basebuffr and point back to basebuffr
  89.         ++++++[->>++++++++<<]>>
  90.        
  91.         print and clear basebuffr then point to basebuffr2
  92.         .[-]>
  93.        
  94.      
  95.         [
  96.             if cell 16 isn't empty then move to v2{2} and clear it
  97.             -<<<<<<<<<<<<[-]
  98.        
  99.             copy v2{1} to v2{2} and point to v2{2}
  100.             <[->+>+<<]>>[<<+>>-]<
  101.        
  102.             add the contents of v2{2} to cell 17 aka v1neg
  103.             [->>>>>>>>>>>>>+<<<<<<<<<<<<<]
  104.        
  105.             repeat until basebuffr2 is empty
  106.             >>>>>>>>>>>>
  107.            
  108.             end loop and point to cell 17
  109.         ]>
  110.            
  111.        subtract v1neg from v1{1}
  112.        [-<<<<<<<<<<<<<<<<<->>>>>>>>>>>>>>>>>]
  113.      
  114.        clear v1{2}
  115.        <<<<<<<<<<<<<<<<[-]  
  116.      
  117.        copy v1{1} to v1{2}
  118.        <[->+>+<<]>>[<<+>>-]>>
  119.      
  120.        subtract 1 from v2{1}
  121.        <-
  122.      
  123.        if v2{1} isn't empty then start the loop
  124.        [
  125.      
  126.                add 1 back to v2{2} and divide it by 10
  127.                +>[-]<[>>++++++++++[-<<->>]<+<]
  128.        ]
  129.      
  130.        copy v2{1} to v2{2} and point back to v2{1}
  131.        >[->+<<+>]>[-<+>]<<
  132. ]
  133. clear cell 7 and point back to cell 0
  134. >>>>-<<<<<<<
  135.  
  136.  
  137.  
  138.  
  139. [->+>+<<]>>[<<+>>-]>+>>++++++[<<[>++<-]>[<+++++>-]>-]<<[->+>+<<]>>[<<+>>-]>>+<<<<[>>>>>>>>>>>[-]+[<<<<<<<<<<<<<[->>>>>>>>+<<<<<<<<]>>>[->>>>>>+<<<<<<]<[->+>+<<]>>[<<+>>-]>>>>[>[-<->>>+<]<<]<[>]>[-<<<<<<<<+>>>>>>>>]>[-]>>>+<[-<<<<<<<<->>>>>>>>]<<<<<<<<[[-]>>>>>>>>>->-<<<<<<<<<<]<[->+>+<<]>>[<<+>>-]>>>>>>>>>]<[->>+>+<<<]++++++[->>++++++++<<]>>.[-]>[-<<<<<<<<<<<<[-]<[->+>+<<]>>[<<+>>-]<[->>>>>>>>>>>>>+<<<<<<<<<<<<<]>>>>>>>>>>>>]>[-<<<<<<<<<<<<<<<<<->>>>>>>>>>>>>>>>>]<<<<<<<<<<<<<<<<[-]<[->+>+<<]>>[<<+>>-]>><-[+>[-]<[>>++++++++++[-<<->>]<+<]]>[->+<<+>]>[-<+>]<<]>>>>-<<<<<<<
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement