{"id":20930203,"url":"https://github.com/dpbm/turing-machine","last_synced_at":"2026-04-16T05:04:47.769Z","repository":{"id":209207688,"uuid":"722720723","full_name":"Dpbm/turing-machine","owner":"Dpbm","description":"A turing machine automaton based library for studies.","archived":false,"fork":false,"pushed_at":"2023-12-09T20:19:12.000Z","size":917,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-30T12:43:36.225Z","etag":null,"topics":["alan-turing","automaton","bash","computer-science","finite-state-machine","formal-languages","gh-packages","gradle","java","junit","maven","opensuse","ossrh","shell","studies","suse","tests","turing","turing-machine","university"],"latest_commit_sha":null,"homepage":"https://dpbm.github.io/turing-machine/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dpbm.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}},"created_at":"2023-11-23T19:33:24.000Z","updated_at":"2023-11-26T16:45:21.000Z","dependencies_parsed_at":"2023-12-09T21:25:06.461Z","dependency_job_id":"76d0861f-ba81-48b1-b260-563d17b7871f","html_url":"https://github.com/Dpbm/turing-machine","commit_stats":null,"previous_names":["dpbm/turing-machine"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Dpbm/turing-machine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fturing-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fturing-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fturing-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fturing-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dpbm","download_url":"https://codeload.github.com/Dpbm/turing-machine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dpbm%2Fturing-machine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31872036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"online","status_checked_at":"2026-04-16T02:00:06.042Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["alan-turing","automaton","bash","computer-science","finite-state-machine","formal-languages","gh-packages","gradle","java","junit","maven","opensuse","ossrh","shell","studies","suse","tests","turing","turing-machine","university"],"created_at":"2024-11-18T21:29:51.408Z","updated_at":"2026-04-16T05:04:47.753Z","avatar_url":"https://github.com/Dpbm.png","language":"Java","readme":"# Turing Machine\n\nA java library to simulate turing machines using automatons.\n\n![actions workflow](https://github.com/Dpbm/turing-machine/actions/workflows/build_test.yml/badge.svg)\n\n---\n\nThis project is a try to map the idea of turing machines using `OOP` with java.\n\nIn general, turing machines are theoretical machines that can compute a bunch of different things, and actually can execute all computational software in it.\n\nThis idea, was postulated by `Alan Turing`, considered one of the fathers of computer science, in its idea for solving the [Entscheidungsproblem](https://en.wikipedia.org/wiki/Entscheidungsproblem).\n\n[![Alan turing](./assets/turing.jpg)](https://en.wikipedia.org/wiki/Alan_Turing)\n\nA turing machine can, as simple ways, have 2 parts:\n\n- `infinite tape`: responsible for contain all the symbols, which are `commands` for the machine.\n- `reader head`: responsible for read and write in the tape based on the actual instruction.\n\nEvery time that the head pass through a symbol, it reads the symbol, and, based on the instruction for that symbol in that `given state`, it writes another symbol and then the machine moves `left` or `right`, and it goes until the last symbol.\n\nThe common approach to see that, is using images like these ones:\n\n[![tape](./assets/tape.png)](https://en.wikipedia.org/wiki/Turing_machine)\n[![machine](./assets/machine.jpg)](https://en.wikipedia.org/wiki/Turing_machine)\n\nHowever, a more mathematical way is representing it with an automaton.\n\n[![automaton](./assets/automaton.png)](https://en.wikipedia.org/wiki/Turing_machine)\n\nThe elements of this graph are:\n\n- circles: representing the machine states\n- arrows: representing the transitions between each state\n- labels: are the commands for each transition. These commands follow this pattern: (read)/(instruction),(move).\n  - read: is the symbol that we expect to read\n  - instruction: what we do when a symbol is reached, (like `P` for print, or you can see this a symbol to rewrite the tape).\n  - move: the direction that you'll follow in the tape (`LEFT/RIGHT`)\n- two circles: the final state. If your program reach it after passing through all the symbols, your the given input is correct and the program executed successfully.\n\nThe head will read symbol-by-symbol following the label instructions. Case your input has a symbol that for the actual state doesn't have a transition for it, the program `crashes`, so this input is not accepted by that given machine configuration.\n\nfor more details check:\n\n- [Wikipedia](https://en.wikipedia.org/wiki/Turing_machine)\n- [Stanford Encyclopedia of Philosophy](https://plato.stanford.edu/entries/turing-machine/)\n- [brilliant](https://brilliant.org/wiki/turing-machines/)\n\n## Java implementation\n\nFor this project, the idea was to try to abstract all this into classes and objects, then gather all it together in a java-library.\n\nFor that was used:\n\n- [gradle](https://gradle.org/)\n- [junit4](https://junit.org/junit4/)\n- [jdk8](https://www.oracle.com/br/java/technologies/javase/javase8-archive-downloads.html)\n- [kotlin](https://kotlinlang.org/)\n\nCase you want to install it, check the [gradle documentation](https://docs.gradle.org/current/samples/sample_building_java_libraries.html).\n\nFor `ASDF` users, I recommend you check these plugins:\n\n- [java](https://github.com/halcyon/asdf-java)\n- [gradle](https://github.com/rfrancis/asdf-gradle)\n\nFor `opensuse` users, I've left a script to install `java` and setup the `JAVA_HOME`, check it [here](./utils/java.sh).  \n\n### Structure\n\nThe main structure has 3 elements:\n\n- [Transition](./lib/src/main/java/machine/Transition.java)\n- [State](./lib/src/main/java/machine/State.java)\n- [Automaton](./lib/src/main/java/machine/Automaton.java)\n\nThese have the following methods:\n\n---\n\n#### Transition\n\n| method |  arguments | returns |\n|--------|------------|---------|\n|constructor|`char read`, `char write`, `Direction direction`, `State next`|-|\n|getReadSymbol| - | `char` |\n|getAction|-|`Action`|\n\nThe direction type is an enum for `LEFT` and `RIGHT`\n\n```java\nenum Direction {\n    LEFT, RIGHT\n}\n```\n\nto access it just use:\n\n```java\nDirection.LEFT \n\nor\n\nDirection.RIGHT\n```\n\nThe Action is an auxiliar class which keeps track of the metadata for a transition, containing:\n\n```java\nchar write; //symbol to be written\nDirection direction; //the tape direction\nState next; //the next state\nboolean reachedFinal; //if the next state is in the final states set\n```\n\nThe methods of `Action` are:\n\n| method |  arguments | returns |\n|--------|------------|---------|\n|constructor|`char read`, `char write`, `State next`, `boolean reachedFinal`|-|\n|getWrite| - | `char` |\n|getDirection|-|`Direction`|\n|getNext|-|`State`|\n|getReachedFinal|-|`boolean`|\n\n---\n\n#### State\n\n| method |  arguments | returns |throws|\n|--------|------------|---------|------|\n|constructor|`String id`|-|-|\n|constructor|`String id`, `ArrayList\u003cTransition\u003e transitions`|-|-|\n|constructor|`String id`, `ArrayList\u003cTransition\u003e transitions`, `boolean firstState`, `boolean finalState`|-|-|\n|addTransition| `Transition transition` | - |-|\n|setFinal|-|-|-|\n|setFirst|-|-|-|\n|isFinal|-|`boolean`|-|\n|isFirst|-|`boolean`|\n|getId|-|`String`|-|\n|test|`char symbol`|`Action`|`TransitionNotFound`|\n\nThe [TransitionNotFound](./lib/src/main/java/machine/exceptions/TransitionNotFound.java) exception is for transitions that doesn't exist for a given input char.\n\n---\n\n#### Automaton\n\n| method |  arguments | returns |throws|\n|--------|------------|---------|------|\n|constructor|`State[] states`, `String tape`|-|`FirstStateException`, `InvalidTape`|\n|getTape|-|`String`|-|\n|test|-|`boolean`|`TransitionNotFound`|\n\nThe [InvalidTape](./lib/src/main/java/machine/exceptions/InvalidTape.java) exception is raised when the given tape has no symbols into.\n\n---\n\n### Example\n\nthis is an example of a automaton architecture:\n![example](./assets/snippet.png)\n\nrelative automaton:\n\n![automaton](./assets/example.svg)\n\nNote that the `\u0026` marks the start of the tape and the `n` in the code is the same as $\\epsilon$ (empty space) in the diagram.\n\nThis example searches for sequences as:\n\n```plaintext\naaabbb\naabb\nab\n```\n\nand the input tapes looks like:\n\n```plaintext\n# code\n\u0026aabbn\n\n# automaton\n\u0026aabbϵ\n```\n\n[`Note: There's an example code in /lib/src/test/examples/App.java check it out`](./lib/src/test/examples/App.java)\n\n## Installation\n\nTo install the `machine` library, follow the instruction at [github packages](https://github.com/Dpbm/turing-machine/packages/1996975), you may need [maven](https://maven.apache.org/) for that.\n\nYou can also install maven as an `ASDF` plugin:\n\n- [maven](https://github.com/Proemion/asdf-maven)\n\n## Testing\n\nAfter [installing gradle](https://docs.gradle.org/current/userguide/installation.html) and cloning this repo, you can run the tests by doing:\n\n```bash\n./gradlew test\n```\n\n## Build\n\nYou can also build the project by your own, using:\n\n```bash\n./gradlew build\n```\n\n## Publishing\n\nTo publish this package to a github package, you need to add a `classic token` to you account, and grant the access to read and write packages, to do that take a look at: [github article](https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-gradle).\n\nAfter that, export the `GH_USERNAME` and the `GH_TOKEN` to your environment variables, like:\n\n```bash\nexport GH_USERNAME=\"username\"\nexport GH_TOKEN=\"gh_token\"\n```\n\nAlso, you'll need a `GPG` key to sign the package, follow [the official instructions](https://docs.gradle.org/current/userguide/signing_plugin.html) to ensure that.\n\nThen, run the `gradle publish` to publish to gh packages.\n\n```bash\n./gradlew publish\n```\n\nalternatively, you can pass the variables along with the `gradlew` command:\n\n```bash\nGH_USERNAME=\"username\" GH_TOKEN=\"gh_token\" ./gradlew publish\n```\n\n## Contributing\n\nIf you want to help this project, feel free to create an issue, make some PRs and text with some other contributors at this repo.\nFix some bugs, add features, fix typos and etc.\n\n*Remember to be kind with everyone!*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpbm%2Fturing-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpbm%2Fturing-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpbm%2Fturing-machine/lists"}