Created
March 4, 2018 13:40
-
-
Save nohwnd/b8efcf42b24101b13a5808b1837f846f to your computer and use it in GitHub Desktop.
Pile of cubes
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
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