Sha256: b1d5781c5536b0ddbf5867705bbc288bb26f6cf09b7a48d1c1f793be4c5b568c

Contents?: true

Size: 1.12 KB

Versions: 110

Compression:

Stored size: 1.12 KB

Contents

module PalindromeProducts

let isPalindrome n = 
    let mutable current = n
    let mutable result = 0
    while(current > 0) do
        result <- result * 10 + current % 10
        current <- current / 10

    result = n

let palindrome predicate minFactor maxFactor = 
    if minFactor > maxFactor then
        None
    else
        let allPalindromes = 
            [for y in minFactor..maxFactor do
                 for x in minFactor ..y do
                     if isPalindrome (x * y) then
                        yield x * y, (x, y)]

        match List.isEmpty allPalindromes with
        | true -> 
            None
        | false ->
            let value = 
                allPalindromes 
                |> List.map fst 
                |> predicate
            
            let factors = 
                allPalindromes 
                |> List.filter (fun x -> fst x = value) 
                |> List.map snd 
                |> List.sort

            Some (value, factors)

let largest minFactor maxFactor = palindrome List.max minFactor maxFactor

let smallest minFactor maxFactor = palindrome List.min minFactor maxFactor

Version data entries

110 entries across 110 versions & 1 rubygems

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