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.98 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.97 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.96 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.95 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.94 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.93 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.92 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.91 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.90 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.89 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.88 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.87 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.86 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.85 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.84 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.83 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.82 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.81 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.80 tracks/fsharp/exercises/largest-series-product/Example.fs
trackler-2.2.1.79 tracks/fsharp/exercises/largest-series-product/Example.fs