Live data from Hacker News

Two problems I had to solve in my Oxford interview (2013)

blog.jgc.org

31–40 of 45 posts

Re: Two problems I had to solve in my Oxford interview (2013)

#32

Well, here is my non-zero-handling answer to the first Z2 I2 And with zero handling (maybe) Z4 I4 Z2 J0,2 -+ +-J0,4 | | I2 Z3 J1,3 -+ +-J1,4 | | I2 exit Edit * 2nd try

My solution, looks pretty similar to your second.

I think this should work:

  0 Z2
  1 Z3
  2 I4
  3 J0,3 -> 5 // If r0 != 0, jump to add it to r2
  4 J3,4 -> 9 // r0 == 0, force jump to check r1
  5 I2 // add r0
  6 I3
  7 J0,3 -> 5
  8 Z3
  9 J1,3 -> 11 // If r1 != 0, jump to add it to r2
  10 J3,4 -> exit // r1 == 0, force jump to exit
  11 I2 // add r1
  12 I3
  13 J1,3 -> 11
  14 exit
Phew that took a while. The simple case was easy enough. I guess exceptional candidates would be able to crack that out in an interview, otherwise they'd move you onto the balls.

Edited!

Re: Two problems I had to solve in my Oxford interview (2013)

#33
post #32

Well, here is my non-zero-handling answer to the first Z2 I2 And with zero handling (maybe) Z4 I4 Z2 J0,2 -+ +-J0,4 | | I2 Z3 J1,3 -+ +-J1,4 | | I2 exit Edit * 2nd try

My solution, looks pretty similar to your second. I think this should work: 0 Z2 1 Z3 2 I4 3 J0,3 -> 5 // If r0 != 0, jump to add it to r2 4 J3,4 -> 9 // r0 == 0, force jump to check r1 5 I2 // add r0 6 I3 7 J0,3 -> 5 8 Z3 9 J1,3 -> 11 // If r1 != 0, jump to add it to r2 10 J3,4 -> exit // r1 == 0, force jump to exit 11 I2 // add r1 12 I3 13 J1,3 -> 11 14 exit Phew that took a while. The simple case was easy enough.…

Couple corrections I think: - Register 4 should be set to zero before incrementing in instruction 2.

- inst. 4 should compare 0,4 , register 1 is unknown at this pt.

- inst. 3 should jump to 5

Re: Two problems I had to solve in my Oxford interview (2013)

#34

Earlier quoted context omitted.

Given the supplied instructions, it is not possible to write a program that handles floating point correctly, so my guess is that the failure conditions are non-integer numbers in locations 0 or 1. My code also doesn't handle negative integers correctly, but I'm pretty sure there is a way to do it. However, given that it is possible to write a program that works for all integers, and that this is an entry question fo…

> My code also doesn't handle negative integers correctly, but I'm pretty sure there is a way to do it. It's pretty easy to show by induction that you can't handle negative numbers in the general case. Consider: if memory locations 0 and 1 are both negative, so is their sum. But the only operations available to you are setting a value to 0, and incrementing it. You can't produce a negative number that way.

This is true. But if you are clever, you can handle the case where you have 2 arbitrary integers whose sum is non-negative!

The trick is to zero out a counter, then increment it until it is one of the two starting values. Then start a second counter and increment it together with the other starting value until the second counter reaches the first and the other contains the sum of the two. Finally start a counter at location 2 and increment it until it reaches the value of the register that has the sum.

Re: Two problems I had to solve in my Oxford interview (2013)

#35
post #9

Sure "only allowed to examine each ball once" should be "only allowed to examine each bucket once"? Otherwise you have to keep track of which balls you've looked at already after swapping. Also, I can't figure out how to do it that way :)

It's highly unlikely that a candidate would recognize this as Dijkstra's Dutch National Flag problem ( http://www.drdobbs.com/cpp/a-classic-example-that-off-the-en... ).

Re: Two problems I had to solve in my Oxford interview (2013)

#36
post #32

Earlier quoted context omitted.

My solution, looks pretty similar to your second. I think this should work: 0 Z2 1 Z3 2 I4 3 J0,3 -> 5 // If r0 != 0, jump to add it to r2 4 J3,4 -> 9 // r0 == 0, force jump to check r1 5 I2 // add r0 6 I3 7 J0,3 -> 5 8 Z3 9 J1,3 -> 11 // If r1 != 0, jump to add it to r2 10 J3,4 -> exit // r1 == 0, force jump to exit 11 I2 // add r1 12 I3 13 J1,3 -> 11 14 exit Phew that took a while. The simple case was easy enough.…

Couple corrections I think: - Register 4 should be set to zero before incrementing in instruction 2. - inst. 4 should compare 0,4 , register 1 is unknown at this pt. - inst. 3 should jump to 5

Yep 3->5 is a typo.

r4 could be zeroed, but I was lazy and assumed that as long as it's greater than zero it doesn't matter (since it's always compared to zero).

Instruction 4 should be cmp(3,4) to force a jump to 9.

EDIT: Although thinking about it, it doesn't make much difference. It has the same effect as doing cmp(0,4) since you know r4 > 0 and r0 == 0.

Thanks!

Re: Two problems I had to solve in my Oxford interview (2013)

#39

Well, here is my non-zero-handling answer to the first Z2 I2 And with zero handling (maybe) Z4 I4 Z2 J0,2 -+ +-J0,4 | | I2 Z3 J1,3 -+ +-J1,4 | | I2 exit Edit * 2nd try

My solution:

    0: Z 2
    1: Z 3
    2: J 0 2 -> 4
    3: J 1 3 -> 7
    4: I 2
    5: J 0 2 -> 4
    6: J 1 3 -> 7
    7: I 2
    8: I 3
    9: J 1 3 -> 7
Handles the zero case. Only uses 4 cells total.

Re: Two problems I had to solve in my Oxford interview (2013)

#40

The real question he was asked is: "Did you have access to computer science materials before applying. Prove it by solving these trivia."

No. I knew nothing about computer science when I got that interview. I had programmed (self-taught) but knew nothing of Big O and had never heard of Dijkstra or the Dutch National Flag problem.

These questions were less about testing my knowledge more about testing my ability to figure stuff out. The latter is highly prized in my experience by Oxford.

Post reply on HN