Live data from Hacker News

The four programming questions from my 1994 Microsoft internship interview (2023)

computerenhance.com

41–50 of 103 posts

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#42

void CopyString(char *From, char *To) { /* Fill this in */ } The only correct answer to this interview question is "No."

/* YOLO */ while (*to++ = *from++) ;

I see someone has read K&R.

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#43

How does the video whiteboard work? I presume he isn't really writing backwards or is this some sort of software that handles the video and writing surface?

https://www.lightboard.info/

I think he wears a shirt with mirrored writing so it looks correct to the viewers.

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#44

How does the video whiteboard work? I presume he isn't really writing backwards or is this some sort of software that handles the video and writing surface?

https://www.lightboard.info/ I think he wears a shirt with mirrored writing so it looks correct to the viewers.

Dang cool, think I've heard or seen references to it before but never seen it. Thanks for the information and link

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#46

What is pitch in regard to a rectangle in question two?

Pitch is the offset between the start of consecutive rows of pixels in the image, used to convert y coordinates into the start of any given row, so you access a pixel as buffer[y*pitch+x]. Often this is the image width, but can be greater depending on required alignment.

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#47
This brings back memories! I could easily pass this interview today, because I used to write code like this all the time 25 years ago doing gamedev (and so did everyone else to some extent). But the really interesting thing is that I just realized I haven't written code like this in a long, long time.

Programming has changed over time, but the change has been so gradual I hadn't even realized this until this article. These days I'm pondering how the profession has changed in the last 2 years due to AI. Feels a lot more like a step change. And yet I'm having more fun than I've had in a long time, both at work and at home, throwing Claude at problems. I still don't fully understand why.

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#48
I had a go at the circle one. What I tried was starting with something very straightforward (pseudocode):

  for each x from -r to r
    find y that minimizes abs(x^2 + y^2 - r^2)
    plot(x,y)
Finding y could be done by taking sqrt(r^2 - x^2) and then taking whichever for floor or ceil of that gives less error. But I assume they probably don't want sqrt. We could find y without using sqrt by doing some kind of search--say start with 0 and increment checked x^2 + y^2 - r^2 until we find where that crosses 0 and then take whichever y made it closes to 0. But that will be even slower than sqrt.

But what if we take advantage when we are trying to find the y for x+1 that we already have found the y that minimizes the error at x? Say we wrote a next_y(y, e) function that takes the y that was used for x and the error e that would be the error if we also used y for x+1 and that function returns the y that would minimize the error at x+1.

That's pretty easy (Python):

  def next_y(y, e):
      if e = 0:
                  if abs(e+delta)  0:     # need to decrease y
          delta = 1 - 2*y
          while e > 0:
              if e + delta 
Here's how it is used:

def circle(r): x = -r y = 0 e = 0 print(f'{x},{y}') for i in range(2r): e += 2x + 1 x += 1 y, e = next_y(y, e) print(f'{x},{y}')

Here are some half circles drawn with it: https://imgur.com/a/5aYzPqS

The basic idea is that when you increase x by 1 you increase x^2 by 2x+1, and so (x+1, y) would have error 2x+1 more than (x, y). You then need to change y to compensate.

Changing y by k changes y^2 by 2yk + k^2. Changing k by 1 changes the amount that y^2 changes by 2y + 2k + 1. Note that 2y + 2k + 1 goes up by 2 every time k goes up. In other words if you look at the sequence y^2, (y+1)^2, (y+2)^2, ... the third order diffs are 2. So to see how consecutive changes to y affect y, we can just keep track of the adjusted e and the current second order diff. Then for each consecutive y we can add the second order diff in to update the adjusted e to for the next y, and add the third order diff (the constant 2) into the second order diff.

I split next_y into two cases depending on whether we need to increase y or decrease y. There is probably some way to combine them but it is late and I'm half asleep. Oh, and I realize half of the abs() calls can be removed. I thought it looked clearer with them.

For a radius 50 half circle here is how times it took N tries to find the right y:

   3 0
  68 1
  18 2
   6 3
   2 4
   1 5
   2 10
i.e., for 68 values of x, the first y it looked at was the right one. Here are the numbers for a radios 300 half circle:

   3 0
 410 1
 121 2
  35 3
  13 4
   7 5
   2 6
   3 7
   2 8
   2 11
   1 24
   1 25
That was a fun little exercise. It has two multiplies, but they are both by 2 so could easily be replaced by add or shift.

An improvement would be to make more use of symmetry. The curve looks best when x is between -r/2 and r/2. It would be better to draw just those parts and then use symmetry to fill the rest.

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#49
Answer posts:

1) https://www.computerenhance.com/p/microsoft-intern-interview...

2) https://www.computerenhance.com/p/microsoft-intern-interview...

3) https://www.computerenhance.com/p/microsoft-intern-interview...

4) https://www.computerenhance.com/p/efficient-dda-circle-outli...

Post reply on HN