Skip to content

Instantly share code, notes, and snippets.

@DavidBrower
Created March 19, 2016 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidBrower/5cc6cd7f36c0a0b44134 to your computer and use it in GitHub Desktop.
Save DavidBrower/5cc6cd7f36c0a0b44134 to your computer and use it in GitHub Desktop.
Palindrome Numbers
// 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