Sha256: 23fd52904e5829b1f6c8988cd4db7cb8ba9d980b4f2e0fcadae208d2d3066943

Contents?: true

Size: 881 Bytes

Versions: 130

Compression:

Stored size: 881 Bytes

Contents

module LargestSeriesProduct

open System

let digits (str: string) = 
    str
    |> Seq.map (string >> int)
    |> Seq.toList

let slices size list = 
    let slice i = 
        list 
        |> List.skip i 
        |> List.take size

    let sliceCount = List.length list + 1 - size

    List.init sliceCount slice

let allDigits input =
    input
    |> Seq.forall Char.IsDigit
    
let isInvalidCase input seriesLength =
    let inputLenth = String.length input
    
    inputLenth < seriesLength 
    || inputLenth = 0 && seriesLength > 0 
    || seriesLength < 0 
    || not (allDigits input)

let largestProduct input seriesLength : int option = 
    match isInvalidCase input seriesLength with 
    | true -> None
    | false ->   
        input 
        |> digits 
        |> slices seriesLength
        |> List.map (List.fold (*) 1)
        |> List.max
        |> Some

Version data entries

130 entries across 130 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/largest-series-product/Example.fs