Computer Science: logic gates problem

15 years after CS 101, I have a “practical” use for the digital logic gates we learned and I about and I have long since forgotten… Redstone circuits in Minecraft.

We have a subway system for transportation that mainly runs in a loop, so each station has only two destinations. The circuitry for this is very simple, as there is only two states. We have an indicator light for the direction the cart will go when it is launched from the station. As the system grows, there will be stations with more than two possible destinations.

The track switching isn’t difficult, but I’m having trouble with the destination signal lights. If I have four possible, destinations, I require two bits of input, with the following combinations:

Each combination will light up one of the destination signal lights.
I have built a Half-adder and attached a NAND gate to the inputs as well.

The NAND gate lights up on 00, the half-adder’s XOR gate lights up on 01 or 10, and the half-adder’s AND gate lights up on 11.

Of course, the problem I have here is no way to differentiate between 01 and 10. XOR is true for both those inputs.
So, what to I do here? An even/odd finite state machine? That might end up taking up too much space. I’d love to hear any suggestions from people who remember their digital logic, and/or minecrafters.

What you need is some constant bits to do some AND masking with.

I don’t know how Minecraft works, but can you make it so that if your XOR gate lights up, you trigger another a circuit that that tries to AND both bits with 01? That circuit will be on for 01, and off for 10.

Would it be overkill to use a demultiplexor?

I don’t know Minecraft – what logic circuits do you have available?

What’s the output supposed to be? Given that, it’s easy to design a circuit using Karnaugh maps or the Quine–McCluskey algorithm.

I’ve never used minecraft, but what you are talking about is your basic address decoder type of circuit. You need two NOT gates and four AND gates.

Output 1 is NOT Input 1 AND NOT input 2
Output 2 is NOT Input 1 AND input 2
Output 3 is Input 1 AND NOT input 2
Output 4 is Input 1 AND input 2

If you need to distinguish each of the four possibilities, you don’t need an XOR, you need two ANDs, each with one input inverted.

It would help if you wrote a truth table for the problem, since I don’t quite get the destination lights. You have four rows on inputs, as you drew - do you also have four outputs? In that case, my solution works.
If you were really doing this, you could find a 2 input four output demux cell.

Take a look at this TI data book page 308 (p. 313 of the pdf.) Warning, fairly large pdf file.

ETA - not fast enough, but I did provide a databook link.

I don’t think you’ll be able to do a lot of logic minimization for this problem.

I think this is the best solution given the limitations of minecraft. There are no built-in gates, but users have come up with implementations of them using the in-game tools. Inverters and AND gates are commonplace, and with space requirements difficult to deal with, a simple solution like this is probably the best one.

Is glitching ever going to be a problem? That is to say, suppose it switches from 00 to 11, but the second input comes up just before the first. The 01 light could flash for a moment.

There are ways to design it so that doesn’t happen, but if it will be a problem, you should make sure to be aware of it.

Good point. People have designed latches in the game, so perhaps the best way is to wait until the signal is stable, latch it, and then work off the stable latched value.

Ah yes, thanks to you and Voyager, both.
Funny how simple it seems now and how I couldn’t for the life of me figure that out last night.

The system will work by setting the destination by flipping switches, then pressing a separate button to launch the minecart. Going from 00 to 11 would turn on the 01 or 10 light briefly, but that isn’t an issue for this application.

Thanks, dopers.

For those interested in Minecraft, there aren’t any logic gates built in, but you can build them out of pieces that function like transistors. With enough space, you can make complex circuitry, such as this 8-bit CPU

Thanks, but I get enough of that at work. :slight_smile:
Just for the education of all, in real life NANDs are often preferred, because they have a very efficient implementation in CMOS. (NORs too.) Of course in real life these days you write Verilog or VHDL code and let Synopsys create the gates for you.