3 ms·
One common interview question I've run across is to write the code for a simple four-function calculator, the kind that you can find for a dollar or two in near
by kabdib 9y ago
One common interview question I've run across is to write the code for a simple four-function calculator, the kind that you can find for a dollar or two in nearly any convenience store, right next to the pencils and erasers.
Hey, it's all just buttons and a display doing simple things, right? Only it turns out to be a fairly complicated task, with a lot of corner conditions, even when you treat the math library as a given and leave out all the really low-level stuff (button handling, display refresh, etc.).
You're not going to get to a usable calculator by having a casual conversation with a user interface builder.
"Computer, make that button green, um, no ... yellow" is comparatively easy. "Computer, now make that button add the two numbers together" is begging so much of the specification that it's not really programming any more. And if you do go deeper and try to teach the computer about pending operations, number entry and a stack (to handle parenthesis), you're programming again, only with a lousy IDE.
- userbinator 9y agoOne common interview question I've run across is to write the code for a simple four-function calculator, the kind that you can find for a dollar or two in nearly any convenience store, right next to the pencils and erasers. Coincidentally, I've previously posted here a detailed model/explanation of how those work: https://news.ycombinator.com/item?id=9456444 https://news.ycombinator.com/item?id=9456444 They're usually based on a 4-bit mask-ROM microcontroller running at several kHz. Very "simple" in relative terms to most computers today, and in hindsight I could probably write the code for one quite quickly, but I bet the 99% of programmers who haven't ever really given a thought to how they work in detail would struggle to come up with an accurate description in an interview. Also worth reading: https://news.ycombinator.com/item?id=6302364 https://news.ycombinator.com/item?id=6302364
- psyc 9y agoI’m about to do a 4-bit 4 op calculator with only logic gates, for a project. Not that I could do it in an interview!
- lgas 9y agoOut of curiosity, in the description you linked you say it's a two-register model but then you mention R, O and I but only refer to O as a register. You refer to both R and I as accumulators. I assume at least one of them is also a register, but that would suggest it's a three-register model, no?
- userbinator 9y agoI meant two actual registers/accumulators (R and I) which store numbers, and O which only stores the operation being performed.
- lgas 9y agoGotcha, thanks.