{"id":20957456,"url":"https://github.com/mrvideo/turing-machine-exercise","last_synced_at":"2026-05-19T11:42:46.434Z","repository":{"id":152358496,"uuid":"477152331","full_name":"MrVideo/turing-machine-exercise","owner":"MrVideo","description":"A small Turing Machine simulator I built to check an exercise","archived":false,"fork":false,"pushed_at":"2022-04-02T20:01:42.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T00:48:31.917Z","etag":null,"topics":["c","turing-machine","turing-machine-simulator"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrVideo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-02T19:29:47.000Z","updated_at":"2023-04-14T23:46:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b845c36-c52c-496b-9e08-6a57ccd4ebfb","html_url":"https://github.com/MrVideo/turing-machine-exercise","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrVideo%2Fturing-machine-exercise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrVideo%2Fturing-machine-exercise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrVideo%2Fturing-machine-exercise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrVideo%2Fturing-machine-exercise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrVideo","download_url":"https://codeload.github.com/MrVideo/turing-machine-exercise/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243352034,"owners_count":20276916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","turing-machine","turing-machine-simulator"],"created_at":"2024-11-19T01:33:42.746Z","updated_at":"2025-12-29T11:33:11.020Z","avatar_url":"https://github.com/MrVideo.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Turing Machine Simulator\n\nThis is a small Turing machine simulator that I programmed to check one of my exercises on the topic.\n\n## What is a Turing Machine?\n\nFrom Wikipedia:\n\u003e A Turing machine is a mathematical model of computation that defines an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, given any computer algorithm, a Turing machine capable of implementing that algorithm's logic can be constructed.\n\nRead more about this [here](https://en.wikipedia.org/wiki/Turing_machine).\n\n## What was the exercise about?\n\nThe exercise asked me to create a Turing machine that checked whether a given string, made from the alphabet composed of the characters *a*, *b* and *c*, contained the same number of *a*'s and *b*'s or the same number of *a*'s and *c*'s.\n\nWhile the authors solved the exercise through a 4-tape Turing machine, I found that a 3-tape Turing machine would be more efficient, and went ahead and solved it through that kind of machine.\n\nTo test my solution, I decided to make this program in C.\n\n## How does the emulation work?\n\nA Turing machine is essentially composed of infinite tapes (in this case, four), and a [Finite-State Automaton](https://en.wikipedia.org/wiki/Finite-state_machine) as the *processing component* of the machine.\n\nI recreated the four tapes, one being the input tape and the other three the memory tapes, through character arrays. For memory usage, I decided to make the tapes 100 character long at most, but there technically is no limit to the length of the tape.\n\nThen I programmed the logic of the FSA with if-else statements and a switch statement: the machine reads the input tape one character at a time and writes one *A* in the first tape for each *a* in the input tape, one *B* in the second tape for each *b* and one *C* in the third tape for each *c*.\n\nOnce the input string ends (which is when the machine reads blank space, in this case represented by the null character `\\0`), the machine stops and reverses the three memory tapes, deleting one symbol from each, until at least one of the tapes returns to the beginning, which is marked by a special symbol: *Z*.\n\nIf all three of the tapes or if the *A* tape and one of the other two tapes return to *Z* at the same time, then the string meets the criteria imposed by the exercise, and the machine accepts it.\n\nThe program uses a `struct` to represent the machine's configuration, which includes the tapes' indexes, the state in which the machine currently is (in my original design, the machine has three states: `q0`, `q1` and `q2`) and whether it will accept the input string or not.\n\n## How do I watch the machine do its work step by step?\n\nTo do that, I used the debugger in VS Code and put breakpoints in the main loops of the program. Just watch the four tapes get updated through the *Variables* window.\n\nI might update this program in the future adding a visualiser for the tapes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrvideo%2Fturing-machine-exercise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrvideo%2Fturing-machine-exercise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrvideo%2Fturing-machine-exercise/lists"}