Skip to content

Instantly share code, notes, and snippets.

@angeloped
Created December 2, 2020 06:20
Show Gist options
  • Save angeloped/e6d147de7eecd8138ba60d5af05ddf4e to your computer and use it in GitHub Desktop.
Save angeloped/e6d147de7eecd8138ba60d5af05ddf4e to your computer and use it in GitHub Desktop.
Determine the nearest perfect cube within the range from 0 to n.
def near_cube(num):
for i in range(num,0,-1):
if (i**(1.0/3))%1==0: # if perfect cube
break
return i
print(near_cube(730))
print(near_cube(729))
print(near_cube(29))
print(near_cube(27))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment