• vitus 11 hours ago

    Another way to frame the brute-force solution: there are "only" 5151 cases when you naively consider the integral constraint and the total number of individuals.

    Python one-liner:

        >>> [(x, y, 100-x-y) for x in range(101) for y in range(101-x) if 0.5*x + 2*y + 3*(100-x-y) == 100]
        [(68, 30, 2), (70, 25, 5), (72, 20, 8), (74, 15, 11), (76, 10, 14), (78, 5, 17), (80, 0, 20)]
    
    If you want to make your state space even smaller, you can assert that at least 2/3 of the people must be children (since 66 children + 34 women -> 101 bushels, so you need at least 67 children), and you must have an even number of children to result in an integral number of bushels overall. As a result, you can replace the first `range` with range(68, 101, 2); that yields only 289 potential triples to check.

    This is about a sixth of the number of cases as the article's brute-force approach (33*50 = 1650).

    • defrost 11 hours ago

      Earlier discussion:

      32 points by jmount 21 hours ago | 13 comments https://news.ycombinator.com/item?id=41688019

      • undefined 11 hours ago
        [deleted]