DEV Community

Discussion on: Daily Challenge #230 - Beeramid

Collapse
 
cipharius profile image
Valts Liepiņš • Edited

Haskell solution using lazy, infinite list of cans:

import Data.List (findIndex)

beeramid :: Double -> Double -> Int
beeramid m p = 
  case findIndex (> cans) levels of
    Just level -> level
    Nothing    -> 0
  where
    cans = m / p
    levels = scanl1 (+) . fmap (^2) $ [1..]