Hacker News new | ask | show | jobs
by gaius 2920 days ago
who can't tell me how to implement cycle detection

You should read this before asking that again http://www.nihlos.com/2009/05/04/stupid-interview-questions/

When my Macbook Pro is "locked" it flashes an image of the desktop screen just before switching to the login prompt.

Same with my Mac Mini on the lock screen. Very easy to start a camera going (say an iPhone) waggle the mouse and get a screenshot of any locked Mac.

2 comments

I think this is because the Mac doesn’t lock at all by default. The actual behavior seems to be “prompt for password after screen saver is interrupted” so that flash is the time it takes the OS to realize the screensaver just turned off and it’s time to ask for the password on the lock screen.

When I leave my Mac I always do a ctrl-shift-eject/power to force the lock immediately.

The saving a screenshot and immediately showing it is a UI trick to make waking up/unlocking look faster, gives the user something to look at while the apps are actually restoring to running state. Just they didn’t think this one through or test it adequately
This sounds like the kind of applicant who would complain that fizzbuzz has no real world application. Despite the attitude in that article, there are real applications of cycle detection.

https://en.wikipedia.org/wiki/Cycle_detection#Applications

It sounds like the kind of applicant who understands the problem far better than the interviewer. So go on then: once you have detected it, what algorithm would you use to repair it? Wouldn’t you consider its existence to be a bug in the way the list was constructed?
It depends too much on the context to give a general answer what to do with it. It can easily not even be an "error," like in the first example on this link where you're simply testing the strength of a PRNG. Another would be if you're writing something to represent reals in decimal and you want to see where your number loops, like 1/7 = 0.(142857).

Examples where it's not desired, and what to do: Detecting infinite redirects in browsers and stopping the loop. Detecting thread deadlock and terminating the process. Detecting looping references in an Excel spreadsheet and showing #ERROR in the cells instead of letting the process hang forever.