Class: TuringMachine::Tape
- Inherits:
-
Object
- Object
- TuringMachine::Tape
- Defined in:
- lib/turing_machine/tape.rb
Overview
Public: The tape of a Turing machine, combined with the head.
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
-
#head ⇒ Object
def size @symbols.size end.
- #head=(symbol) ⇒ Object
-
#initialize ⇒ Tape
constructor
A new instance of Tape.
- #shift_left ⇒ Object
- #shift_right ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Tape
Returns a new instance of Tape.
6 7 8 9 10 11 |
# File 'lib/turing_machine/tape.rb', line 6 def initialize # @symbols = [ '0' ] # @index = 0 @symbols = Array.new(10) { '0' } @index = 4 end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
13 14 15 |
# File 'lib/turing_machine/tape.rb', line 13 def index @index end |
Instance Method Details
#head ⇒ Object
def size
@symbols.size
end
19 20 21 |
# File 'lib/turing_machine/tape.rb', line 19 def head @symbols[@index] end |
#head=(symbol) ⇒ Object
23 24 25 |
# File 'lib/turing_machine/tape.rb', line 23 def head=(symbol) @symbols[@index] = symbol end |
#shift_left ⇒ Object
27 28 29 |
# File 'lib/turing_machine/tape.rb', line 27 def shift_left @index -= 1 end |
#shift_right ⇒ Object
31 32 33 |
# File 'lib/turing_machine/tape.rb', line 31 def shift_right @index += 1 end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/turing_machine/tape.rb', line 35 def to_s @symbols.join end |