Skip to content

Functions update #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions src/TuringMachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Output
- `read_cell`::String : value for the current cell being read by the head
"""
function read_tape(tape_right)
read_cell = front(tape_right)
read_cell = first(tape_right)
return read_cell
end

Expand Down Expand Up @@ -134,25 +134,30 @@ Outputs
- `tape_right`::Deque{Int} : updated values for the stack to the right of the head (after writing/movement)
"""
function write_move!(movement, write_cell, tape_left, tape_right)
if isempty(tape_right)
return tape_left, tape_right
# if the tape is empty, don't do anything yet
# if the tape is not empty, pop the first value to be replaced with the value in write_cell
checkme = false
if (!isempty(tape_right))
popfirst!(tape_right)
checkme = true
end
popfirst!(tape_right)
pushfirst!(tape_right, parse(Int, write_cell))
if movement == "<"
if isempty(tape_left)
pushfirst!(tape_right, "_")

# if the next element of the tape to be accessed is to the left, push the write_cell value to the right
# tape and pop the element on the left tape and push it to the right tape

# if the next element of the tape to be accessed is to the right, push write_cell to the left tape

if (movement == "<")
pushfirst!(tape_right, parse(Int, write_cell))

if (isempty(tape_left))
pushfirst!(tape_right, 2)
else
carry = pop!(tape_left)
pushfirst!(tape_right, carry)
end
elseif movement == ">"
if isempty(tape_right)
push!(tape_left, "_")
else
carry = popfirst!(tape_right)
push!(tape_left, carry)
end
push!(tape_left, parse(Int, write_cell))
end
return tape_left, tape_right
end
Expand Down