diff --git a/README.md b/README.md index aae557c..631a8d3 100644 --- a/README.md +++ b/README.md @@ -302,8 +302,8 @@ fn show_head_pos_radio_label( let read_value = current_tape[current_head_pos]; let tape_move_dir = STATE_TABLE.get_tape_mov_dir(current_state, read_value); let updated_head_pos = match tape_move_dir { - TapeMoveDir::Left => current_head_pos + 1, // Tape moves left -> head position moves right. - TapeMoveDir::Right => current_head_pos - 1, + TapeMoveDir::Left => current_head_pos - 1, + TapeMoveDir::Right => current_head_pos + 1, }; let expect_selected = head_pos_idx == updated_head_pos; @@ -321,15 +321,15 @@ fn show_head_pos_radio_label( current_state: usize, ) -> bool { // STATE_TABLE.get_tape_mov_dir(const, const) is a known constant value during the compilation process. - (current_state == 1 && current_tape[current_head_pos] && STATE_TABLE.get_tape_mov_dir(1, true) == TapeMoveDir::Left && head_pos_idx == current_head_pos + 1 && !dest_head_pos[head_pos_idx]) || - (current_state == 1 && current_tape[current_head_pos] && STATE_TABLE.get_tape_mov_dir(1, true) == TapeMoveDir::Right && head_pos_idx == current_head_pos - 1 && !dest_head_pos[head_pos_idx]) || - (current_state == 1 && !current_tape[current_head_pos] && STATE_TABLE.get_tape_mov_dir(1, false) == TapeMoveDir::Left && head_pos_idx == current_head_pos + 1 && !dest_head_pos[head_pos_idx]) || - (current_state == 1 && !current_tape[current_head_pos] && STATE_TABLE.get_tape_mov_dir(1, false) == TapeMoveDir::Right && head_pos_idx == current_head_pos - 1 && !dest_head_pos[head_pos_idx]) + (current_state == 1 && current_tape[current_head_pos] && STATE_TABLE.get_tape_mov_dir(1, true) == TapeMoveDir::Left && head_pos_idx == current_head_pos - 1 && !dest_head_pos[head_pos_idx]) || + (current_state == 1 && current_tape[current_head_pos] && STATE_TABLE.get_tape_mov_dir(1, true) == TapeMoveDir::Right && head_pos_idx == current_head_pos + 1 && !dest_head_pos[head_pos_idx]) || + (current_state == 1 && !current_tape[current_head_pos] && STATE_TABLE.get_tape_mov_dir(1, false) == TapeMoveDir::Left && head_pos_idx == current_head_pos - 1 && !dest_head_pos[head_pos_idx]) || + (current_state == 1 && !current_tape[current_head_pos] && STATE_TABLE.get_tape_mov_dir(1, false) == TapeMoveDir::Right && head_pos_idx == current_head_pos + 1 && !dest_head_pos[head_pos_idx]) // And so on for each possible value of current_state (finite number of states)... } ``` -The second line, assuming `STATE_TABLE.get_tape_mov_dir(1, true)` returns `TapeMoveDir::Right`, can be translated to: +The first line, assuming `STATE_TABLE.get_tape_mov_dir(1, true)` returns `TapeMoveDir::Left`, can be translated to: ```css input#state-1:checked ~ input:not(:checked) + input + label + label + input:checked + input:checked + input + input + label { visibility: visible; diff --git a/src/CompiledMachinePageBody.jsx b/src/CompiledMachinePageBody.jsx index 6da2bec..566daa1 100644 --- a/src/CompiledMachinePageBody.jsx +++ b/src/CompiledMachinePageBody.jsx @@ -303,11 +303,11 @@ function addTapeCellValueLabelStyling(sb, config) { function addHeadPositionLabelStyling(sb, config) { // Rules for head position where destination has mismatch with move instruction: config.forEach((state, stateIdx) => { - const moveLeftIf1 = state[1].move === 'L'; - const moveLeftIf0 = state[0].move === 'L'; - // TODO: if moveLeftIf1 === moveLeftIf0, then we can optimize this to one shorter selector. + const moveRightIf1 = state[1].move === 'R'; + const moveRightIf0 = state[0].move === 'R'; + // TODO: if moveRightIf1 === moveRightIf0, then we can optimize this to one shorter selector. - if (moveLeftIf1) { + if (moveRightIf1) { // Concrete example: current head is at tape cell 0, moving to 1, destination head label is in tape cell 2 group. const displayMoveIf1Mismatch = select(id(BUFFER_SWITCH_ID).unchecked(), '~', id(getInputId(0, STATE_PREFIX, stateIdx)).checked(), '~', checked(), '+', '*', '+', checked(), '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', @@ -323,7 +323,7 @@ function addHeadPositionLabelStyling(sb, config) { .displayBlock(); sb.push(displayMoveIf1Mismatch); } - if (moveLeftIf0) { + if (moveRightIf0) { const displayMoveIf0Mismatch = select(id(BUFFER_SWITCH_ID).unchecked(), '~', id(getInputId(0, STATE_PREFIX, stateIdx)).checked(), '~', checked(), '+', '*', '+', unchecked(), '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', unchecked(), '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', @@ -339,7 +339,7 @@ function addHeadPositionLabelStyling(sb, config) { } // Reverse direction: - if (moveLeftIf1) { + if (moveRightIf1) { const displayMoveIf1Mismatch = select(id(BUFFER_SWITCH_ID).checked(), '~', id(getInputId(1, STATE_PREFIX, stateIdx)).checked(), '~', checked(), '+', '*', '+', checked(), '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', unchecked(), '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', @@ -353,7 +353,7 @@ function addHeadPositionLabelStyling(sb, config) { .displayBlock(); sb.push(displayMoveIf1Mismatch); } - if (moveLeftIf0) { + if (moveRightIf0) { const displayMoveIf0Mismatch = select(id(BUFFER_SWITCH_ID).checked(), '~', id(getInputId(1, STATE_PREFIX, stateIdx)).checked(), '~', checked(), '+', '*', '+', unchecked(), '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', unchecked(), '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', '*', '+', diff --git a/src/TuringMachineForm.jsx b/src/TuringMachineForm.jsx index 95a4c9b..4057748 100644 --- a/src/TuringMachineForm.jsx +++ b/src/TuringMachineForm.jsx @@ -4,8 +4,8 @@ import TuringMachineStateTable from './TuringMachineStateTable.jsx' import ShareableHtmlLink from './ShareableHtmlLink.jsx'; import toHTML from './CompiledMachinePageBody.jsx'; -const DEFAULT_STATE_0 = { name: 'A', 0: { write: '1', move: 'L', next: 'HALT' }, 1: { write: '0', move: 'L', next: 'A' } }; -const DEFAULT_ADD = { 0: { write: '1', move: 'L', next: 'HALT' }, 1: { write: '0', move: 'L', next: 'HALT' } }; +const DEFAULT_STATE_0 = { name: 'A', 0: { write: '1', move: 'L', next: 'HALT' }, 1: { write: '0', move: 'R', next: 'A' } }; +const DEFAULT_ADD = { 0: { write: '1', move: 'L', next: 'HALT' }, 1: { write: '0', move: 'R', next: 'HALT' } }; export default function TuringMachineForm() { const [numTapeCells, setNumTapeCells] = useState("15"); diff --git a/src/TuringMachineStateTable.jsx b/src/TuringMachineStateTable.jsx index a4bf067..2527e48 100644 --- a/src/TuringMachineStateTable.jsx +++ b/src/TuringMachineStateTable.jsx @@ -15,7 +15,7 @@ export default function TuringMachineStateTable({ config, setConfig }) { )} - {config.map((c) => Write symbolMove tapeNext state)} + {config.map((c) => Write symbolMove headNext state)} 0