Skip to content

Instantly share code, notes, and snippets.

@magcks
Last active December 27, 2015 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magcks/7383823 to your computer and use it in GitHub Desktop.
Save magcks/7383823 to your computer and use it in GitHub Desktop.
//////////////////////
// turing: dec to bin
//////////////////////
// Copyright (c) 2013 Max von Buelow
// Copyright (c) 2013 kd3x
// License: CC BY-NC-SA 3.0
// Simulator: http://db.ing.puc.cl/turingmachine/
// Initial state: init
// Accepting state: fin
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Greetings to the course 'FGdI 1'
// at the TU Darmstadt.
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
init,0
init,0,>
init,1
init,1,>
init,2
init,2,>
init,3
init,3,>
init,4
init,4,>
init,5
init,5,>
init,6
init,6,>
init,7
init,7,>
init,8
init,8,>
init,9
init,9,>
init,_
halve,0,<
// Halve and go to addHalf to add the goBack
halve,0
halve,0,<
halve,1
addHalf,0,>
halve,2
halve,1,<
halve,3
addHalf,1,>
halve,4
halve,2,<
halve,5
addHalf,2,>
halve,6
halve,3,<
halve,7
addHalf,3,>
halve,8
halve,4,<
halve,9
addHalf,4,>
// Add 0.5 to the right
addHalf,0
jump,5,<
addHalf,1
jump,6,<
addHalf,2
jump,7,<
addHalf,3
jump,8,<
addHalf,4
jump,9,<
// Jump back
jump,0
halve,0,<
jump,1
halve,1,<
jump,2
halve,2,<
jump,3
halve,3,<
jump,4
halve,4,<
// If we halved successfully, we first remove the zero if there is one and then we go back
halve,_
removezero,_,>
removezero,0
removezero,_,>
removezero,1
goBack,1,>
removezero,2
goBack,2,>
removezero,3
goBack,3,>
removezero,4
goBack,4,>
removezero,5
goBack,5,>
removezero,6
goBack,6,>
removezero,7
goBack,7,>
removezero,8
goBack,8,>
removezero,9
goBack,9,>
// finished
removezero,_
fin,_,>
// normal goBack
goBack,0
goBack,0,>
goBack,1
goBack,1,>
goBack,2
goBack,2,>
goBack,3
goBack,3,>
goBack,4
goBack,4,>
goBack,5
goBack,5,>
goBack,6
goBack,6,>
goBack,7
goBack,7,>
goBack,8
goBack,8,>
goBack,9
goBack,9,>
// rest
goBack,_
rest,_,<
rest,0
rest0,_,>
rest0,_
setrest0,_,>
rest,5
rest1,_,>
rest1,_
setrest1,_,>
setrest0,0
setrest0,0,>
setrest0,1
setrest0,1,>
setrest1,0
setrest1,0,>
setrest1,1
setrest1,1,>
setrest0,_
continue,0,<
setrest1,_
continue,1,<
// continue
continue,0
continue,0,<
continue,1
continue,1,<
continue,_
continue2,_,<
// delimiter
continue2,_
halve,0,<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment