Story Details

  • Show HN: Betting game puzzle (Hamming neighbor sum in linear time)

    Posted: 2025-02-28 20:33:43

    The Hacker News post presents a betting game puzzle where you predict the sum of your neighbors' bets, with the closest guess winning. The challenge is to calculate this sum efficiently when dealing with a large number of players, each choosing a bet from 0 to 9. The author shares a clever algorithm that achieves this in linear time, utilizing a frequency array to avoid redundant calculations. This approach significantly improves performance compared to a naive quadratic solution, making the game scalable for a substantial number of participants.

    Summary of Comments ( 0 )
    https://news.ycombinator.com/item?id=43210185

    Hacker News users discussed the efficiency and practicality of the presented algorithm for the betting game puzzle. Some questioned the "linear time" claim, pointing out the algorithm's reliance on a precomputed lookup table, the creation of which would not be linear. Others debated the best way to construct such a table efficiently. A few commenters suggested alternative approaches, including using Gray codes or focusing on bit manipulation tricks. There was also discussion about the problem's framing, with some arguing it's more of a dynamic programming exercise than a puzzle. Finally, some users explored variations of the puzzle, such as changing the allowed bet sizes or considering non-integer bets.