29

First, you pass the salt. Then you pass the pepper. Then you pass the grated parmesan cheese. At this point, you have enough experience to start developing a general condiment-passing system. It works in software projects in the same way: use special purpose systems that you develop as your learning steps to generalized ones, so when it is time to start ...


21

Ask why a lot, and keep asking it until the problem is clear. Why did the code crash? Because we got a divide by zero. Why did we get a divide by zero? Because X was zero. Why was X zero? Because it was passed in by function foo. Why did foo pass in a zero? Because it was set to the total number of relationships that the object has Why did this object have ...


17

I recall reading a study on how fire marshalls form a plan of action on arrival at the scene of a fire; the study observed (and condemned) them for coming up with an idea, then pursuing that first idea immediately. Due to the pressure of time, it was pretty much "this might work" followed by "ok, let's do that". The study noted that better, quicker, safer ...


14

As a hiring manager, if I'm asking you to solve a problem with code right there in front of me, I'm not doing it so much to see the code itself (although it's important) but rather to ascertain the how and why you did what you did. One of those things that you might do is not code, and instead interrogate me as to the aspects of the problem itself, to ...


14

Google Drive If you're trying to make your own version of google docs, I suggest you take a look at the Google Realtime API. Google recently released this with the intent of allowing other developers to use the same tools they did to allow for realtime collaboration. This would allow you to save time on your development and get a working product sooner. You ...


11

Teachers may encourage students to approach problems in a structured way because it breeds good habits and fosters a structured mindset, both of which are good things. If you polled all software developers with more than two years of experience, I bet that they would all tell you that software developers do not follow any such formal, prescribed, structure, ...


11

Divide and conquer is about making the problem so small that it is absolutely trivial to solve. Then you make it slightly larger, and slightly larger, and look for patterns. For Towers of Hanoi, what is the simplest possible problem? One disk, moved straight to its destination. The second simplest is two disks. First you move one disk to a temporary ...


10

For these types of things, I recommend that you file a defect, issue or an enhancement request as appropriate so that it can be tracked, scheduled if need be, and not forgotten. Get your primary and most important work done before you start tackling the extra. Not only does this help ensure you hit your own deadlines, it also gives others a chance to ...


10

You don't need monads to solve anything. They just make certain things simpler. A lot of people go way too abstract and theoretical when explaining monads. Mostly, monads are a pattern that comes up over and over again in programming. By recognizing that pattern, we can simplify our code and avoid reimplementing certain functions. For Haskell, from a ...


9

First of all, a question that takes two experienced developers three hours to elegantly optimize is a poor choice for an interview question. If you ask it, you shouldn't expect perfect answers. On the other hand, sometimes you learn the most about someone when you make them hit their limits. That's why a lot of college courses ramp up the difficulty then ...


9

Spoiler alert: This answer leads you to a solution, but does not implement it Using WuHoUnited's example, modified for uniqueness: 9 7 0 2 4 6 8 5 1 3 Ask yourself this: If you found yourself at 2, would you ever take 8 instead of 5, knowing they are the leaf nodes of the tree? Similarly, If you found yourself at 6, would you ever take 3 instead of ...


9

How do I know when it's best to try and cover a finite list of cases, or make a generic system to cover all possibilities? Experience. The only way to know is to have tried one path before, seen how it's bitten you in the ass (or you've wasted a bunch of time). Repeat until you get bit in the ass less. Even then, you don't really know; you just have a ...


9

Think about this: first of all, to solve the given problem, there is a non-trivial program to be written. It does not need to have a fancy Web or desktop UI or a "database layer" or , but it involves some kind of "business logic" which has to be tested and debugged. for solving the problem, you need some integer math / combinatorics. There are lots of real-...


9

Given a direct line of sight, the problem is obviously trivial. However, we are dealing with reflection. Properly finding out which parts of the scene can be seen is challenging when implementing reflection as part of a ray tracer, since this might miss some openings. A “binary search” between two promising angles is also not viable: due to the reflections, ...


8

You don't architect your "framework". You can use many different techniques to determine what it is you want your game to do. Then you just start doing it. As you go along you make decisions on if a method (or unit of logic) belongs in the framework or not. For example, you shouldn't be trying to figure out save file formats, until you actually have a ...


8

You can encode the 8! possible permutations of the corners in 16 bits, and the 12! possible permutations in 29 bits, by numbering the permutations from 1 to 8! (or 1 to 12!), and storing the number. I found a description for how to make this encoding efficient here, using a Lehmer code. In an analogous manner, you can pack the 3^8=6561 orientations of the ...


7

Just extending Karl Bielefeldt idea for a 2 walls reflections: A and B are given (the tanks). You first must list all walls that A can see and a list of all walls B can see. Then you make pairs where the first wall is in the fist list and the second wall is different from the first wall and is in the second list. You need to make this test for all possible ...


6

It's always possible to come up with an even worse case that ruins whatever solution you come up with. Assume a hostile web service, or a hostile database, and you're screwed. But in the scenario you describe, you mainly need a more reliable action log than an external database. Let's assume that the local file system is reliable if you don't increase file ...


6

I would like to know how I can schedule the job to not forget anything You can't. Whether you're Robin Seggelmann or Donald Knuth, writing a computer program of any realistic size is simply not a task that the human mind can achieve wholly without errors. That's a simple truth, it's just often ignored because the mind has a fantastically advanced capability ...


5

I think it's not a reasonable thing. We try to find candidates, which are good at the task we want them to do. Writing code on a whiteboard is not one of them and I don't think it's a valid filter to find good candidates. Good code doesn't get written, it gets rewritten. A whiteboard is pretty much immutable, as it's hard to change once you wrote it. It ...


5

You can indeed compound ('add up') the rotations by multiplication. I'd consider using Quaternions instead though. They're much nicer to work with and they avoid problems with Euler type rotations (e.g. gimbal lock). You can plug in arbitrary axes of rotation, rather than worrying about X, Y, Z rotations. Quaternion compound rotations nicely -- and if you ...


5

It is easier to understand if you look at the particular monads and see what problems they solve. For example, in Haskell: IO: Allows IO to be represented in the type system, so you can cleary seperate pure functions from functions performing IO. List: Allows you to do list comprehensions and nodeterministic computations. Maybe: A better alternative to ...


5

It is just by definition that the carry output of the last ALU operation is captured to bit-0 of the flags. This kind of thing is relatively easy for hardware to accomplish in a number of ways. It could have just as easily been any (other) bit of the flags (or even somewhere else!). From only the definition of the instruction set architecture, we don't ...


4

I'd want both, but they may display a "code that just works" in one solution and then possibly discuss potential solutions for improvement in that one or another problem. If you ask someone to write code and they just want to talk about possible solutions with zero code, that would be a concern. Like you said, someone may struggle with the particular ...


4

You basically have a tournament. In a round-robin tournament, 40 players can play 39 rounds and meet each player exactly once. The Wikipedia article on round robin tournaments has a description of a simple algorithm to generate the pairings for each round. There are also pre-computed tables on the Internet (look for Berger tables, for instance), but not ...


4

Basically, your range is 0 to 1000. When one value is changed, your new range is 0 to sum(N). You want to then normalize to 0 to 1000. So you compute the fraction of the total for each value and then multiple by 1000. Each value is thus multiplied by 1000/sum(N). Here's an example: [100,100,300,500] Now suppose we change one value: [100,300,300,500] # ...


4

First, the CPU just does what you tell it. Someone else has to translate an expression into CPU instructions. Second, -x-(-y)=z and -x+y=z are equations (relation formulas), not assignment statements, at least in most languages I can imagine off hand. An expression like y-x is typically assigned to a variable looking something like var z = y-x;. Third, ...


4

The F-register is a special one which holds different flags. You can read and evaluate it. If you have an add-operation that overflows, it will set the carry bit in the F-register. A carry over is created if the MSB of either operand is set and the bitwise addition result is larger than the target. E.g. if you add the two unsigned bytes 0x80 and 0x81 the ...


3

Is there a rule like after 20 minutes you should just start coding no matter what? No, but if you spend 20 minutes analyzing the problem before you get down to business, you're probably in trouble already. An employer who asks you a question like the one you cited is mostly interested in how you approach a problem, but if they ask it as a coding problem ...


3

As a manager, If I ask you to code as a test, I am most interested in: Whether you can write code Your coding style The algorithm you selected Does the attempt indicate that you understood the problem If I'm really hot about a specific technology, did you demonstrate that you more or less know it. The first item may seem crazy, but you would be surprised......


Only top voted, non community-wiki answers of a minimum length are eligible