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