<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://turingcomplete.wiki/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=BlockOG</id>
	<title>Turing Complete - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://turingcomplete.wiki/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=BlockOG"/>
	<link rel="alternate" type="text/html" href="http://turingcomplete.wiki/wiki/Special:Contributions/BlockOG"/>
	<updated>2026-04-21T01:36:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>http://turingcomplete.wiki/w/index.php?title=K-map&amp;diff=3261</id>
		<title>K-map</title>
		<link rel="alternate" type="text/html" href="http://turingcomplete.wiki/w/index.php?title=K-map&amp;diff=3261"/>
		<updated>2023-11-21T19:21:27Z</updated>

		<summary type="html">&lt;p&gt;BlockOG: A couple typos fixed, and Is capitalized&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{guide|narrow=1}}&lt;br /&gt;
=== What are Karnaugh-Veitch maps? ===&lt;br /&gt;
A Karnaugh-Veitch map is a modified truth table for 4 bits, which allows to derive simplified circuits for this table just by looking at it. So every time you come across a logic, that has 3 or 4 bits of input, you can plug its truth table into a KV map and build the circuit.&lt;br /&gt;
&lt;br /&gt;
=== Okay, so how does it look like? ===&lt;br /&gt;
Usually you start with a truth table with 4 inputs and an output column with values that are either {{Off}} or {{On}}. In this example the output values doesn&#039;t matter (yet), but notice that I gave them numbers from 0 to 15 that matches their corresponding input bit pattern.&lt;br /&gt;
&lt;br /&gt;
[[File:4bit_TruthTable_decimal_output.png]]&lt;br /&gt;
&lt;br /&gt;
A Karnaugh map is a truth table, where each bit combination is represented in 2D form. &lt;br /&gt;
So the outputs are not a straight line like above, but like a square:&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_undefined_output.png]]&lt;br /&gt;
&lt;br /&gt;
As a careful observer, you may have noticed something strange: The input combinations are not numbered 0-1-2-3 (in binary), but &#039;&#039;&#039;0-1-3-2&#039;&#039;&#039;! &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Why though?!&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The answer: We make sure, that &#039;&#039;&#039;only 1 bit changes in each step&#039;&#039;&#039;. So if we would go 0-1-2-3, then the step from 1 to 2 in binary would be 01 to 10. &#039;&#039;&#039;Both&#039;&#039;&#039; bits would change, but we only want 1 bit to change at max. This is why we swap the order of the inputs, but make sure, that we still have all possible combinations available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;BUT WHYYY?!&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
Yes, yes... later...&lt;br /&gt;
&lt;br /&gt;
Changing the order of the input also changes the order in which we fill in the outputs. Going from left to right, skipping the third column and going from top to bottom, skipping the third row. The white numbers are the order in which you plug in the output values.&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_undefined_output_graycode.png]]&lt;br /&gt;
[[File:KMap_decimal_output_graycode.png]]&lt;br /&gt;
&lt;br /&gt;
=== How does this help me in any way? ===&lt;br /&gt;
&#039;&#039;&#039;BLOCKS!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The answer is blocks.&lt;br /&gt;
&lt;br /&gt;
Let me explain...&lt;br /&gt;
&lt;br /&gt;
Humans are very good at visual pattern recognition (if the layout favors it). By using the &#039;&#039;only-1-bit-change&#039;&#039; trick, we can now combine bits in blocks of size 1,2,4 and 8. When forming blocks, we only focus on the {{On}} bits! Leaving the {{Off}} bits alone.&lt;br /&gt;
&lt;br /&gt;
Lets say there are the following 2 green output bits that we are interested in:&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Question is: How can we describe these two bits using the bits from the columns and rows?&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_Example2.png]]&lt;br /&gt;
[[File:KMap_Example3.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Row:&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The bits that we are interested in, are in the row where:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
| [[File:D_boxed.png]] || [[File:C_boxed.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Off.png|24px]] || [[File:On.png|frameless|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Column:&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
The bits that we are interested in, are in the columns where:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
| [[File:A_boxed.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:On.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We don&#039;t need [[File:B_boxed.png]] to describe the two columns, because [[File:A_boxed.png]] = {{On}} already covers both columns.&lt;br /&gt;
&lt;br /&gt;
By putting those together, we can describe the {{On}} bits as &#039;&#039;&#039;2-bit block&#039;&#039;&#039;. The bigger the block, the less inputs we need to describe it! So we want to make the blocks as big as possible. To describe a 2-bit block, we need 3 inputs - the 4th does not matter (also a feature of our &#039;&#039;1-bit-change-only trick&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_Example4.png]]&lt;br /&gt;
&lt;br /&gt;
The block is described by this combined input conditions:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
| [[File:D_boxed.png]] || [[File:C_boxed.png]] || [[File:B_boxed.png]] || [[File:A_boxed.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Off.png|24px]] || [[File:On.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:On.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
So now we can &#039;&#039;&#039;AND&#039;&#039;&#039; everything together and the block is done.&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_circuit_block.png]]&lt;br /&gt;
&lt;br /&gt;
=== Any more block limitations? ===&lt;br /&gt;
&lt;br /&gt;
Only the 1,2,4,8 block size rule.&lt;br /&gt;
&lt;br /&gt;
Additional note: The blocks can also &#039;&#039;&#039;&#039;&#039;go around&#039;&#039;&#039;&#039;&#039; from left to right, and from top to bottom. So for example, you can do an 8-bit block from left to right (using only one input variable to describe it).&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_around.png]]&lt;br /&gt;
&lt;br /&gt;
This block is described only by one input variable&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
| [[File:D_boxed.png]] || [[File:C_boxed.png]] || [[File:B_boxed.png]] || [[File:A_boxed.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Question for you:&#039;&#039;&#039; &#039;&#039;Can you do a block, that covers only the 4 corners?&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== So this is it? ===&lt;br /&gt;
Not quite.&lt;br /&gt;
&lt;br /&gt;
Since we can only do 1,2,4 and 8 bit blocks, we have to combine multiple blocks together, to cover all {{On}} outputs. Each one of them has to be part of a block. Overlapping blocks are no problem, they are actually quite helpful to create big blocks for missing bits.&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
This is our truth table, that we already plugged into our Karnaugh map:&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_Example5.png]]&lt;br /&gt;
&lt;br /&gt;
Now we have to do blocks of 1,2,4 or 8 (as big as possible) to cover all {{On}} output bits.&lt;br /&gt;
&lt;br /&gt;
We can do it like this:&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_Example9.png]]&lt;br /&gt;
&lt;br /&gt;
We need 3 blocks to cover all bits:&lt;br /&gt;
&lt;br /&gt;
#[[File:YellowBox.png|14px]] A yellow 2-bit block&lt;br /&gt;
#[[File:BlueBox.png|14px]] A blue 4-bit block&lt;br /&gt;
#[[File:WhiteBox.png|14px]] A white 4-bit block&lt;br /&gt;
&lt;br /&gt;
Combined they look like this:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
|  || [[File:D_boxed.png]] || [[File:C_boxed.png]] || [[File:B_boxed.png]] || [[File:A_boxed.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:YellowBox.png]] || [[File:Cross_gray.png|24px]] || [[File:On.png|24px]] || [[File:On.png|24px]] || [[File:On.png|24px]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:BlueBox.png]] || [[File:On.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]] || [[File:Cross_gray.png|24px]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:WhiteBox.png]] || [[File:On.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:On.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To build the blocks, we &#039;&#039;&#039;AND&#039;&#039;&#039; the inputs and after that we &#039;&#039;&#039;OR&#039;&#039;&#039; the blocks together&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_circuit_combining_blocks.png|640px]]&lt;br /&gt;
&lt;br /&gt;
And that&#039;s it! We created a circuit that describes the truth table completely!&lt;br /&gt;
&lt;br /&gt;
=== Final notes ===&lt;br /&gt;
The whole idea is based on the fact that a circuit like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
(SuperComplexExpression AND a) OR (SuperComplexExpression AND NOT a)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is the same as just&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
(SuperComplexExpression)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because it doesn&#039;t matter if A is {{On}} or {{Off}} - either the first part of the bracket is passed through, or the second part. So if only one bit changes, then we can remove that bit from the equation. (I was asked about that fact in my exam, so maybe it is good to know).&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can do a Karnaugh map for 3 bits, by throwing away the two rows on the bottom and the D input.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can also do a Karnaugh map for 5 bits, by creating two 4-bit maps. One where the 5th bit is {{Off}} and one where the 5th bit is {{On}}. Then imagine you lay both maps on top of each other, so you can do additional blocks by piercing through both maps.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
The way we collected the bits and put together the blocks is called &#039;&#039;Disjunctive Normal Form (DNF)&#039;&#039; which focuses on the {{On}} output bits, which are then &#039;&#039;&#039;OR&#039;&#039;&#039;d together. There is also a &#039;&#039;Conjunctive Normal Form (CNF)&#039;&#039; where you focus on the {{Off}} bits and then &#039;&#039;&#039;AND&#039;&#039;&#039; the blocks together (a bit more complicated - you have to look it up).&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
If you have two potential blocks of {{On}} bits, but the intersection of those two blocks are {{Off}}, then you can &#039;&#039;&#039;XOR&#039;&#039;&#039; them together instead of &#039;&#039;&#039;OR&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_Example10.png]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
If you have a &#039;&#039;chess board pattern&#039;&#039; in your KV map, you can just XOR all inputs together.&lt;br /&gt;
&lt;br /&gt;
=== Now its your turn! ===&lt;br /&gt;
Here is a task for you:&lt;br /&gt;
&lt;br /&gt;
You get a 4 bit number as input, and you have to display the number in decimal. For this purpose there is the 7-Segment display in the sandbox, which has 7 segments that you can turn on and off.&lt;br /&gt;
&lt;br /&gt;
Fill a Karnaugh map for each segment (Seg1 to Seg7) and build a circuit, so that the correct decimal number is displayed for each binary input number. If you want, you can also display 10 as A, 11 as b etc. up to 15 (hex converter). Otherwise the numbers 10-15 do not matter and can be used to build bigger blocks.&lt;br /&gt;
&lt;br /&gt;
In this picture the input number is a binary 6. Build the circuit in the purple box (the box is way to small, I know), so that for the binary 6 the segments 1,6,7,5,4, and 3 are &#039;&#039;&amp;quot;glowing&amp;quot;&#039;&#039;. (And for the rest of the binary numbers as well from 0 to 9). You need a KV map for each segment. Create the &amp;quot;normal&amp;quot; truth table first, and then fill the map, create blocks and OR them together.&lt;br /&gt;
&lt;br /&gt;
[[File:KMap_Exercise.png|640px]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Happy wiring! Hope you learned something :)&lt;/div&gt;</summary>
		<author><name>BlockOG</name></author>
	</entry>
	<entry>
		<id>http://turingcomplete.wiki/w/index.php?title=State_Machines_-or-_How_to_solve_the_maze_with_2_gates&amp;diff=3260</id>
		<title>State Machines -or- How to solve the maze with 2 gates</title>
		<link rel="alternate" type="text/html" href="http://turingcomplete.wiki/w/index.php?title=State_Machines_-or-_How_to_solve_the_maze_with_2_gates&amp;diff=3260"/>
		<updated>2023-11-21T13:34:33Z</updated>

		<summary type="html">&lt;p&gt;BlockOG: Fixed some typos, non-capitalized Is and... some British English&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{guide|narrow=1}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites: &#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Make sure you completed &#039;&#039;&#039;The Maze&#039;&#039;&#039; level. I also use KV diagrams later on, so you might check out this guide before: &#039;&#039;&#039;[[K-map]]&#039;&#039;&#039;&lt;br /&gt;
== The idea - what is a state machine? ==&lt;br /&gt;
&lt;br /&gt;
Imagine you have to build a circuit to control some kind of device. You don&#039;t have a full computer - only basic gates, and need to come up with a solution, so that your device behave the way you want it to.&lt;br /&gt;
&lt;br /&gt;
The idea is, that we go over all possible things that our device can do step-by-step. We draw a circle for each of those steps and call it a &#039;&#039;&#039;state&#039;&#039;&#039;. Usually every possible output that our device can have has at least one state. We then connect this circles by arrows that have a certain condition assigned to it (called &#039;&#039;&#039;transitions&#039;&#039;&#039;). These conditions are usually a specific configuration of input signals (What shall the device do when certain inputs arrive).&lt;br /&gt;
&lt;br /&gt;
This means something like that:&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;We go from state A to state B, when the condition on the arrow from A to B is met.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:State basic.png]]&lt;br /&gt;
&lt;br /&gt;
By doing so, we can construct a picture where the complete behavior is visible for us and we can understand it easily (= &#039;&#039;&#039;state machine&#039;&#039;&#039;). The cool thing is: There is a completely deterministic way to convert this pictures to circuits by following a few steps, and your device will do exactly what you specified in the picture. It is so straight forward, that you can technically write a program that converts state machines to circuits.&lt;br /&gt;
&lt;br /&gt;
If That&#039;s to easy for you, you can then go and optimize your state machine to get an even better result with super few gates (That&#039;s the fun part).&lt;br /&gt;
&lt;br /&gt;
== Step 1: Draw a simple state machine ==&lt;br /&gt;
We have a perfect example for a level which we can solve using a state machine:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The Maze&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In the level description, we find a hint where the exact behavior is described&lt;br /&gt;
&lt;br /&gt;
 1: Step forward&lt;br /&gt;
 2: Turn left&lt;br /&gt;
 3: Turn right as long as there is a wall ahead&lt;br /&gt;
 4: Press use after each turn (in case the exit is ahead)&lt;br /&gt;
 5: Repeat&lt;br /&gt;
&lt;br /&gt;
This is the behavior we want to implement, but we don&#039;t want to use a computer or any programming. Only basic gates are allowed!&lt;br /&gt;
&lt;br /&gt;
We start with line 1: &amp;lt;code&amp;gt;Step forward&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Step forward.png]]&lt;br /&gt;
&lt;br /&gt;
Simple enough. &lt;br /&gt;
&lt;br /&gt;
Let&#039;s go on with line 2: &amp;lt;code&amp;gt;Turn left&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We always do that after we take a step forward, so &#039;&#039;&#039;always&#039;&#039;&#039; is our condition, that we write on the transition arrow. There is no right and wrong, it only has to make sense for us as humans.&lt;br /&gt;
&lt;br /&gt;
[[File:Turn_left.png]]&lt;br /&gt;
&lt;br /&gt;
Makes sense? &lt;br /&gt;
&lt;br /&gt;
Here comes line 3: &amp;lt;code&amp;gt;Turn right as long as there is a wall ahead&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we have our first &#039;real&#039; condition. As soon as our input tells us &#039;&#039;&amp;quot;There is a wall ahead&amp;quot;&#039;&#039;, we go from &#039;&#039;&#039;Turn left&#039;&#039;&#039; to &#039;&#039;&#039;Turn right&#039;&#039;&#039;, and stay there as long as our input sees a wall.&lt;br /&gt;
&lt;br /&gt;
[[File:Turn right.png]]&lt;br /&gt;
&lt;br /&gt;
Note: In each tick the machine has to use one of the arrows, based on its input values.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s continue: &amp;lt;code&amp;gt;Press use after each turn (in case the exit is ahead)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Basically what this means is: &amp;lt;blockquote&amp;gt;If you see a door after you turned, then use the action command&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So we add an &#039;&#039;Action&#039;&#039; state that we enter, when we see a door, after we turned&lt;br /&gt;
&lt;br /&gt;
[[File:SM Door.png]]&lt;br /&gt;
&lt;br /&gt;
Since the door is the end, we don&#039;t need any arrows going out from there.&lt;br /&gt;
&lt;br /&gt;
Time for the last line: &amp;lt;code&amp;gt;Repeat&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It means, we start over with the first step, if we see a free space. Let&#039;s add that:&lt;br /&gt;
&lt;br /&gt;
[[File:Repeat.png]]&lt;br /&gt;
&lt;br /&gt;
And that&#039;s it! That&#039;s all we need. In each tick, we check the roboters inputs and take the transition that matches that condition. Now we have to convert that into a circuit.&lt;br /&gt;
&lt;br /&gt;
== Step 2: Add Outputs ==&lt;br /&gt;
Since we now know which states there are, we also know which output signals we have to send during a particular state.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take a look at all the output signals, that the robot understands&lt;br /&gt;
&lt;br /&gt;
[[File:Robot out.png]]&lt;br /&gt;
&lt;br /&gt;
In each state, we send one of these signals to the output. E.g. when we are in state &#039;&#039;&#039;Turn Right&#039;&#039;&#039;, then we send the corresponding signal to the output, which is {{Off}}{{On}}{{Off}}.&lt;br /&gt;
&lt;br /&gt;
We can add that information to our graph for each state:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Outputs.png]]&lt;br /&gt;
&lt;br /&gt;
== Step 3: Number the states ==&lt;br /&gt;
Each state needs a unique id (bit pattern), so that we can identify in which state we are currently in. This id is completely arbitrary - we can choose whatever we want, the only thing that matters is, that it is unique for each state.&lt;br /&gt;
&lt;br /&gt;
The easiest (but not necessary the smartest) way to do that is to simply assign a number to each state. By doing so, each state can be referenced using that number.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s do it and add that information to our graph: we have 4 states, so we count from 0 to 3 - and we need 2 bits to represent every number.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Number.png]]&lt;br /&gt;
&lt;br /&gt;
What does this mean for our circuit? &lt;br /&gt;
Somewhere in our circuit there are 2 wires that represent our state number. We can access these wires at any time if we want to know which state is currently active.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;HOLD ON! &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
That also means that we can already start building things! We can access the state wires, and we already plugged in our output signals, that we want to send in a particular state...&lt;br /&gt;
So assuming that the state wires are already there - we can build the part, that sends output signals!&lt;br /&gt;
&lt;br /&gt;
== Step 4: Build the output circuit ==&lt;br /&gt;
Okay, we know that there are 2 wires [[File:Symbol S1.png|20px]][[File:Symbol S0.png|20px]] that provide the number of a state. And if we know the state number, we can determine which of the output bits [[File:Symbol O2.png|20px]][[File:Symbol O1.png|20px]][[File:Symbol O0.png|20px]] has to be {{On}}.&lt;br /&gt;
&lt;br /&gt;
So Let&#039;s start with [[File:Symbol O0.png|20px]] and see in which state it needs to be {{On}}. Look at the graph and write down all state numbers in which this bit is {{On}}.&lt;br /&gt;
&lt;br /&gt;
[[File:SM O0green.png]]&lt;br /&gt;
&lt;br /&gt;
It is {{On}} in only one state, so Let&#039;s write that down:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol O0.png]]&lt;br /&gt;
! StateName &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot; | Step forward || [[File:Off.png|24px]] || [[File:Off.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It&#039;s only one state here, but there could be more in theory - leading to a bigger table.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s continue with [[File:Symbol O1.png|20px]]:&lt;br /&gt;
&lt;br /&gt;
[[File:SM O1green.png]]&lt;br /&gt;
&lt;br /&gt;
Writing down all states where it is {{On}}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol O1.png]]&lt;br /&gt;
! StateName&lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot; | Turn Right || [[File:On.png|24px]] || [[File:Off.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
And finally for [[File:Symbol O2.png|20px]]:&lt;br /&gt;
&lt;br /&gt;
[[File:SM O2green.png]]&lt;br /&gt;
&lt;br /&gt;
Again, there is only one state where the bit is {{On}}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol O2.png]]&lt;br /&gt;
! StateName&lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot; | Action || [[File:On.png|24px]] || [[File:On.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We are almost done - we just have to build our tables now. For each state that we have written down, &#039;&#039;&#039;AND&#039;&#039;&#039; all signals together. If you have more than one state in a table, then &#039;&#039;&#039;OR&#039;&#039;&#039; these ANDs (for each state) together, to get the final signal. (In short: &#039;&#039;&#039;AND&#039;&#039;&#039; the columns for each row, and &#039;&#039;&#039;OR&#039;&#039;&#039; all rows)&lt;br /&gt;
&lt;br /&gt;
Our circuit for all 3 bits [[File:Symbol O2.png|20px]][[File:Symbol O1.png|20px]][[File:Symbol O0.png|20px]] looks like this:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Outputcircuit.JPG]]&lt;br /&gt;
&lt;br /&gt;
Okay great - we build the output. But we need the s-Signals for that... so how do we do that?&lt;br /&gt;
&lt;br /&gt;
== Step 5: Translate the transition conditions ==&lt;br /&gt;
The [[File:Symbol S1.png|20px]][[File:Symbol S0.png|20px]] signals represent our state. So we have to make sure, that the signal on these wires change, whenever we take a transition from one state to another (so they represent the new state).&lt;br /&gt;
&lt;br /&gt;
That means we have to translate the words, that are written on our arrows into bits.&lt;br /&gt;
&lt;br /&gt;
All these words represent some kind of input value, that the roboter sees. So Let&#039;s take a look at all the things that we can find in the maze:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Inputs.png]]&lt;br /&gt;
&lt;br /&gt;
How do these inputs correspond to the words we wrote on our arrows?&lt;br /&gt;
&#039;&#039;Door&#039;&#039; and &#039;&#039;Wall&#039;&#039; are obvious. But what does &#039;&#039;&#039;Free&#039;&#039;&#039; mean?&lt;br /&gt;
&lt;br /&gt;
Well, it means either &#039;&#039;Nothing&#039;&#039; or &#039;&#039;Coin&#039;&#039;, because we can walk over a coin as if its nothing. But that also means that we only have to focus on the first two input bits, because they are both {{Off}}{{Off}} for &#039;&#039;Nothing&#039;&#039; and &#039;&#039;Coin&#039;&#039;, but different for any other input.&lt;br /&gt;
&lt;br /&gt;
That means in the end we have the following conditions, based on the first two input bits [[File:Symbol I1.png|20px]][[File:Symbol I0.png|20px]]:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px;&amp;quot;&lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|&lt;br /&gt;
! style=&amp;quot;text-align: left; padding-left:5px;&amp;quot; | means&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Off.png|24px]] || [[File:Off.png|24px]] || || style=&amp;quot;padding-left:5px;&amp;quot; | Free&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Off.png|24px]] || [[File:On.png|24px]] || || style=&amp;quot;padding-left:5px;&amp;quot; | Wall&lt;br /&gt;
|-&lt;br /&gt;
| [[File:On.png|24px]] || [[File:On.png|24px]] || || style=&amp;quot;padding-left:5px;&amp;quot; | Door&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Symbol Dc.png|24px]] || [[File:Symbol Dc.png|24px]] || || style=&amp;quot;padding-left:5px;&amp;quot; | Always (we don&#039;t care about the value of the input)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Alright, Let&#039;s put that into our graph!&lt;br /&gt;
&lt;br /&gt;
[[File:SM Condition.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There can be multiple conditions on a single arrow (e.g. Door + Wall). You can write that in a little table as we did above (and later you &#039;&#039;&#039;OR&#039;&#039;&#039; all the conditions together)&lt;br /&gt;
&lt;br /&gt;
== Step 6: Build the transition circuit ==&lt;br /&gt;
We now have all the information that we need to build the circuit for our [[File:Symbol S1.png|baseline|20px]][[File:Symbol S0.png|20px]] wires.&lt;br /&gt;
&lt;br /&gt;
We begin with the wire for [[File:Symbol S0.png|20px]]&lt;br /&gt;
&lt;br /&gt;
Here is what we do: &lt;br /&gt;
#We look at all the states where [[File:Symbol S0.png|20px]] is {{On}}&lt;br /&gt;
#We look at all the arrows that go into these states (because these arrows are the reason, that our bit is now {{On}})&lt;br /&gt;
#For all these arrows, we write down from which state they are coming from, and which condition the arrow has&lt;br /&gt;
&lt;br /&gt;
So Let&#039;s see:&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;We have to look at all states where [[File:Symbol S0.png|20px]] is {{On}} and all arrows that lead to this state&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:SM Condition1.png]]&lt;br /&gt;
&lt;br /&gt;
Now Let&#039;s write down all these arrows together with the state where they start&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Origin State &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]] &lt;br /&gt;
! style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Condition&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Step Forward || [[File:Off.png|24px]] || [[File:Off.png|24px]] ||  || [[File:Symbol Dc.png|24px]] || [[File:Symbol Dc.png|24px]] || style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Always&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Turn Left || [[File:Off.png|24px]] || [[File:On.png|24px]] ||  || [[File:On.png|24px]] || [[File:On.png|24px]] || style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Door&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Turn Right || [[File:On.png|24px]] || [[File:Off.png|24px]] ||  || [[File:On.png|24px]] || [[File:On.png|24px]] || style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Door&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Each combination would turn [[File:Symbol S0.png|20px]] to {{On}}.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s interpret what we just wrote down:&lt;br /&gt;
&lt;br /&gt;
The first row says:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;quot;If we were in state &#039;Step Forward&#039; last tick, then whatever is at the input - we will turn the s0 bit on in this tick&amp;quot;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second row says:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;quot;If we were in state &#039;Turn Left&#039; last tick, and our input now sees a door, then we turn the s0 bit on&amp;quot;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The third row says:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;quot;If we were in state &#039;Turn Right&#039; last tick, and our input now sees a door, then we turn the s0 bit on&amp;quot;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the bit [[File:Symbol S0.png|20px]] turns {{On}} if any one of those three statements is true, so we simply &#039;&#039;&#039;OR&#039;&#039;&#039; them together. Like before: &#039;&#039;&#039;AND&#039;&#039;&#039; all columns and &#039;&#039;&#039;OR&#039;&#039;&#039; all rows.&lt;br /&gt;
&lt;br /&gt;
So Let&#039;s build it! (We once again just have to implement the table from above).&lt;br /&gt;
&lt;br /&gt;
[[File:SM ConditionCircuit1.png|650px]]&lt;br /&gt;
&lt;br /&gt;
As a careful observer you may have seen that you can reuse the AND gate that detects the &#039;&#039;door&#039;&#039; - but Let&#039;s continue and optimize later.&lt;br /&gt;
&lt;br /&gt;
Alright, [[File:Symbol S0.png|20px]] is done - Let&#039;s do the same with [[File:Symbol S1.png|20px]]&lt;br /&gt;
&lt;br /&gt;
Same as before: Collect all arrows, that lead to a {{On}} s1-bit&lt;br /&gt;
&lt;br /&gt;
The relevant arrows are the yellow ones:&lt;br /&gt;
&lt;br /&gt;
[[File:Condition2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Let&#039;s write down the table for it&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Origin State &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]] &lt;br /&gt;
! style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Condition&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Turn Left || [[File:Off.png|24px]] || [[File:On.png|24px]] ||  || [[File:Off.png|24px]] || [[File:On.png|24px]] || style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Wall&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Turn Left || [[File:Off.png|24px]] || [[File:On.png|24px]] ||  || [[File:On.png|24px]] || [[File:On.png|24px]] || style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Door&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Turn Right || [[File:On.png|24px]] || [[File:Off.png|24px]] ||  || [[File:Off.png|24px]] || [[File:On.png|24px]] || style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Wall&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;text-align: right; padding-left:8px; padding-right:8px;&amp;quot; | Turn Right || [[File:On.png|24px]] || [[File:Off.png|24px]] ||  || [[File:On.png|24px]] || [[File:On.png|24px]] || style=&amp;quot;padding-left:8px; padding-right:8px;&amp;quot; | Door&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
We already build some of those arrows, but Let&#039;s optimize later and expand our circuit:&lt;br /&gt;
&lt;br /&gt;
[[File:SM ConditionCircuit2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
All the rows in our table have &#039;&#039;&#039;AND&#039;&#039;&#039;s, that are &#039;&#039;&#039;OR&#039;&#039;&#039;d together.&lt;br /&gt;
&lt;br /&gt;
We are almost done! We just need to put it all together.&lt;br /&gt;
&lt;br /&gt;
== Step 7: Put everything together ==&lt;br /&gt;
Now there are two more things left to do. The fist one is kinda obvious:&lt;br /&gt;
&lt;br /&gt;
In the last step we produced our state bits [[File:Symbol S1.png|20px]][[File:Symbol S0.png|20px]] based on the value they had in the tick before. So Let&#039;s make sure, that the signal we produced is available on these wires in the next tick for us to calculate again. We simply have to add a delay line like this:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final1.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Last, but not least: we have to add our output circuit.&lt;br /&gt;
Note: We have to decide if we want to react on our new values immediately, or one tick later (like in saving gracefully). We basically have to decide if we want to pick up the s-Values before the delay line, or after it. Of course our robot has to act in the same tick, as he sees a wall or an opening - so we need to pick up the signals from our current tick (before the delay line).&lt;br /&gt;
&lt;br /&gt;
Just copy paste the output circuit that we build before:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
That&#039;s it - That&#039;s all we need. Go an try it - the robot can now solve the maze!&lt;br /&gt;
&lt;br /&gt;
Now the question is: Where can we get better?&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s get better ==&lt;br /&gt;
It&#039;s time for optimizing our state machine!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; All the things we do here are dependent on the particular state machine that you have in front of you. There a general things that you can look at, but this time, there is no &#039;&#039;&amp;quot;Step1/Step2/Step3-Guide&amp;quot;&#039;&#039; to get to the best solution. So don&#039;t be discouraged if you have an &#039;&#039;&amp;quot;How should I see that?!&amp;quot;&#039;&#039;-moment. This all comes down to practice and getting a feeling for the things you have to look out for.&lt;br /&gt;
&lt;br /&gt;
== Optimizing 1: State numbers ==&lt;br /&gt;
Remember when I stopped you from optimizing redundant wires? Of course you can do that, but if you really want to improve the circuit, we have to start somewhere else: with the numbering of the states.&lt;br /&gt;
&lt;br /&gt;
The number that we assign to each individual state is completely up to us. We can choose whatever we want as long as each state number is unique. This is where we can improve.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take a look at the graph that we had after &#039;&#039;Step 2: Add Outputs&#039;&#039; before we assigned any numbers to the states. Do you see that the output values themselves already produce unique numbers?&lt;br /&gt;
&lt;br /&gt;
[[File:SM Outputs1.png]]&lt;br /&gt;
&lt;br /&gt;
That&#039;s great, because that means, if we assign these numbers to their states, then the state variables are equal to the output signals and we don&#039;t need any logic to translate state signals to output signals - only straight wires from our s-wires to the output!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The fact that our output signals are unique in each state is a special case! If you come across a  state machine where multiple states have the same output, then you still have to give them a unique id - but it&#039;s a good idea to keep the numbers as close to your output signals as possible.&lt;br /&gt;
&lt;br /&gt;
So what does this look like?&lt;br /&gt;
&lt;br /&gt;
[[File:SM Number1.png]]&lt;br /&gt;
&lt;br /&gt;
Now our outputs are equal to our s-wires. The output circuit therefore looks like this:&lt;br /&gt;
&lt;br /&gt;
[[File:SM OutputCircuit1.png]]&lt;br /&gt;
&lt;br /&gt;
Of corse this comes at the cost of adding a new state variable that we didn&#039;t need before, but maybe That&#039;s not so bad. We have to rewire our s-circuit anyways, so Let&#039;s do that and apply more optimizations there.&lt;br /&gt;
&lt;br /&gt;
== Optimizing 2: Simplify your s-circuit ==&lt;br /&gt;
We changed our state codes so now we have to change our s-circuit as well, so that it matches the graph again. Let&#039;s do the same as we did in &#039;&#039;Step 6: Build the transition circuit&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For each bit in our state code, we look at all the states where it is {{On}}, and &#039;&#039;&amp;quot;collect&amp;quot;&#039;&#039; all the arrows (transitions) that led to that state.&lt;br /&gt;
&lt;br /&gt;
But this time, we organize the signals for the arrows in a KV diagram. An arrow is defined by the state in which it emerges (3 bits for the origin state) and by the conditions that are assigned to it (2 bits because each condition is represented by 2 bits). So we need a KV diagram with 3+2=5 variables to represent each possible arrow. A 5-bit KV diagram consists of two 4-bit KV maps in which the 5th bit [[File:Symbol S2.png|20px]] is considered {{Off}} in the first map, and considered {{On}} in the second map.&lt;br /&gt;
&lt;br /&gt;
The raw KV diagram looks like this and it has a place for each possible arrow in the graph. &#039;&#039;&#039;These are not two different KV diagrams!&#039;&#039;&#039; They belong to each other so that we have a spot for each possible combination.&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV.png]]&lt;br /&gt;
&lt;br /&gt;
Let&#039;s begin with our circuit to create the signal [[File:Symbol S0.png|20px]]. Look at all arrows that lead to a state where it is {{On}}.&lt;br /&gt;
&lt;br /&gt;
[[File:SM O0green2.png]]&lt;br /&gt;
&lt;br /&gt;
Now we take all these arrows (where they are coming from, and under what condition) and set it to {{On}} in our KV diagram, because that are exactly the conditions in which our [[File:Symbol S0.png|20px]] should turn {{On}}. All other positions are {{Off}}.&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV2.png]]&lt;br /&gt;
&lt;br /&gt;
The two arrows produce 2 {{On}} bits in our KV diagram, that are right next to each other - creating a 2-bit block. This means that we need 1 bit fewer to describe that block than if we were to describe each arrow individually.&lt;br /&gt;
&lt;br /&gt;
The table that describes this block looks like this (we don&#039;t need [[File:Symbol S1.png|20px]]):&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol S2.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Off.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]] ||  [[File:Off.png|24px]] || [[File:Off.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
And when we build that, it would lead to the following s-circuit:&lt;br /&gt;
&lt;br /&gt;
[[File:SM S circuit.png|650px]]&lt;br /&gt;
&lt;br /&gt;
We could now go ahead and do the same with the two other bits as well, &#039;&#039;&#039;BUT&#039;&#039;&#039; we stop right here, because there are more things that we can do to get even better...&lt;br /&gt;
&lt;br /&gt;
== Optimizing 3: Things that can never happen ==&lt;br /&gt;
When we filled out our KV diagram for [[File:Symbol S0.png|20px]], we turned all the bits that corresponded to an arrow to {{On}} and left every other bit at {{Off}}.&lt;br /&gt;
&lt;br /&gt;
But there are some combinations that can &#039;&#039;&#039;never ever happen!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&#039;&#039;&#039;There is no way that an arrow can start from a state where [[File:Symbol S2.png|20px]] = [[File:On.png|24px]].&#039;&#039;&#039; &lt;br /&gt;
Why? Because when s2 is {{On}}, the only existing state is {{On}}{{Off}}{{Off}}, which is &#039;&#039;&amp;quot;Action&amp;quot;&#039;&#039;. In that state, we are about to open the door and the level is over! We can not use another arrow from that state.&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV3.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;That means, we can ignore the whole second KV map and also [[File:Symbol S2.png|20px]] in all other KV diagrams&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Knowing that, our KV diagram for [[File:Symbol S0.png|20px]] turns into this:&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV dc0.png]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
|  [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]] ||  [[File:Off.png|24px]] || [[File:Off.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
So we got rid of the [[File:Symbol S2.png|20px]] gate - yay! But there is more&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take another look at our state machine:&lt;br /&gt;
&lt;br /&gt;
[[File:SM State.png]]&lt;br /&gt;
&lt;br /&gt;
We can ignore [[File:Symbol S2.png|20px]] and see that there is no state, where [[File:Symbol S1.png|20px]][[File:Symbol S0.png|20px]] is {{On}}{{On}}. But in our KV diagram, there is a whole row for potential arrows, coming out of {{On}}{{On}}, which can never happen (because there is no state for it).&lt;br /&gt;
&lt;br /&gt;
So let&#039;s overwrite that row with a &#039;&#039;&amp;quot;don&#039;t care&amp;quot;&#039;&#039; signal, that we can use to build bigger blocks:&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV dc1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;gt;&amp;gt;Waaait! You said we get bigger blocks, this doesn&#039;t help to get bigger blocks! SCAM!&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Yes, yes - but keep in mind that this also applies for our other 2 bits [[File:Symbol S2.png|20px]] and [[File:Symbol S1.png|20px]], that we haven&#039;t looked at, yet. And also, we are still not done...&lt;br /&gt;
&lt;br /&gt;
Let&#039;s revisit the inputs, that our robot can have:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Inputs.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Nothing&#039;&#039; and &#039;&#039;Coin&#039;&#039; is the same for us (= &#039;&#039;&amp;quot;Free&amp;quot;&#039;&#039;), so we can ignore i3 and i2 - so far so good. But if you look closely, you can see that the input combination [[File:Symbol I1.png|20px]][[File:Symbol I0.png|20px]] = {{On}}{{Off}} also never happens!&lt;br /&gt;
This is a whole column in our KV diagram, that we can ignore! More &#039;&#039;don&#039;t care&#039;&#039; signals for us!&lt;br /&gt;
&lt;br /&gt;
[[File:KV dc2.png]]&lt;br /&gt;
&lt;br /&gt;
Do you see the 4-bit block, that we can build now?&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV dc3.png]]&lt;br /&gt;
&lt;br /&gt;
This block is described by the following table:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]] ||  [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
So we cut off yet another gate - nice!&lt;br /&gt;
&lt;br /&gt;
[[File:SM S circuit1.png|650px]]&lt;br /&gt;
&lt;br /&gt;
== Optimizing 3.5: Interim result ==&lt;br /&gt;
It&#039;s getting better and better! And I think it&#039;s time, that we apply our optimization to our other 2 missing state bits [[File:Symbol S1.png|20px]] and [[File:Symbol S2.png|20px]].&lt;br /&gt;
&lt;br /&gt;
Alright - time for [[File:Symbol S1.png|20px]]! What are the conditions, to turn that bit to {{On}}? Let&#039;s see...&lt;br /&gt;
&lt;br /&gt;
[[File:SM O1green2.png]]&lt;br /&gt;
&lt;br /&gt;
All yellow arrows go directly in our modified KV diagram&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV dc4.png]]&lt;br /&gt;
&lt;br /&gt;
Which leads to the following table&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]] ||  [[File:Off.png|24px]] || [[File:On.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Expanding our circuit...&lt;br /&gt;
&lt;br /&gt;
[[File:SM S circuit2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
And finally the same again for [[File:Symbol S2.png|20px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM O2green2.png]]&lt;br /&gt;
&lt;br /&gt;
Collecting all the arrows again and building blocks:&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV dc5.png]]&lt;br /&gt;
&lt;br /&gt;
Leading to a table...&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S2.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]] ||  [[File:On.png|24px]] || [[File:Cross_gray.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Which again expands our circuit:&lt;br /&gt;
&lt;br /&gt;
[[File:SM S circuit3.png|650px]]&lt;br /&gt;
&lt;br /&gt;
That&#039;s our complete s-circuit for all 3 bits.&lt;br /&gt;
So just for fun - let&#039;s wire that up with our output circuit and see if it still solves our maze:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final3.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Spoiler: It does :)&lt;br /&gt;
&lt;br /&gt;
Do you think it&#039;s time to finally optimize some gates using de&#039;morgans law? Nope! There is still more fancy stuff that we can do!&lt;br /&gt;
&lt;br /&gt;
== Optimizing 4: Things that are allowed to happen ==&lt;br /&gt;
We have 3 KV diagrams now, one for each s-Bit. Each {{On}} bit in one of these diagrams represents an arrow in our graph. All {{Off}} bits represent arrows, that are either not visible or leading to a state, where its corresponding s-Bit is {{Off}}.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s take a look at our three KV diagrams. Note that in each one of them, there is a {{Off}} bit, which, if turned into {{On}}, would allow us to build bigger blocks.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Arrow s0.png]]&lt;br /&gt;
&lt;br /&gt;
Suppose that this bit was {{On}}, what would that mean? It means that there is an arrow in our picture, starting from state {{Off}}{{Off}}{{On}} &#039;&#039;&#039;(Step)&#039;&#039;&#039; and when the condition {{Off}}{{Off}} &#039;&#039;&#039;(Free)&#039;&#039;&#039; is active, it would lead to a state, where [[File:Symbol S0.png|20px]] is {{On}} - so before the change we landed in {{Off}}{{Off}}{{Off}}, and now we turn s0 on, and we would land in {{Off}}{{Off}}{{On}} &#039;&#039;&#039;(Step)&#039;&#039;&#039; again.&lt;br /&gt;
&lt;br /&gt;
So this is the arrow, that we would create, and we now have to interpret, if that is ok for us.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Arrowstate s0.png]]&lt;br /&gt;
&lt;br /&gt;
So is it ok to add this arrow? &lt;br /&gt;
Answer: &#039;&#039;&#039;NO!&#039;&#039;&#039; That would totally ruin our robot behavior, because when we are in state &#039;&#039;&#039;Step&#039;&#039;&#039;, we would take another step if we see nothing and probably pass the door and/or miss intersections.&lt;br /&gt;
&lt;br /&gt;
So we can not turn that bit to {{On}} to get bigger blocks :(&lt;br /&gt;
&lt;br /&gt;
Maybe on [[File:Symbol S1.png|20px]], let&#039;s see...&lt;br /&gt;
&lt;br /&gt;
[[File:SM Arrow s1.png]]&lt;br /&gt;
&lt;br /&gt;
Which arrow does that bit describe?&lt;br /&gt;
We start at &#039;&#039;&#039;Step&#039;&#039;&#039; again, and when we see a &#039;&#039;&#039;Wall&#039;&#039;&#039;, we usually would go to {{Off}}{{Off}}{{Off}} &#039;&#039;&#039;(Turn left)&#039;&#039;&#039;, but this time we turn [[File:Symbol S1.png|20px]] on, so we land in {{Off}}{{On}}{{Off}} &#039;&#039;&#039;(Turn Right)&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Arrowstate s1.png]]&lt;br /&gt;
&lt;br /&gt;
So is it ok to add this arrow?&lt;br /&gt;
Answer: &#039;&#039;&#039;Again NO!&#039;&#039;&#039; The first thing that we have to do after we take a step, is to check our left hand side, or we won&#039;t reach the end. So again nothing to get us bigger blocks :(&lt;br /&gt;
&lt;br /&gt;
But have still one bit left, let&#039;s check out [[File:Symbol S2.png|20px]] &lt;br /&gt;
&lt;br /&gt;
[[File:SM Arrow s2.png]]&lt;br /&gt;
&lt;br /&gt;
So again: Which arrow is that?&lt;br /&gt;
We start in &#039;&#039;&#039;Step&#039;&#039;&#039; yet again, but this time we see a &#039;&#039;&#039;Door&#039;&#039;&#039;. Usually, we would go to {{Off}}{{Off}}{{Off}} &#039;&#039;&#039;(Turn left)&#039;&#039;&#039;, but this time, the arrow turns the [[File:Symbol S2.png|20px]] bit on. So we land in {{On}}{{Off}}{{Off}} &#039;&#039;&#039;(Action)&#039;&#039;&#039;. &lt;br /&gt;
Sounds promising! Let&#039;s take a look at the state machine:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Arrowstate s2.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;YES!&#039;&#039;&#039; That could work! Assume that we just stepped forward and see a door, then it&#039;s totally fine to go to the &#039;&#039;&#039;Action&#039;&#039;&#039; state and open it, finishing the level. &lt;br /&gt;
&lt;br /&gt;
But there is one last thing that we have to take care of, before we can add that arrow: We have to adjust the conditions of the other arrows, because before our change, that condition was part of the &#039;&#039;&#039;&amp;quot;Always&amp;quot;&#039;&#039;&#039; arrow! Taking it away from there also changes the s-circuits for all bits, what would be turned {{On}}, using the &#039;&#039;&#039;&amp;quot;Always&amp;quot;&#039;&#039;&#039; arrow. If it had been {{On}} in their KC diagrams, it would be {{Off}} now, because we took it away. Luckily &#039;&#039;&#039;&amp;quot;Always&amp;quot;&#039;&#039;&#039; leads to {{Off}}{{Off}}{{Off}}, so there is no s-Bit that is affected by our change. But nevertheless, we have to &#039;&#039;&amp;quot;cut out&amp;quot;&#039;&#039; the &#039;&#039;&#039;&amp;quot;Door&amp;quot;&#039;&#039;&#039;-condition from the &#039;&#039;&#039;&amp;quot;Always&amp;quot;&#039;&#039;&#039; arrow. We do that by listing all conditions except &#039;&#039;&#039;&amp;quot;Door&amp;quot;&#039;&#039;&#039; (which is only &#039;&#039;&#039;Wall&#039;&#039;&#039; and &#039;&#039;&#039;Free&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
So a quick adjustment and our state machine looks like this:&lt;br /&gt;
&lt;br /&gt;
[[File:SM State final.png]]&lt;br /&gt;
&lt;br /&gt;
With this change, the interesting bit, that we had in our [[File:Symbol S2.png|20px]] KV diagram turns {{On}} and we can build an 8-bit block:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Arrow s2 final.png]]&lt;br /&gt;
&lt;br /&gt;
Which leads us to an even smaller table:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S2.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] ||  [[File:On.png|24px]] || [[File:Cross_gray.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
So our optimized s-circuit for [[File:Symbol S2.png|20px]] looks like this:&lt;br /&gt;
&lt;br /&gt;
[[File:SM S circuit4.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Slow but steady we are reaching a point where we can&#039;t get any better.&lt;br /&gt;
&lt;br /&gt;
== Optimizing 5: De&#039;Morgan and boolean laws ==&lt;br /&gt;
It&#039;s time to polish our circuit by doing some boolean algebra. We don&#039;t do any high level tricky stuff here - just the application of a few rules, so that we can get rid of the &#039;&#039;&#039;NOT&#039;&#039;&#039; gates in our circuit.&lt;br /&gt;
&lt;br /&gt;
=== De&#039;Morgans Law ===&lt;br /&gt;
De&#039;Morgans law says, that we can turn an &#039;&#039;&#039;AND&#039;&#039;&#039; into an &#039;&#039;&#039;OR&#039;&#039;&#039;, by surrounding it with &#039;&#039;&#039;NOT&#039;&#039;&#039;s and vice versa.&lt;br /&gt;
&lt;br /&gt;
So these two circuits behave exactly the same&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan1.png]]&lt;br /&gt;
&lt;br /&gt;
And so do these&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan2.png]]&lt;br /&gt;
&lt;br /&gt;
Our [[File:Symbol S0.png|20px]] circuit looks almost like a de&#039;morgen circuit:&lt;br /&gt;
&lt;br /&gt;
[[File:SM S circuit4.png|650px]]&lt;br /&gt;
&lt;br /&gt;
So here is what we do: we take the &#039;&#039;&#039;AND&#039;&#039;&#039; there and replace it with an &#039;&#039;&#039;OR&#039;&#039;&#039; as in De&#039;Morgans law.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan3.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Now the double &#039;&#039;&#039;NOT&#039;&#039;&#039;s cancel out, and the remaining &#039;&#039;&#039;OR&#039;&#039;&#039; , followed by a &#039;&#039;&#039;NOT&#039;&#039;&#039; turns into a &#039;&#039;&#039;NOR&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan4.png|650px]]&lt;br /&gt;
&lt;br /&gt;
=== Boolean laws ===&lt;br /&gt;
There are more laws around to simplify circuits, [https://en.wikipedia.org/wiki/Boolean%20algebra &amp;lt;here is the wikipedia page&amp;gt;], if you want a full list (De&#039;morgans laws are in there as well), but the one we need to simplify our [[File:Symbol S1.png|20px]] circuit is the &#039;&#039;&amp;quot;Associativity of AND&amp;quot;&#039;&#039;. Which means, that if you have and &#039;&#039;&#039;AND&#039;&#039;&#039; with more that 2 inputs, then it doesn&#039;t matter in which order you &#039;&#039;&#039;AND&#039;&#039;&#039; first.&lt;br /&gt;
&lt;br /&gt;
So these two circuits are the same:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan5.png]]&lt;br /&gt;
&lt;br /&gt;
Let&#039;s apply that to our circuit, because there, we have 2 &#039;&#039;&#039;AND&#039;&#039;&#039;s chained up. The idea is, to plug both &#039;&#039;&#039;NOT&#039;&#039;&#039;-inputs into the same &#039;&#039;&#039;AND&#039;&#039;&#039;, so that we can apply De&#039;Morgan again.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan6.png|650px]]&lt;br /&gt;
&lt;br /&gt;
With the now reordered &#039;&#039;&#039;AND&#039;&#039;&#039;, we can do the same as we did with s0: De&#039;Morgan the &#039;&#039;&#039;AND&#039;&#039;&#039; into an &#039;&#039;&#039;OR&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan7.png|650px]]&lt;br /&gt;
&lt;br /&gt;
And finally the &#039;&#039;&#039;NOT&#039;&#039;&#039;s cancel out again and the &#039;&#039;&#039;OR&#039;&#039;&#039; followed by a &#039;&#039;&#039;NOT&#039;&#039;&#039; turns into a &#039;&#039;&#039;NOR&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan8.png|650px]]&lt;br /&gt;
&lt;br /&gt;
=== Put everything together and remove dead wires ===&lt;br /&gt;
&lt;br /&gt;
So let&#039;s put everything back together:&lt;br /&gt;
&lt;br /&gt;
[[File:SM_Morgan9.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Looks good, but the wires &#039;&#039;&amp;quot;s2 last_tick&amp;quot;&#039;&#039; and &#039;&#039;&amp;quot;s1 last_tick&amp;quot;&#039;&#039; are not connected to anything! So we can just delete them and get rid of the delay line.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Morgan10.png|650px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;And this is it! That&#039;s our state machine that can&#039;t get any better, with a score of 4/4!&lt;br /&gt;
&lt;br /&gt;
How cool is that :D&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This is the end.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;lt;roll credits&amp;gt;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
... or is it?!&lt;br /&gt;
&lt;br /&gt;
== Optimizing 6: A different solution ==&lt;br /&gt;
There is no way we can get any better for our solution to the algorithm. But let&#039;s go all the way back and read the level description again. Maybe there &#039;&#039;&#039;IS&#039;&#039;&#039; a way to get better.&lt;br /&gt;
&lt;br /&gt;
Here is the description again, and I have subtly highlighted the hint for you:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right hint.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;gt;&amp;gt; You are kidding right?! How&#039;s that gonna change anything - it&#039;s just mirrored! I don&#039;t wanna do everything again :( &amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luckily we don&#039;t have to. We take all the good ideas from before - modify our state machine a little bit, and see how the s-circuits change.&lt;br /&gt;
&lt;br /&gt;
So where did we leave off last time with our state machine?&lt;br /&gt;
&lt;br /&gt;
[[File:SM State final2.png]]&lt;br /&gt;
&lt;br /&gt;
So let&#039;s swap &#039;&#039;Turn left&#039;&#039; and &#039;&#039;Turn right&#039;&#039;. So our robot watches to its right first, then turn left to look for an opening. Everything else stays the same.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right state.png]]&lt;br /&gt;
&lt;br /&gt;
Time to collect arrows again, starting with [[File:Symbol S0.png|20px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right s0.png]]&lt;br /&gt;
&lt;br /&gt;
The KV diagram for [[File:Symbol S0.png|20px]] stays the same, which makes sense, because the left and right state both fed into &#039;&#039;&#039;Step&#039;&#039;&#039; with {{Off}}{{Off}}, so by just flipping them, nothing happens.&lt;br /&gt;
&lt;br /&gt;
[[File:SM KV dc3.png]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol S1.png]]&lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]]&lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]] ||  [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Let&#039;s go on with [[File:Symbol S1.png|20px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right s1.png]]&lt;br /&gt;
&lt;br /&gt;
Notice that the arrow, that goes into &#039;&#039;Turn Right&#039;&#039;, has 2 conditions - we put both in our diagram&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right KV s1.png]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:On.png|24px]] || [[File:Off.png|24px]] || [[File:Cross_gray.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
And for [[File:Symbol S2.png|20px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right s2.png]]&lt;br /&gt;
&lt;br /&gt;
With this KV diagram (again, the same that we had last time, because the conditions stayed the same)&lt;br /&gt;
&lt;br /&gt;
[[File:SM Arrow s2 final.png]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S2.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:On.png|24px]] || [[File:Cross_gray.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
So the only real difference is in in [[File:Symbol S1.png|20px]], where we moved from a 2-bit block to a 4-bit block. It&#039;s something, I guess - let&#039;s build it:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right circuit.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Because [[File:Symbol S0.png|20px]] and [[File:Symbol S2.png|20px]] have the same KV diagram as before, we only have to modify our [[File:Symbol S1.png|20px]] circuit, which cuts off a &#039;&#039;&#039;NOR&#039;&#039;&#039;, but we still need the &#039;&#039;&#039;NOT&#039;&#039;&#039;. This time however, we can&#039;t get rid of the &#039;&#039;&#039;NOT&#039;&#039;&#039; :( De&#039;Morgan is only useful when both inputs have a &#039;&#039;&#039;NOT&#039;&#039;&#039; - not just one. And that means, that this is sill a 4/4 solution, like the one we had before.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;gt;&amp;gt; WAAIT!! I FOUND IT!!! GO BACK TO THE S1 DIAGRAM!&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Okay?! Nice - what did you find? Show me&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;gt;&amp;gt; HAH! I learned something in &amp;quot;Optimizing 4: Things that are allowed to happen&amp;quot;! We can turn that bit to green without breaking our robot and get a 8 bit block&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right KV suggest.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;gt;&amp;gt; Turning that bit to green means, that we go to &amp;quot;Turn right&amp;quot; after a step when we see a door, which is allowed, because we can open the door later, when we turn left again. That&#039;s how it&#039;s described in the algorithm anyways. And I tested it - and it works!&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Good idea - but how does your state machine looks like now, when you add that arrow?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;gt;&amp;gt; Uhm... the bit says that we come from &amp;quot;Step&amp;quot; under the condition &amp;quot;Door&amp;quot;... so like this:&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:SM Right state suggest.png]]&lt;br /&gt;
&lt;br /&gt;
So far so good, but have you also thought about the fact, that the &#039;&#039;&#039;&amp;quot;door&amp;quot;&#039;&#039;&#039; arrow already points to &#039;&#039;&#039;&amp;quot;Action&amp;quot;&#039;&#039;&#039;? And when you take it away from &#039;&#039;&#039;&amp;quot;Action&amp;quot;&#039;&#039;&#039; - it turns its bit to {{Off}} in the &amp;quot;Action&amp;quot; KV diagram? We would lose the 8-bit block there.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;gt;&amp;gt; But it works!&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Yes - you found the right solution! But it doesn&#039;t work for the reason you think it does. The circuit you build no longer matches our state machine, and we have to explain, why it still works. (And hope that in the future no self-destruction action is implemented on output {{On}}{{On}}{{Off}}...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;gt;&amp;gt; What???&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We have to figure out why that works. Let me explain...&lt;br /&gt;
&lt;br /&gt;
== Optimizing 7: Try ideas - but do it properly ==&lt;br /&gt;
Let&#039;s look at the state machine that you came up with and its KV diagrams&lt;br /&gt;
(I have separated the door arrow from the other two conditions)&lt;br /&gt;
&lt;br /&gt;
[[File:SM Contra state.png]]&lt;br /&gt;
&lt;br /&gt;
Here are the KV diagrams&lt;br /&gt;
&lt;br /&gt;
[[File:SM Contra KV origin.pgn.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Nice blocks there - the circuit would definitely be better than ours!&lt;br /&gt;
But now you have a &#039;&#039;&#039;contradiction&#039;&#039;&#039; in your machine. What is the machine supposed to do, when it sees a door? Go to &#039;&#039;&#039;&amp;quot;Action&amp;quot;&#039;&#039;&#039; and open the door, or go to &#039;&#039;&#039;&amp;quot;Turn right&amp;quot;&#039;&#039;&#039;?&lt;br /&gt;
&lt;br /&gt;
Here is the thing: &#039;&#039;&#039;Contradictions&#039;&#039;&#039; are only a thing in our graph. There is no contradiction in the circuit - every step is perfectly described by the equations (and KV diagrams) that we build. The question is: what does the circuit do in this situation? Which state does it prefer?&lt;br /&gt;
&lt;br /&gt;
The state that we land in is determined by the 3 s-Variables for our next state. So let&#039;s see which signals [[File:Symbol S2.png|20px]][[File:Symbol S1.png|20px]][[File:Symbol S0.png|20px]] we get, when we come from &#039;&#039;&#039;&amp;quot;Step: {{Off}}{{On}}&amp;quot;&#039;&#039;&#039; and see &#039;&#039;&#039;&amp;quot;Door: {{On}}{{On}}&amp;quot;&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Contra KV.png|650px]]&lt;br /&gt;
&lt;br /&gt;
This is what each s-Bit would do. We would land in state {{On}}{{On}}{{Off}}, which does not exists! At least not in our graph... yet. &lt;br /&gt;
&lt;br /&gt;
You know what? Let&#039;s go on and see what happens in that state... &lt;br /&gt;
&lt;br /&gt;
So instead of two contradicting arrows, what really happens is that we go in a &#039;&#039;&#039;new mysterious state&#039;&#039;&#039; {{On}}{{On}}{{Off}}.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Contra state2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Okay we may have opened pandoras box here... &lt;br /&gt;
Remember when we build our KV diagrams and said &#039;&#039;&amp;quot;We can ignore s2, because there is no state where an arrow can come out of a state where s2 ={{On}}&amp;quot;&#039;&#039;? &lt;br /&gt;
&lt;br /&gt;
Well, now we have such a state.&lt;br /&gt;
That means our 3 KV diagrams become three-dimensional again, with a second half where [[File:Symbol S1.png|20px]] is {{On}}.&lt;br /&gt;
&lt;br /&gt;
But before we adjust our KV diagrams, let&#039;s quickly analyze what can happen when we are in the &#039;&#039;&#039;Mystery&#039;&#039;&#039; state.&lt;br /&gt;
&lt;br /&gt;
The output, that we send to the robot is {{On}}{{On}}{{Off}} = 6, which does not exist (would be a pity if this was the self-destruct command). So the robot does nothing. But that also means, that the input signals doesn&#039;t change! Hence, we can only see &#039;&#039;&#039;&amp;quot;Door&amp;quot;&#039;&#039;&#039; and nothing else - everything else turns into &#039;&#039;&amp;quot;don&#039;t care&amp;quot;&#039;&#039; in out KV diagrams, since it can never happen!&lt;br /&gt;
&lt;br /&gt;
Let&#039;s apply these findings to our KV diagrams. The only thing we know is, that the combination &#039;&#039;&#039;&amp;quot;Mystery&amp;quot;&#039;&#039;&#039; with condition &#039;&#039;&#039;&amp;quot;Door&amp;quot;&#039;&#039;&#039; is no longer &#039;&#039;&amp;quot;don&#039;t care&amp;quot;&#039;&#039;. Very other bit in the second KV map is still &#039;&#039;&amp;quot;don&#039;t care&amp;quot;&#039;&#039; because they can never happen.&lt;br /&gt;
&lt;br /&gt;
What we DON&#039;T know is the value of these bits, so let&#039;s put a placeholder there.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Mystery kv s2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM Mystery kv s0.png|650px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM Mystery kv s1.png|650px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The value of these bits is determined by our s-circuit = our blocks that we built from the KV diagrams. If a bit is in a block, it turns {{On}}, if it is not in a block it turns {{Off}}. So let&#039;s take the same blocks that we had before and put it back in, because we want to see what the circuit does, without us changing anything (the blocks now extend over both maps combined). This turns our placeholders into fix values, depending on whether they are in a block or not.&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final kv s2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final kv s1.png|650px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final kv s0.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Now the bits are fixed, and we see which state is going to be active, when we come from &#039;&#039;&#039;&amp;quot;Mystery&amp;quot;&#039;&#039;&#039; and see a door:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final target s2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
[[File:Final target s1.png|650px]]&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final target s0.png|650px]]&lt;br /&gt;
&lt;br /&gt;
We would land in [[File:Symbol S2.png|20px]][[File:Symbol S1.png|20px]][[File:Symbol S0.png|20px]] = {{On}}{{Off}}{{Off}} = &#039;&#039;&#039;Action!&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
So our final state machine, that is actually underlying our KV blocks is this:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final state.png|650px]]&lt;br /&gt;
&lt;br /&gt;
When the robot is in &#039;&#039;&#039;&amp;quot;Step&amp;quot;&#039;&#039;&#039; sees a door, we output {{On}}{{On}}{{Off}} first (which fortunately doesn&#039;t break anything), and &#039;&#039;&#039;then&#039;&#039;&#039; go to &#039;&#039;&#039;&amp;quot;Action&amp;quot;&#039;&#039;&#039; and open the door. It works!&lt;br /&gt;
&lt;br /&gt;
Now we just have to finish it!&lt;br /&gt;
&lt;br /&gt;
== The End ==&lt;br /&gt;
So this is our final state machine&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final state.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Which is described by these KV diagrams:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final kv s0.png|650px]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol S2.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Off.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final kv s1.png|650px]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S2.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:On.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final kv s2.png|650px]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;truthtable&amp;quot; style=&amp;quot;border: 2px solid darkgray; padding: 2px&amp;quot;&lt;br /&gt;
! rowspan=&amp;quot;2&amp;quot; style=&amp;quot;width: 30px;&amp;quot; | [[File:Symbol S2.png]] &lt;br /&gt;
| [[File:Symbol S2.png]] &lt;br /&gt;
| [[File:Symbol S1.png]] &lt;br /&gt;
| [[File:Symbol S0.png]] &lt;br /&gt;
| [[File:Symbol I1.png]] &lt;br /&gt;
| [[File:Symbol I0.png]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:Cross_gray.png|24px]] || [[File:On.png|24px]] || [[File:Cross_gray.png|24px]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The only thing left for us to do is to build the circuits described by the tables&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final circuit1.png|650px]]&lt;br /&gt;
&lt;br /&gt;
Or, if you clean it up a little bit:&lt;br /&gt;
&lt;br /&gt;
[[File:SM Final circuit2.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Result:&#039;&#039;&#039; To solve the maze - you need only 2 gates (one of which is a delay line).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Roll credits... again&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== A few final notes ===&lt;br /&gt;
&lt;br /&gt;
You may have noticed that the end of chapter &#039;&#039;&amp;quot;Optimization 6&amp;quot;&#039;&#039; and the whole chapter of &#039;&#039;&amp;quot;Optimization 7&amp;quot;&#039;&#039; was just an expansion of chapter &#039;&#039;&amp;quot;Optimizing 4: Things that are allowed to happen&amp;quot;&#039;&#039; with its only purpose of &#039;&#039;&amp;quot;Is that bit-change ok for us?&amp;quot;&#039;&#039;. So keep in mind that this is not always an easy question to answer.&lt;br /&gt;
&lt;br /&gt;
However, I was very surprised about the amount of stuff and things that happen in this level. My original goal was to go all the way down to the 4/4 solution (end of Chapter &#039;&#039;&amp;quot;Optimizing 5&amp;quot;&#039;&#039;) and leave the 2/2 solution to the reader as an exercise. Well... by doing this &amp;quot;exercise&amp;quot; myself, I simply had to explain it in detail, because this contradiction, that we had with the two door signals is easy to ignore when it solves the level. In reality however, you have to be really careful with that, because this hidden mystery state (that you encounter when you leave the contradiction in place) can trigger something completely unexpected.&lt;br /&gt;
&lt;br /&gt;
Hope that gives you a glimpse on how state machines work. There is a lot more to state machines than presented here. Especially when you want to use this concept in real life, you have to deal with signal synchronization, stability of states and so on.&lt;br /&gt;
&lt;br /&gt;
Feel free to leave a comment and tell me if there are parts, where my explanation isn&#039;t detailed enough, or things that I rushed over, but actually need more pictures etc. Also spelling and grammar mistakes please :)&lt;br /&gt;
&lt;br /&gt;
Well - that&#039;s it! Thanks for reading!&lt;/div&gt;</summary>
		<author><name>BlockOG</name></author>
	</entry>
</feed>