NandGame – Build a computer from scratch

(nandgame.com)

123 points | by OuterVale a day ago ago

23 comments

  • magicalhippo 19 minutes ago

    Love the game, and it inspired me to get a small FPGA dev board and make my own instruction set and soft-CPU for it. Not very practical, but a fun exercise.

    I got an iCE40 board[1] as the open-source story was decent and price was low. There might be better options now.

    [1]: https://www.digikey.com/en/products/detail/lattice-semicondu...

  • dang 5 hours ago

    Related:

    NandGame – Build a Computer from Scratch - https://news.ycombinator.com/item?id=36862274 - July 2023 (3 comments)

    NandGame – Build a Computer from Scratch - https://news.ycombinator.com/item?id=31055307 - April 2022 (14 comments)

    NandGame – Build a Computer from Scratch - https://news.ycombinator.com/item?id=25282507 - Dec 2020 (136 comments)

    Show HN: Online challenge: Build a CPU from scratch - https://news.ycombinator.com/item?id=17508151 - July 2018 (60 comments)

    • Patrick_Devine 4 hours ago

      Not sure how I missed this those other times, but I have read the book and implemented the computer before. It's a super fun exercise.

  • schoen 2 hours ago

    I did both this and the Nand2Tetris course before realizing that they are implementing the same computer -- this is an interactive graphical version, while the original Nand2Tetris uses a textual HDL where you write down the connections between logic gates as text, instead of clicking and dragging to indicate them.

    I found them both fun and educational, but I thought the NandGame was more fun. But it's good to know about the connections, for example because there are more follow-on exercises that you can do from Nand2Tetris (working with higher layers of computer software) after you complete the NandGame. Or you can just be aware that you can talk about the experience and the substance with people who have done the other version!

  • kelnos 4 hours ago

    Ugh, this just reminded me how far I've fallen. I did EE in college (>20 years ago), specializing in computer architecture. Never did anything with it professionally; I ended up in software. I couldn't remember how to do any of these. I managed to trial-and-error my way to the half-adder, at least.

    • lifeisstillgood 4 hours ago

      I get the reaction but I suggest that your previous work has set you up to make decisions “in the right direction” time and again.

      It’s a bit like saying “darn I can never remember which Prime Minster passed the corn laws or the name of the guy who started refrigerated shipping in the USA.

      The point is if we have a grasp of the essential narrative (something like “wars require engineering, agricultural revolution, Industrial Revolution, history is class warfare” that background acts like a magnetic field for all the new pieces of information, aligning them correctly.

      Anyway, relax, be kinder to yourself.

      • kelnos 3 hours ago

        Thanks for that! I think I wrote that comment a little more negative-sounding than it was in my head. While I do lament skills I've lost and forgotten over the years, I know my EE background came in handy when writing software professionally for embedded and semi-embedded devices, earlier in my career. These days I've moved on to distributed systems, so all that low-level knowledge isn't quite as useful as it once was.

  • AlchemistCamp 2 hours ago

    I played a similar game called Turing Complete and really enjoyed it! https://store.steampowered.com/app/1444480/Turing_Complete/

    It's very similar to the Nand2Tetris book.

    • XorNot 2 hours ago

      Dropped 30 hours into Turing Complete before I realised what was happening to me. Upgraded the machine to 32 bit instructions and wrote documentation of my assembly language for it and everything.

      Fantastic game even in early release!

  • ActorNightly 4 hours ago

    Some food for thought:

    Once you complete this (ignoring the first level where you actually build a NAND gate) you essentially get very much what looks like a Neural Network (since it takes 2 neurons to represent a NAND gate), n layers deep, with a lot of zeros in the weight matrices, and some storage.

    Here is my question: given the input/output semantics at the assembly level, is it possible to train a blank neural network to look like this? Backprop obviously wouldn't work, but perhaps there is some form of directed search one could use?

    • programjames an hour ago

      I tried this with a friend last year (using 3-majority and a variety of other gates). We couldn't get backprop to work past one layer, probably because there isn't enough bit precision. The "train without backprop" issue is actually pretty difficult to accomplish, so we gave up.

      Does anyone have a decent method to train neural networks without backprop? I think the information bottleneck sort-of works, but it's hard to evaluate the mutual information without a neural network.

    • iterance 2 hours ago

      Some of the earliest tests of neural networks decades upon decades ago were done to prove they could be used to model logic gates successfully.

  • michael-online a day ago

    This looks awesome! I never finished working the book and I regret it. Can't wait to try even more of this out.

  • ziofill 5 hours ago

    Very nice! Related: https://turingcomplete.game/

  • ivanbelenky 4 hours ago

    this is awesome, I recommend everyone to also peek into or play MHRD

    https://store.steampowered.com/app/576030/MHRD/

  • insane_dreamer 5 hours ago

    Awesome! Will do this with my child.

  • rahen 2 hours ago

    Does a similar game but with neural networks exist?

  • tonetheman 4 hours ago

    I wish there were more hints.

    I have done this before in another version of this game but for the life of me cannot see how to get to a single output from all of the components I have placed on the screen.

    It does look cool but without more directions or hints I am done for.

    • magicalhippo 43 minutes ago

      > for the life of me cannot see how to get to a single output from all of the components I have placed on the screen

      That should be a clue that you're up the wrong alley. A single output means a single output...

    • kelnos 3 hours ago

      One option might be to search the web for "nand gate using relays". That will give you the answer, which might be a little spoilery, but you can try to puzzle out how it works from the solution.

      I found this[0], which is nice in that it's interactive (you can click the inputs to change their values and see how the current flows), though I think the visuals are a little harder to understand. Would be nicer if it had clearer delineation of the relays, and their inputs and outputs labeled with more than just their voltages.

      [0] https://everycircuit.com/circuit/4954026060021760/relay-base...

    • chrisbrandow 2 hours ago

      yeah, there's something missing in the instructions regarding the first Nand gate. I understand how a NAND Gate is constructed but I can't figure out how to combine the outputs of the two relays in this tool

      • Arnavion 30 minutes ago

        A nand B = not(A and B)

        One of the relays gives you "A and B". The other gives you "A and not B". "A and not B" with A = 1 is just "not B".

      • magicalhippo 42 minutes ago

        The components that are available is usually a hint. Have you used both types?