 # Shenzhen I/O: Unknown Optimization Device

Poseidon-779 a Decentralized Autonomous Corporation has decided that we need to help them go into Thorium mining. And while I wont steer off a tangent telling you about Thorium reactors, although they are pretty cool, we should just make this unknown optimization device also known as 2A27.

We get two simple inputs x and y and have to deliver a simple output with a given value. That means we at least have to use 2 micro controllers. So we should not be able to make a solution for less than 6￥.

## Analyzing the solution space

we are given the following solution for the output values given the x and y coordinates. And that can seem a little bit overwhelming considering how many lines of code we have available in 2 MC4000. If we take another look at it we can see that the square in the middle between 40 and 80 on both x and y axis always add 50 to the value given just by the x axis. Which all of a sudden makes the solution a little bit easier. Because that means we can split the problem in two.

The first micro controller should check if we are between 40 and 80 on both x and y axis. And if that is the case output 50, otherwise output 30.

The other microcontroller needs to check if we are between 20 and 60 and in that case output 0 otherwise output 30. Then we need to add the two together and send the result to the output.

## Coding the unknown optimization device

Looking at the rough sketch I outlined before it is clear to me that the first micro controller needs both the x and y input on the simple inputs, and therefore needs to send the output

with the xbus to the second micro controller which will check only the x condition, add the two results and send it via a simple output.

The solutions looks like with the code of the first micro controller being

```  tgt p0 39
+ tlt p0 80
+ tgt p1 39
+ tlt p1 80
+ mov 50 x1
- mov 0 x1
slp 1
```

And the code of the second micro controller being

```  tgt p0 19
+ tlt p0 60
+ mov 0 acc
- mov 30 acc
mov acc p1
slp 1
```

This gives a total
Cost: 6￥
Energy: 715
Lines of code: 14 ### Posted by Kristian Kinay

Second controller could be:
slx x1
mov x1 acc
tlt p0 20
– tgt p0 59
mov acc p1

Cost: 6￥
Energy: 683
Lines of code: 13 Simon

if you start the second controller with an unconditional ‘mov x1 acc’, you can omit the ‘mov 0 acc’ step, as the output of the first controller’s x1 will always correctly be 0 or 50. Here’s the program I wrote:
mov x1 acc
tlt p0 20
– tgt p0 59
mov acc p1
slp 1 Fresh

The second microcontroller code can be simplified resulting in one less line of code and a small power usage improvement:

mov x1 acc
tgt p0 19
+ tlt p0 60
mov acc p1
slp 1

Cost: 6￥
Energy: 690
Lines of code: 13 Jared ynrbode

This is the first puzzle of the game I ran into that I couldn’t figure out on my own.
Initially I tried to have one MCU checking if Y was inside the 50/80 box and send that information over xBus to another MCU, that was programmed to check only for
the value of x and output the expected result. This solution proved too complex for even the MC6000 to handle.
Unfortunately, It did not come to me that “the square in the middle between 40 and 80 on both x and y axis always add 50 to the value given just by the x axis” before reading this post.
Thank you for posting this Kristian, it helped me a lot.