turing-machine 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/turing-machine.rb +51 -0
- metadata +46 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module TuringMechine
|
2
|
+
|
3
|
+
class Tape
|
4
|
+
attr_accessor :head_location, :array, :target
|
5
|
+
attr_reader :head
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
yield self
|
9
|
+
|
10
|
+
@head_location = head_location
|
11
|
+
@array = array
|
12
|
+
@target = target
|
13
|
+
@head = array[head_location]
|
14
|
+
|
15
|
+
if @array == @target
|
16
|
+
puts "Passed!"
|
17
|
+
else
|
18
|
+
puts "Failed!"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def head_left
|
23
|
+
if @head_location -1 < 0
|
24
|
+
array.unshift(nil)
|
25
|
+
else
|
26
|
+
@head_location -= 1
|
27
|
+
end
|
28
|
+
@head = array[@head_location]
|
29
|
+
end
|
30
|
+
|
31
|
+
def head_right
|
32
|
+
@head_location += 1
|
33
|
+
@head = array[@head_location]
|
34
|
+
end
|
35
|
+
|
36
|
+
def change_into(content)
|
37
|
+
@head = array[@head_location] = content
|
38
|
+
end
|
39
|
+
|
40
|
+
def switch(conditon)
|
41
|
+
case @head
|
42
|
+
when conditon
|
43
|
+
yield(@head)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
load "/home/fenprace/Dev/turing-machine/lib/tapespec.rb"
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: turing-machine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Prace Fen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-05 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Play Turing machine.
|
15
|
+
email:
|
16
|
+
- fenprace@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/turing-machine.rb
|
22
|
+
homepage: ''
|
23
|
+
licenses: []
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.24
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Play Turing machine.
|
46
|
+
test_files: []
|