Hacker News new | past | comments | ask | show | jobs | submit login

I was once asked a very similar problem during a job interview for a position of a software engineer. I was offered to solve it on a piece of paper or orally. We ran out of time and they offered me to take it home. I did and I spent a few hours thinking about it. Google and ChatGPT were not able to produce better results than the intuitive answer, so I built a test program that confirmed the weird behaviour. After meditating for a few hours I was able to find the correct answer and I was indeed fascinated by this. Do you also think it's too much for a usual interview?



Kudos for solving this. And yes, this is too much for a job interview.


I don't think this an unreasonable puzzle for a role that involves problem-solving or security.

You can read the code, figure out what primitives you have, translate the problem into something simple (I like card and board games), then map it back.

Problem: two processes each do this ten times: - read the counter - do any number of other things in other processes - write back what you read, plus one.

Game: You have two piles of cards. Each card costs 1 move to play, but lets you discard any number of cards from other piles at the same time.

Solution: play one red card, discarding everything but one blue card. Play the single remaining blue card, discarding the leftover red cards.

Back: process 1 reads, process 2 runs 9 steps, process 1 writes, process 2 reads, process 1 finishes, process 2 writes.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: