Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It may have been ruined by this year's Advent of Code, but for over a decade now my standard warm-up question has been: Write a Boolean function that determines whether two closed intervals [a,b] and [c,d] overlap.

No loops are required, no data structures, no algorithms, really: just a simple predicate expression. It is one example of what I think of as "programming in the small", this basic survival skill of being able to relate some values and correctly characterize a situation. You just have to be able to do this correctly if you're going to write correct if statements and while loops. Lots of bugs boil down to errors in examples of this kind of expression.

I've had PhDs from good schools write doubly-nested loops looking for a point in common. I've have very experienced engineers write expressions that have false negatives or false positives. A depressingly small proportion of candidates can think of a good way to test their answers.



I happened to want a generalization of this problem once and I went down a long rabbit hole: https://github.com/RhysU/intersection

Tests, QMC, the works.


I've been programming for decades, and I had to google what "closed interval" means exactly.. I even read quite a lot of mathematics. I don't see the term very often, and manage to forget which is "open" and which is "closed". Guess I don't get the job. :-(


That's an interesting approach and question. I think I might use that. Thanks!




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

Search: