Hacker News new | past | comments | ask | show | jobs | submit login
Making a virtual machine in Google Sheets (briansteffens.github.io)
1074 points by signa11 on July 5, 2017 | hide | past | favorite | 113 comments

This may sound silly, but I don't think I've actually seen a more elegant functional visualization of how computers work at that level. I could see this being used as an educational aid to introduce students to the key concepts.

My professors at the University of Virginia made this one: The IBCM == Itty Bitty Computing Machine https://aaronbloomfield.github.io/pdr/book/ibcm-chapter.pdf

If you like this you might also like the games "Human Resource Machine" and "TIS-100", which both give a similarly visual insight into how computers work.

Links below. Worth noting that both of these are included in the Steam Summer Sale which ends in a couple hours.



In case anyone missed the Steam Summer Sale, these (as well as Shenzhen I/O) are also on sale at Humble Bundle for the next 4 days.



Also, SHENZHEN I/O, from the author of TIS100:


HRM looks fun. Bought it. TIS100 notsomuch to me. I can see the appeal for some thou.

I'd only recommend HRM for people who haven't touched assembly before. For those that have, it is a bit of a waste of time and not very challenging...I kept hoping the problems would be harder, and maybe something that you wouldn't do in an introductory college course.

TIS and Shenzhen I/O on the other hand have unique challenges and are well worth your time investment for help thinking outside of the box. Many different ways to solve the problems, unlike HRM where there is basically one obvious speed and one obvious size solution.

On the contrary, I teach x86 assembly to advanced audiences and I still haven't solved some of the harder optimization problems there. It was so much fun!

Maybe I gave up on the game too early. The difficulty was not ramping up fast enough for me. I might take your advice and reinstall it and continue where I left off.

I thought HRM had a very odd skill curve, started out very easy and then got difficult quickly. I think overall it's too hard for somebody who isn't a programmer, and there aren't enough hard problems for a programmer. And once the problems got hard, it seemed more like work and less like fun. And a lot of it seemed like busy work since there were so few instructions.

Excellent point...I think that is what was happening...I must have gotten to the "hard" zone as you describe, and simply got bored of work, but wasn't challenged (which is what I want from a game).

I've never been able to articulate why I gave up on this game when I did, and your comment finally put it into words. Spot on observation, thanks!

I don't really know assembly (other than a little RISC) and I breezed through HRM, but I still had a lot of fun with it. There's some real charm and humour wrapped around its programming puzzles, unlike most games of its ilk.

The main game is only half the story though, fully optimising the later levels and especially the optional challenge levels is not trivial!

+1 for assembly

I'd love to see more assembly-like games. I've hear about Core War, well so far there are no new exciting progress.

HRM Pro-tip -- You can cut & paste your programs.

I've played both and I like HRM better myself.

My son and I went through this excellent interactive 6502 tutorial after completing HRM: https://skilldrick.github.io/easy6502/

Thank you for sharing that link, I've been looking for resources for gently improving my ASM skills and this looks perfect!

I enjoy TIS-100/Infinifactory/Shenzhen IO. Nevertheless, I don't think any of those games represent all the key elements quite as explicitly, like the stack pointer and how the stack and heap build up. In terms of games with that level of detail, the only one that comes to mind for me is https://microcorruption.com/ which displays exactly what's in every register and in memory at all times. But I think playing it requires a little familiarity in advance.

In fact, all Zachtronics games are awesome and programming/logic inspired. If you use steam, I would highly recommend getting the bundle that is currently on sale: http://store.steampowered.com/bundle/2925/The_Zachtronics_Pu...

My favorite of all of them is SHENZEN I/O though, as it's a bit simpler than TIS-100 but more programming focused than both Infinifactory and SpaceChem. All of them are fun though.

For what it's worth, although I always hear good things about Shenzhen IO I don't think it's for everyone.

I quit after a day because it just felt like I was working.

> In fact, all Zachtronics games are awesome and programming/logic inspired.

Ironclad Tactics (http://www.zachtronics.com/ironclad-tactics/) is not - and was a commercial failure.

Also "The Bureau of Steam Engineering" (http://www.zachtronics.com/the-bureau-of-steam-engineering/), of which Ironclad Tactics was planned to be a commercial spin-off also only partly satisfies this criterion.

Also worth checking out is the free web game BOX-256 where you use a toy assembly language to draw stuff: http://box-256.com/

I liked HRM but TIS was annoying and difficult enough that I thought "you know I could be doing TIS-100 or I could have equal frustration figuring out the nordic bluetooth SDK and mbed.io"... I went with the real world device. Same amount of skill required, actually useful though.

I got the same feeling playing TIS-100! It's cool it has a bit of story to it, but I just kept thinking to myself "I may as well write real software".

Yes! I played HRM, and the optimization challenges were challenging even for someone that teaches low level programming.

There is at least one puzzle in HRM where I can't get either the size or speed opt. It's annoying me a bit.

> "TIS-100", which both give a similarly visual insight into how computers work.

You know that TIS-100 was originally planned to be a very different game:

> http://www.gamasutra.com/view/news/244969/Things_we_create_t...

'The story of how TIS-100 came to Early Access this week starts where many development stories end: with an idea for a sprawling, grandiose game that proved too impractical to live.

“Years ago, I came up with this game idea called The Second Golden Age,” says Barth. It was basically a cyberpunk thriller set in a future Middle East crawling with nanotechnology other weird future tech.

“You'd be an engineer, and you'd be dabbling in all these different technologies; you'd be designing all these tiny little devices that could like, go into your bloodstream, and it'd be a super-cyberpunk engineering game,” says Barth.

The idea was to build an open world filled with different kinds of puzzles for the player to solve, a bit akin to Myst. Multiple systems of puzzles would be in play -- all of the chemical engineering puzzles in SpaceChem would be akin to one distinct subset of puzzles in Golden Age, for example -- and players could learn things about the world and advance themselves by mastering various puzzle mechanics. as the player could explore a virtual world filled with different kinds of puzzles to solve. Recently, Barth took a shot at making his idea a reality.

“We were really deep in production on Infinifactory, and I really wanted to ‘go indie’ -- even as an indie developer -- and make something on my own, to prove I could still do that,” recalls Barth. “Because now I don't make anything by myself, right? We have between 4-7 people on our team full-time, plus a bunch of external people. I wanted to see if I could make something -- not by myself, because I still didn't -- but at least with a smaller team.”

So Barth set out to try and recapture something of his past by crafting his Second Golden Age with some collaborators, designing a game with a story and five different puzzle games within it before realizing "Oh god, I can't make another game. There's so much work here! It doesn't make sense, it will cost a fortune to make the art, I just...I don't have time for this."

But out of that aborted attempt came a piece of game design that would become the foundation for a game he could actually make, a game about solving puzzles with assembly code.

“One of the puzzles I designed [for Golden Age] was exactly TIS-100,” says Barth. “The original story of The Second Golden Age was going to involve, as you're going around this future city in the Middle East, you can stumble into this junk shop where you find this old computer.'

(see also https://en.wikipedia.org/w/index.php?title=TIS-100&oldid=780... for a shorter summary).

I had no idea, that's really interesting!

This reminds me of my work at a big corp.

The admins didn't allow my team too much software, especially no compiler or something, but(!) they allowed MS Office.

So what happened was, that we started to program everything we need in VBA, with Word, Excel or Access as base, depending on the needs.

Yeah, very usual, and these companies make me very happy - they make exceptionally well paying customers when they critically need to redo everything into a "normal" application.

This is the case at a lot of places.

I know of global banks where billions of $ gets moved about by updating Excel spreadsheets.

I did this when I worked at JPM Chase in 2008; not as developer but as an analyst on treasury side. I executed $B daily of margin trades through an Excel macro.

Not very sophisticated. Each row in the spreadsheet was a trade. The loop would just send commands to a 1970s-era mainframe terminal application. Everything had to be executed in order, just like a human using the keyboard to enter the trades manually. The trades required several calculations, and you'd have to enter the results in terminal screen to execute the trade. Other analysts had been doing those calculations one by one on a calculator next to their mouse. The efficiency being, they didn't need to switch between apps on their PC.

This macro only existed because I built it. They didn't like it much, they wanted me to do it manually. I said OK and kept using the macro anyway. I quit after ~6 months out of boredom.

Unreal. I was working as a developer in their investment bank at that time and by then a lot of their software suite was pretty mature. In credit risk (my group) they had built a sophisticated set of applications to prevent being burned by another Enron. I'm pretty surprised they couldn't ask someone to take your macro and replicate it into a web app, but of course no one asks for our opinion. :)

This is frightening. Couldn't you have easily made a huge error?

probably, but doing the same thing over and over again manually is even more error prone.

Sure - but I am guessing a few errors here and there would have much less impact than a single programming mistake. Not that I think this is the right way, but I do understand where they come from.

Human error was much more common. But they did have another tool for reconciling trades that was better. It was web based and auto reconciled most things that were obvious matches. I don't recall why, but they were not too concerned with mistakes so long as we could fix them by the end of business. I think it was because that's when clients would see something was off on their statement/account. There was never a concern of losing money. I wish I could remember why, but this is my cumulative experience in banking industry and I quickly forgot everything I learned.

If you can automate your job you deserve to keep it and get paid for it, IMHO. :)

I can believe it. Once upon a time, a friend of mine at one of the largest oil companies told me how they were passing around a complex spreadsheet with tons of tabs and formulas and it was for managing the budgets of all their chemical plants around the world. I tried to explain how I could just put it all into a database and whip up a front end for it, but he said there's no way a consultant like me could get anywhere near his department since all firms had to be vetted extensively, there'd be a big RFP, etc, and anyway it sounds like they thought Excel was just fine for managing all this money.

I was encouraged to use Excel/VBA by our official Auditors and Advisors at a Fortune 500 public company. The rationalization was (whatever you might make of this):

- Excel is generally "contained" without too many external dependencies (not really true, but truer than others...)

- Excel is easily auditable (true for excel formulas, less so for VBA, but sure, better than Perl etc)

- Excel is easily versioned and frozen (some truth to this)

Obviously none of these answers are universally correct, but there was some truth to this. And Auditors/Advisors are generally more concerned about risk mitigation than other goals.

That's unbelievable and got me intrigued, please expand.

I find this hard to believe, maybe on bank loans or something, but billions of funds transfer?


This cannot be possibly true :o. Please expand.

I don't know about billions, but I've personally witnessed an Excel spreadsheet for millions of dollars that was manually updated.

It was sent over an encrypted Symantec thingie (where it was processed on my side), but errors weren't uncommon, it was really hard to automate, and I did get to see people being over-(and under-)charged due to manual errors.

Edit: a sibling comment has a story about moving billions over a macro, not mere millions :) .

One place I worked, they processed and paid payroll twice one month because someone dropped the files again and the ESB dutifully picked them up and sent them. That was a $6m mistake, took them years to work out how to reclaim the money from the workers (unions involved, contract lawyers, you name it).

The JP Morgan Whale incident [1] was a classic recent example of huge amounts of cash being managed in spreadsheets.

[1] http://spreadserve.com/blog/entry/saving-the-whale-excel-spr...

I sincerely hope you are trolling.

I hoped he was trolling because what he describes sounds outrageous.


I'm not trolling. It's 100% true and far more prevalent than you would expect.

People always choose the path of least resistance.

Oh, man. This is a VM in JS ("Google Script") with a UI in Google Sheets.

If I had more time I'd post a VM in Google Sheets formulas only.

Anyone want to take it up?

Edit: hold my beer (see my reply below)

OK, Gimme back my beer, it's done!

A Brainfk interpreter in pure Google Sheets formulas. I chose BF because of how cool and simple and powerful and turing complete it is and because I have a lot of practice implementing it (Just gave a talk at PyCon IL where I live coded one, https://www.slideshare.net/AurSaraf/virtual-machines-and-bra...).

Of course it would be at least as easy to implement any other virtual machine, you might not need the parentheses matcher which was the biggest challenge and I had to go through a few designs until it worked.

> "OK, Gimme back my beer, it's done!"

2 hours later. In BF none-the-less. You're my hero, you put me to shame.

These things are so much easier than they seem. I just did a PyCon IL talk where I livecoded a BF interpreter just so the audience gets a feel for how easy it is. Try sometime :-)

I created a VM in excel in my master's thesis. Table 1-4


Wow, this is extremely cool.

You created a VM in Excel and a VM that runs Excel in an FPGA, proving equivalence of Excel and an FPGA :-P

Try implementing a simple FPGA in Excel. 4-input look-up-table: MID(lutcell,bin2dec(concat(inputcells),1) and hten the input cells can be done with OFFSET to support programmable routing. You can set the values by hand at first, but then connect it to your VM to load in bitstreams :)

I have met an accountant with no knowledge in programming that wrote an entire accounting suite in an excel spreadsheet, which he would copy for each client.

You would be surprised how many accountants still do that. Accountants are a finicky bunch and they don't trust what a cloud accounting platform such as Xero/QB spit out, so they end up writing their own "custom software" in excel.

"Still"? I met him like three years ago. And the Israeli Xero/QB hasn't changed in like 20 years.

People have done some absolutely crazy things with Excel as well. To some people its like an OS.

Wasn't there a flight simulator or a Doom a decade ago?

Excel had a flight simulator as an easter egg, but it wasn't written in Excel formulas or VBA :)

Excel 97 had a sort of flight simulator. Excel 2000 had a car game. Earlier versions had other little easter eggs, but I think that Microsoft cracked down on them after Excel 2000.

Turns out the federal government to which Microsoft sells wondered, “if they’re sneaking in flight simulators and dungeons, what else are they sneaking in?” That’s the version I was told, anyway.

That, and Easter eggs are another attack vector. How much of a security audit do you think those get?

Indeed - some people have implemented games in it: http://mashable.com/2014/08/27/microsoft-excel-games/

My favorite is the Puerto Rico Evolver ( http://www.tropiceuro.com/puerto-rico-evolver/ ), which both allows you to play (vanilla) Puerto Rico (the board game), AND evolves to your playstyle as you play. Pretty amazing.

I am 99% sure you cannot do that. Cross-referencing cell loops are detected and prohibited, so you cannot even make a tape reader. Also, I'm not sure if you can set cell formulas with formulas either.

Well, I already have parentheses parsing working, which is the biggest challenge. The rest should be really easy.

Of course I'm working on Brainfk, both because of how cool it is and how simple for a Turing Complete VM. Also, because I have a lot of practice implementing it (https://www.slideshare.net/AurSaraf/virtual-machines-and-bra...)


Stay tuned.

Awesome! I originally wanted to use only cell formulas to do this but couldn't figure out how to modify cell contents from other cells. Can't wait to see what you put together.

I'd love to hear your thoughts. It's done! https://news.ycombinator.com/item?id=14703098

Not really, circular references and iterative calculations are supported in Google Sheets, as in Excel.

This reminds me of a "game" that a friend and I made in Excel.

The game was, roughly, a text-based adventure game. Each row in the sheet represented a "room", columns across gave names to the directions you could go and the target rooms, a description of the room, etc. I think there were other columns to mark whether the room represented the end of the game too. The UI was a bunch of buttons and cells on another tab that were manipulated by VBA code.

The game was never very good, but we ended up creating quite a lot within that limited framework.

VBA is less limited than people like the believe. When I was bored in one college lesson I was playing around with calling Win32 APIs inside a Word 97 macro. I was able to call winsock and write a simple chat application.

VBA is actually a pretty amazing language.

Even without diving into the Win32 APIs, there is an absolutely amazing amount of stuff that gets exposed via COM and, as a result, is easily accessible from VBA.

Of course, the biggest downside to all this power is that people actually used it. This is how you end up with businesses that live and die by gigantic and virtually impenetrable Excel workbooks.

Absolutely incredible. So when am I going to be able to play Doom on Sheets?

not really doom but 5 years ago some people made a raycasting engine on Sheets, lets you move around and everything.



wait for Bellard to release docslinux

A cell per frame-buffer pixel...

Not soon enough.. :)

Someone, somewhere, has just mumbled "hold my beer"...

Ha, good one. I implemented levenshtein distance in Apps Script the other day to help some poor colleagues who were doing manual data cleaning tasks.

Amazing, I did avoid hell to collegues by implementing some form of counter in VBA. My most prized coding contribution. 8 lines that evaporated hell (filtering 1000 rows in Excel to find duplicates) into fun.

This is how I started as well. But we had too many typos so I had to find something a little bit 'smarter'.

Next thing on my list is to implement tf–idf to help with free text categorisation.

Sounds great! Feel free to adapt this to your usecase, if useful: https://github.com/yesbabyyes/tfidf

I did levenstein a few time at that job, indeed, anything with operator input will have errors

I didn't know about App Scripts. This is very cool not just because it is a relatively clean visualization of a CPU but also because (on a personal level) it showed me what App Scripts can do.

Now if only it displayed the register values in hex or binary. As an education aid in college I found it easier to visualize what was actually happening in one of those bases. Another useful feature for debuggers is to highlight the values that changed in the last step. Sometimes even highlighting the exact bit if displaying in binary. I'm not sure how doable that is in Google Sheets though.

Edit: it's also a nice attention to detail that the stack shares the same heap as instructions. It might have been an easy out to put the stack in it's own column.

>Now if only it displayed the register values in hex or binary.

I assume that's as easy as adding a few more cells with =DEC2HEX(A2) or whatever.

I can't see the code without edit access? I go to Tools -> Script Editor, click, and it does nothing. No error even. (Happens in both Firefox and Chrome.)

Yes, me too, I also wanted to see the implementation. I did submit a "Problem Report" on why you don't get visual feedback when opening the script editor and getting an error.

That's weird. You should be able to copy the document and then view the source in your copy.

Thanks, making a copy works. But it should show you an error like "You need permissions to edit this document" or something.

I came in to learn how to run Windows XP in Google sheet.

Not exactly disappointed though.

Can it run Crysis though?

Doom hasn't been ported yet. Have achievable goals man!

First Doom, then Google Sheets on Google Sheets and then Crysis!

Fun read, it reminded me of a Computing Science assignment I remember to this day - prof had us build a Russian compiler that worked with trits (0,1,2) instead of bits. A tool like this would have made traversing and visualizing it a lot easier.

And I thought that http://www.deepexcel.net/ (Deep Spreadsheets with ExcelNet) was mind-blowing...

I had this idea one time to use MySQL triggers to create a bunch of XOR gates and then use those as a basis for a CPU. Then eventually I could run Linux on that and rung MySQL on top of it.

Now all we need is a higher-level language that compiles to Sheets VM. How hard would it be to write a C-like for this?

Not that hard. Allow me to recommend NAND2Tetris, one of the best courses I've ever tried, that has a great practical lesson on exactly that.

From the "use the right tool for the job" department :D

I remember of a Blackjack game implemented in SuperCalc 3 using only circular referencing and IF() as "programming" loopholes

Cloud vaping The next big step in free hosting: Milking public available turing complete services for free computation power.

I have a pretty big app that uses Sheets for free storage, apps script for processing and HtmlService to expose an json api endpoints and to serve the UI. I'm pretty happy with it. Totally free app.

Haha I did the same thing to build huge scrapers.

So cool! Useless, but cool :)

Wut? It's a really nice illustration of how a computer works. Have you clicked the link?

So much awesomeness!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact