-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
669 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.a | ||
*.bak | ||
*.dSYM | ||
*.o | ||
*.sw* | ||
*.test | ||
*~ | ||
/.bin |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule cli
added at
bb9189
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
* The MIT License (MIT). | ||
* | ||
* https://github.com/jonathanmarvens/turing-machine | ||
* | ||
* Copyright (c) 2014 Jonathan Barronville ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
########## | ||
default: build | ||
########## | ||
|
||
build: deps lint test | ||
gox -output=".bin/{{.OS}}-{{.Arch}}/turing-machine" -verbose | ||
|
||
clean: | ||
rm -fr ./.bin | ||
|
||
deps: | ||
godep go install -v -x ./... | ||
|
||
errcheck: | ||
errcheck github.com/jonathanmarvens/turing-machine | ||
|
||
fmt: | ||
gofmt -e -s -w . | ||
|
||
lint: fmt errcheck | ||
|
||
test: lint | ||
# TODO(@jonathanmarvens): Add some damn tests to fix this. | ||
|
||
.PHONY: default | ||
.PHONY: build clean deps errcheck fmt lint test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Turing machinez tho. | ||
|
||
This is a simple turing machine I created for an article I’ve been writing titled, “*Neurons, turing machines, & lambda abstractions: an interesting combo?*” | ||
|
||
## Setup. | ||
|
||
There are 3 ways you can install this on your system in order to play with it. | ||
|
||
----- | ||
|
||
__(1) Download a pre-built binary.__ | ||
|
||
You should be able to grab a pre-built binary on the [__Releases__ page](https://github.com/jonathanmarvens/turing-machine/releases) (oh, the power of Go cross-compiling __:)__ … I’m looking at you, GCC). | ||
|
||
----- | ||
|
||
Assuming you have your [Go workspace](http://golang.org/doc/code.html) all set up, the following are your two other options. | ||
|
||
----- | ||
|
||
__(2) Using `go get`.__ | ||
|
||
```sh | ||
go get -t -u github.com/jonathanmarvens/turing-machine | ||
``` | ||
|
||
----- | ||
|
||
__(3) Building from source.__ | ||
|
||
```sh | ||
go get -t -u github.com/kisielk/errcheck github.com/mitchellh/gox github.com/tools/godep | ||
git clone https://github.com/jonathanmarvens/turing-machine.git $GOPATH/src/github.com/jonathanmarvens/turing-machine | ||
cd $GOPATH/src/github.com/jonathanmarvens/turing-machine | ||
make | ||
``` | ||
|
||
Now look in the __.bin/__ directory. | ||
|
||
----- | ||
|
||
## Usage. | ||
|
||
Running `turing-machine help` should be helpful enough about the usage. | ||
|
||
----- | ||
|
||
Feel free to use the example *programs* in [__examples/__](https://github.com/jonathanmarvens/turing-machine/tree/master/examples). | ||
|
||
```sh | ||
# ./.bin/{OS}-{ARCH}/turing-machine --prog="./examples/n-plus-1.btm.json" | ||
``` | ||
|
||
## Author. | ||
|
||
__Jonathan Barronville__ < [__http://乔纳森.com__](http://乔纳森.com) > ( *[email protected]* ) | ||
|
||
## Acknowledgements. | ||
|
||
Here’s a great document that includes a formal (mathematical) definition of a turing machine (from Cornell University’s CS department): [http://www.cs.cornell.edu/courses/cs4820/2012su/handouts/turingm.pdf](http://www.cs.cornell.edu/courses/cs4820/2012su/handouts/turingm.pdf) … I liked this document more compared to like 6 others I read (the math is clearer and pretty straightforward to follow, there are real examples, the author doesn’t make stupid assumptions about things __-.-__, *et cetera*), so I (loosely) modeled the turing machine around it. You should read it if you want a better mathematical understanding of turing machines! Please don’t rely on Wikipedia for a good understanding of turing machines. | ||
|
||
Here’s a good document, which also includes a formal definition of a turing machine: [http://plato.stanford.edu/entries/turing-machine](http://plato.stanford.edu/entries/turing-machine) … although I didn’t particularly love this document, it’s pretty informative (you probably wanna read it first if you’re new to turing machines). | ||
|
||
## License. | ||
|
||
See [__LICENSE__](https://github.com/jonathanmarvens/turing-machine/blob/master/LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* The MIT License (MIT). | ||
* | ||
* https://github.com/jonathanmarvens/turing-machine | ||
* | ||
* Copyright (c) 2014 Jonathan Barronville ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package error | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
func New(msg string) error { | ||
return errors.New("[github.com/jonathanmarvens/turing-machine]: " + msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{ | ||
"K": [ | ||
"l", "r0", "r1", "s" | ||
], | ||
|
||
"s": "s", | ||
|
||
"Σ": [ | ||
"^", "$", "0", "1" | ||
], | ||
|
||
"x": [ | ||
"^", "0", "1", "0", "1", "1", "1", "0", | ||
"$" | ||
], | ||
|
||
"δ": [ | ||
{ | ||
"map": { | ||
"dir": "R", | ||
"state": "r0", | ||
"sym": "^" | ||
}, | ||
|
||
"state": "s", | ||
"sym": "^" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "R", | ||
"state": "r0", | ||
"sym": "0" | ||
}, | ||
|
||
"state": "r0", | ||
"sym": "0" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "R", | ||
"state": "r1", | ||
"sym": "0" | ||
}, | ||
|
||
"state": "r0", | ||
"sym": "1" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "L", | ||
"state": "l", | ||
"sym": "0" | ||
}, | ||
|
||
"state": "r0", | ||
"sym": "$" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "R", | ||
"state": "r0", | ||
"sym": "1" | ||
}, | ||
|
||
"state": "r1", | ||
"sym": "0" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "R", | ||
"state": "r1", | ||
"sym": "1" | ||
}, | ||
|
||
"state": "r1", | ||
"sym": "1" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "L", | ||
"state": "l", | ||
"sym": "1" | ||
}, | ||
|
||
"state": "r1", | ||
"sym": "$" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "L", | ||
"state": "l", | ||
"sym": "0" | ||
}, | ||
|
||
"state": "l", | ||
"sym": "0" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "L", | ||
"state": "l", | ||
"sym": "1" | ||
}, | ||
|
||
"state": "l", | ||
"sym": "1" | ||
}, | ||
|
||
{ | ||
"map": { | ||
"dir": "N", | ||
"state": "@HALT", | ||
"sym": "^" | ||
}, | ||
|
||
"state": "l", | ||
"sym": "^" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"K": [], | ||
|
||
"s": "", | ||
|
||
"Σ": [], | ||
|
||
"x": [], | ||
|
||
"δ": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* The MIT License (MIT). | ||
* | ||
* https://github.com/jonathanmarvens/turing-machine | ||
* | ||
* Copyright (c) 2014 Jonathan Barronville ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package machine | ||
|
||
type Conf struct { | ||
currState State | ||
currTapePos uint | ||
} | ||
|
||
func (self *Conf) MovTapePosLeft() { | ||
if int(self.currTapePos) == 0 { | ||
return | ||
} | ||
self.currTapePos-- | ||
} | ||
|
||
func (self *Conf) MovTapePosRight() { | ||
self.currTapePos++ | ||
} | ||
|
||
func (self *Conf) SetCurrState(state State) { | ||
self.currState = state | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* The MIT License (MIT). | ||
* | ||
* https://github.com/jonathanmarvens/turing-machine | ||
* | ||
* Copyright (c) 2014 Jonathan Barronville ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package machine | ||
|
||
type Dir string | ||
|
||
const ( | ||
DirMovLeft Dir = "L" | ||
DirMovRight Dir = "R" | ||
DirStay Dir = "N" | ||
) |
Oops, something went wrong.