Last active
October 16, 2022 14:10
-
-
Save FBosler/be0e667ed8437160572979d38fb99fb4 to your computer and use it in GitHub Desktop.
foobar_dodge_the_lasers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal, localcontext | |
def solution(s): | |
n = Decimal(s) | |
with localcontext() as ctx: | |
ctx.prec = 102 | |
r = Decimal(2).sqrt() | |
s = Decimal(2) + Decimal(2).sqrt() | |
def solve(n): | |
if n == 0: | |
return 0 | |
Brn = int(r * n) | |
Brns = int(Decimal(Brn) / s) | |
return (Brn * (Brn + 1)) / 2 - solve(Brns) - Brns * (Brns + 1) | |
return str(int(solve(n))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be improved slightly by replacing
Decimal(2).sqrt()
in thes
variable assignment withr
, since they are exactly the same. I tried it against the test cases to make sure and the results were identical.Cheers!