902 (HANGOVER) - Hangover
How many cards in a stack can overhang from a table?
Given a distance between 0.01 to 5.20 inclusive, return the number of cards required for the overhang length. In general, n cards can overhang to 1/2 + 1/3 + 1/4 + ... + 1/(n+1) card lengths.
This is a straight forward problem. Given the limited nature of answers, it's possible to build the entire set of answers in a 520-element array.
Here is a C++ implementation that precalculates all the overhangs, then uses a recursive binary search to find how many cards are required to produce the given overhang.
1.00 3.71 0.04 5.19 0.00
3 card(s) 61 card(s) 1 card(s) 273 card(s)