Skip to content

Instantly share code, notes, and snippets.

@amchercashin
Created May 4, 2018 15:39
Show Gist options
  • Save amchercashin/8df70242ae686921bc80c6a28b872f3d to your computer and use it in GitHub Desktop.
Save amchercashin/8df70242ae686921bc80c6a28b872f3d to your computer and use it in GitHub Desktop.
from math import sqrt, ceil
def solve(room_number):
s = room_number
square_float = 1/2*((sqrt(3)*sqrt(3888*s**2-1)+108*s)**(1/3)/3**(2/3) + 1/(3**(1/3)*(sqrt(3)*sqrt(3888*s**2-1)+108*s)**(1/3)) - 1)
level_float = (1/2)*(1+square_float)*square_float
square = ceil(square_float)
level = ceil(level_float)
approx_position = level_float - level + 1
position = round(approx_position / (1/square))
return level, position
print(solve(60))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment