Search HoldMyTwist

Browse all posts

Episode 16

One Ticket, One Turn

Duck wants to walk through some toy gate that only knows if it's locked or unlocked. You need a ticket to unlock it.

Episodes

Computing Basics

    Duck is pressing on the (locked) toy turnstile in the monitor. Duck wants to get in.
    Duck tries to move the bar. He can't get through the locked gate.
    Duck holds a fake ticket all pompously, still in the monitor, still on the waiting side of the gate. Robot's watching the scanner.
    Robot displays the cards of state LOCKED and UNLOCKED.
    Duck scans one ticket. "LOCKED" turns to "UNLOCKED". The admissions counter remains at zero.
    The turnstile can be in one of two states: locked or unlocked.
    Duck has a second ticket laying right next to the unlocked gate.
    If you try to put in a ticket while the gate is already unlocked, the gate will remain unlocked and not save another future entry.
    Duck has the 2 old tickets in his hand, standing next to the unlocked gate.
    Robot resets miniature of toy gate to LOCKED with zero admissions. Duck sets up event cards in monitor PUSH,TICKET,TICKET,PUSH,PUSH.
    Robot logs states LOCKED then UNLOCKED.
    Duck goes through gate once, then gate closes behind him.
    Duck makes final PUSH against little locked gate. It does not let anyone in. Robot gives final state LOCKED. Total admissions is one.
    Duck shows new trace TICKET,PUSH,TICKET,PUSH next to reset LOCKED gate. Answer counter is hidden. Robot asks for prediction.
    First ticket, first push means you get one in and the gate is locked.
    Robot shows admissions 2, final state LOCKED.
    Robot compares TICKET at LOCKED leads to UNLOCKED with TICKET at UNLOCKED leads to UNLOCKED. Duck is pointing out that they start from two different places.
    Duck stows his spare ticket deep in the monitor. The locked gate stands ready. Robot takes a bow from outside the screen.

    Episode transcript

    A stubborn gate

    Duck is pressing on the (locked) toy turnstile in the monitor. Duck wants to get in.

    Diagram values: LOCKED

    Duck: I just want to get in

    Duck tries to move the bar. He can't get through the locked gate.

    Diagram values: LOCKED + PUSH → LOCKED; ADMISSIONS 0

    Robot: It's locked to start with. You can't get in by pushing it now.

    Duck holds a fake ticket all pompously, still in the monitor, still on the waiting side of the gate. Robot's watching the scanner.

    Duck: Then I will produce my MOST important ticket.

    Robot displays the cards of state LOCKED and UNLOCKED.

    Diagram values: LOCKED; UNLOCKED

    Robot: Guess what it will remember (before you scan it).

    One stored permission

    Duck scans one ticket. "LOCKED" turns to "UNLOCKED". The admissions counter remains at zero.

    Diagram values: LOCKED + TICKET → UNLOCKED; ADMISSIONS 0

    Duck: It says unlocked. But I gotta push it.

    The turnstile can be in one of two states: locked or unlocked.

    Diagram values: UNLOCKED + PUSH → LOCKED; ADMIT 1

    Robot: If you push the gate while unlocked, you will allow 1 person in and the turnstile will be set back to locked.

    Duck has a second ticket laying right next to the unlocked gate.

    Diagram values: UNLOCKED

    Duck: What if I scan another one? Two turns for a fancy duck?

    If you try to put in a ticket while the gate is already unlocked, the gate will remain unlocked and not save another future entry.

    Diagram values: UNLOCKED + TICKET → UNLOCKED; NO EXTRA CREDIT

    Robot: There is no extra-credit counter on this toy gate.

    Duck has the 2 old tickets in his hand, standing next to the unlocked gate.

    Duck: I have scanned twice.

    Try the whole sequence

    Robot resets miniature of toy gate to LOCKED with zero admissions. Duck sets up event cards in monitor PUSH,TICKET,TICKET,PUSH,PUSH.

    Diagram values: PUSH,TICKET,TICKET,PUSH,PUSH; START LOCKED

    Robot: Start locked again.

    Robot logs states LOCKED then UNLOCKED.

    Diagram values: PUSH → LOCKED; TICKET → UNLOCKED; ADMISSIONS 0

    Duck: If you push the gate while locked, you will allow 0 people in and the turnstile will remain locked.

    Duck goes through gate once, then gate closes behind him.

    Diagram values: TICKET → UNLOCKED; PUSH → LOCKED; ADMISSIONS 1

    Robot: That push admits one and locks the gate

    Duck makes final PUSH against little locked gate. It does not let anyone in. Robot gives final state LOCKED. Total admissions is one.

    Diagram values: PUSH → LOCKED; TOTAL ADMISSIONS 1

    Duck: Locked out again

    The ticket Duck saved

    Duck shows new trace TICKET,PUSH,TICKET,PUSH next to reset LOCKED gate. Answer counter is hidden. Robot asks for prediction.

    Diagram values: START LOCKED; TICKET,PUSH,TICKET,PUSH

    Duck: How many entrances?

    First ticket, first push means you get one in and the gate is locked.

    Diagram values: TICKET → UNLOCKED; PUSH → LOCKED; ADMISSIONS 1

    Robot: A ticket makes the turnstile go from locked to unlocked.

    Robot shows admissions 2, final state LOCKED.

    Diagram values: TICKET → UNLOCKED; PUSH → LOCKED; ADMISSIONS 2

    Duck: Second push lets in another and locks it.

    Robot compares TICKET at LOCKED leads to UNLOCKED with TICKET at UNLOCKED leads to UNLOCKED. Duck is pointing out that they start from two different places.

    Diagram values: LOCKED + TICKET → UNLOCKED; UNLOCKED + TICKET → UNLOCKED

    Robot: It's about the current situation as well as the event.

    Duck stows his spare ticket deep in the monitor. The locked gate stands ready. Robot takes a bow from outside the screen.

    Duck: I'll reserve my 2nd ticket for my 2nd entry.

    The lesson

    Our imaginary turnstile has a state of locked or unlocked. Inserting a ticket will unlock a locked gate. Pushing on an unlocked gate will allow you in and lock it. Pushing on a locked gate will not let you in. Insert a ticket in an unlocked gate and it will remain unlocked but you don't get extra credit. These are the rules for this toy gate.

    Try it

    Diagram values: START UNLOCKED; PUSH,PUSH,TICKET,PUSH

    Start with a gate (like the toy gate) that is not locked. Then do push push ticket push. How many times do you get admitted. What's the final state?

    Answer

    Diagram values: PUSH: ADMIT1, LOCKED; PUSH: ADMIT0, LOCKED; TICKET: UNLOCKED; PUSH: ADMIT1, LOCKED; TOTAL2, FINAL LOCKED

    In the new problem the initial state is unlocked. So the first push will let in Duck and lock the gate. The second push will encounter a locked gate and will not let anyone in. Then Duck scans a ticket. This will unlock the gate. The last push will let Duck in (again). It will lock the gate. Total admissions: 2, final state: locked.

    Sources

    finite-state machine (opens in a new tab)