16
submitted 11 months ago* (last edited 11 months ago) by gerikson@awful.systems to c/notawfultech@awful.systems

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.

you are viewing a single comment's thread
view the rest of the comments
[-] swlabr@awful.systems 2 points 11 months ago* (last edited 11 months ago)

6 a,bVery 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".

this post was submitted on 01 Dec 2023
16 points (100.0% liked)

NotAwfulTech

358 readers
10 users here now

a community for posting cool tech news you don’t want to sneer at

non-awfulness of tech is not required or else we wouldn’t have any posts

founded 1 year ago
MODERATORS