Rules: no spoilers.

The other rules are made up as we go along.

Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.

  • swlabr@awful.systems
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    1 year ago
    6 a,b

    Very easy today. You don’t need any programming to solve this; it’s a series of inequalities. That said, the brute force calculation is fast enough if you don’t want to think and is quite honestly faster than solving this mathematically.

    So that being said, here’s the mathematic solution:

    The inequality to solve is just: x = time holding the button

    x^2 - tx + d < 0

    which occurs when x is between (t/2) +/- (t^2 - 4d). The total ways are the total integers between those two numbers, exclusive.

    Writing that all in code is a little tricky thanks to int/double rounding/truncation intricacies, so the brute force solution is “better”.