finish level5/dodge-the-lasers #7
@ -28,11 +28,12 @@
|
|||||||
* Completed in: 6 hrs, 49 mins, 26 secs.
|
* Completed in: 6 hrs, 49 mins, 26 secs.
|
||||||
* DP & Optimization
|
* DP & Optimization
|
||||||
|
|
||||||
## Encrypted message
|
|
||||||
CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQMQVBkPERkECQAWDVwXX1BGEwgJBAwCBFRVHQRGUlFBShwaDVZTGBUFVUdBShsVA1tZBwNGUlFB ShoVB1wXX1BGFAQOSklOQR5HGh5AVRY=
|
|
||||||
|
|
||||||
## Others
|
|
||||||
### dodge-the-laser
|
### dodge-the-laser
|
||||||
|
* Completed in: 2 days, 20 hrs, 22 mins, 39 secs.
|
||||||
* Reference
|
* Reference
|
||||||
* [Beatty sequence](https://en.wikipedia.org/wiki/Beatty_sequence)
|
* [Beatty sequence](https://en.wikipedia.org/wiki/Beatty_sequence)
|
||||||
* How to find A001951 A Beatty sequence: a(n)=floor(n\*sqrt(2)), stackexchange, https://math.stackexchange.com/questions/2052179/how-to-find-sum-i-1n-left-lfloor-i-sqrt2-right-rfloor-a001951-a-beatty-s
|
* How to find A001951 A Beatty sequence: a(n)=floor(n\*sqrt(2)), stackexchange, https://math.stackexchange.com/questions/2052179/how-to-find-sum-i-1n-left-lfloor-i-sqrt2-right-rfloor-a001951-a-beatty-s
|
||||||
|
|
||||||
|
## Encrypted message
|
||||||
|
CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQMQVBkPERkECQAWDVwXX1BGEwgJBAwCBFRVHQRGUlFBShwaDVZTGBUFVUdBShsVA1tZBwNGUlFB ShoVB1wXX1BGFAQOSklOQR5HGh5AVRY=
|
||||||
|
|
||||||
|
|||||||
@ -2,25 +2,23 @@ import math
|
|||||||
from decimal import *
|
from decimal import *
|
||||||
|
|
||||||
def solution(s):
|
def solution(s):
|
||||||
getcontext().prec = 10000
|
getcontext().prec = len(s)+1
|
||||||
sqrt_2 = Decimal(2).sqrt()
|
return str(beatty_sum_sqrt2(int(s)))
|
||||||
|
|
||||||
return str(beatty_sum(sqrt_2, int(s)))
|
def beatty_sum_sqrt2(n):
|
||||||
|
|
||||||
def beatty_sum(r, n):
|
|
||||||
if n == 0:
|
if n == 0:
|
||||||
return 0
|
return 0
|
||||||
if n == 1:
|
if n == 1:
|
||||||
return 1
|
return 1
|
||||||
floor_r_n = int(math.floor(r*n))
|
floor_r_n = int(Decimal(2*(n**2)).sqrt())
|
||||||
|
|
||||||
return natural_number_sum(floor_r_n) - 2 * natural_number_sum(floor_r_n - n) - beatty_sum(r, floor_r_n - n)
|
return natural_number_sum(floor_r_n) - 2 * natural_number_sum(floor_r_n - n) - beatty_sum_sqrt2(floor_r_n - n)
|
||||||
|
|
||||||
def natural_number_sum(n):
|
def natural_number_sum(n):
|
||||||
return n*(n+1)/2
|
return n*(n+1)/2
|
||||||
|
|
||||||
def ten(n):
|
def ten(n):
|
||||||
return 10**n
|
return str(10**n)
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
['77', '4208'],
|
['77', '4208'],
|
||||||
@ -34,7 +32,7 @@ tests = [
|
|||||||
['8', '47'],
|
['8', '47'],
|
||||||
['9', '59'],
|
['9', '59'],
|
||||||
['10', '73'],
|
['10', '73'],
|
||||||
[ten(100), '0']
|
[ten(100), '70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078638821760123411090095254685423841027253480565451739737157454059823250037671948325191776995310741236436']
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user