Sha256: c381449a2534a89c77cbcb46eb835eeffe5df715edf475d13b59249a6ce9bc26

Contents?: true

Size: 587 Bytes

Versions: 334

Compression:

Stored size: 587 Bytes

Contents

module Series (largestProduct) where

import Control.Monad    ((>=>))
import Data.Char        (digitToInt, isDigit)
import Data.List        (tails)
import Data.Maybe       (mapMaybe)
import Safe             (maximumMay)
import Safe.Exact       (takeExactMay)

largestProduct :: (Integral a, Num b, Ord b) => a -> String -> Maybe b
largestProduct n = traverse charToNum >=> maximumMay . products
  where
    products = mapMaybe (fmap product . takeExactMay (fromIntegral n)) . tails
    charToNum x
        | isDigit x = Just . fromIntegral . digitToInt $ x
        | otherwise = Nothing

Version data entries

334 entries across 334 versions & 1 rubygems

Version Path
trackler-2.2.1.96 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.95 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.94 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.93 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.92 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.91 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.90 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.89 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.88 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.87 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.86 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.85 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.84 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.83 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.82 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.81 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.80 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.79 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.78 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs
trackler-2.2.1.77 tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs