Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Input: a binary number n, for example 1101
- // Ouput: 01101
- //
- // Author: Milan Nedic
- //
- name: Shift bit-string to the right
- init: to_the_right
- accept: qAccept
- to_the_right,0
- to_the_right,0,>
- to_the_right,1
- to_the_right,1,>
- // to_the_right takes me to the first empty position on the right
- to_the_right, _ // empty found? put the placeholder
- blank_found, x, < // and get back one place
- blank_found, x // you are on placeholder?
- to_the_left, x, < // move back one place
- to_the_left, x // move back through all placeholders
- to_the_left, x, <
- to_the_left, 0 // you saw 0 while moving back?
- bring_0, 0, > // bring it forward one place
- bring_0, 0
- bring_0, x, >
- bring_0, x
- to_the_left, 0, <
- // ---------------------
- to_the_left, 1 // you saw 1 while moving back?
- bring_1, 1, > // bring it forward one place
- bring_1, 1
- bring_1, x, >
- bring_1, x
- to_the_left, 1, <
- to_the_left, _ // blank on the way to the left?
- clean_placeholder,_ , > // keep it blank and move right
- clean_placeholder, _ // clean_placeholder initiated
- to_the_right, _, > // keep blank and move right
- to_the_right, x // found placeholder?
- qAccept, 0, - // complete algorithm
- //to_the_right,_
- //qAccept,_,-
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement