Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created March 4, 2018 13:40
Show Gist options
  • Save nohwnd/b8efcf42b24101b13a5808b1837f846f to your computer and use it in GitHub Desktop.
Save nohwnd/b8efcf42b24101b13a5808b1837f846f to your computer and use it in GitHub Desktop.
Pile of cubes
findNb :: Integer -> Integer
findNb m =
if (volume == m) then
fromIntegral $ length cubes
else
-1
where
cubes = listCubesTillVolume m
volume = last cubes
listCubesTillVolume :: Integer -> [Integer]
listCubesTillVolume m =
takeWhile (<= m) $ listCubes
listCubes :: [Integer]
listCubes =
scanl (\acc v -> acc+v^3) 1 $
iterate (+1) 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment