Created
March 19, 2016 12:20
-
-
Save DavidBrower/5cc6cd7f36c0a0b44134 to your computer and use it in GitHub Desktop.
Palindrome Numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A palindromic number reads the same both ways. | |
//The largest palindrome made from the product of two | |
//2-digit numbers is 9009 = 91 × 99. | |
//Find the largest palindrome made from the product of | |
//two 3-digit numbers. | |
open System | |
let noOfDigits = 3 | |
let lowestCandidateFactor = pown 10 (3 - 1) //100 | |
let highestCandidateFactor = (pown 10 3) - 1 //999 | |
let reverse (input: string) = | |
new string(input.ToCharArray() |> Array.rev) | |
let isParabola n = | |
(string n) = reverse n | |
let candidateFactors = {lowestCandidateFactor .. highestCandidateFactor} | |
Seq.map (fun x -> (Seq.map (fun y -> x * y) candidateFactors)) candidateFactors | |
|> Seq.concat | |
|> Seq.filter isPalindrome | |
|> Seq.max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment