72 people like it.

Largest Palindrome Number from Product of Two Three Digit Numbers

Here is an improved version twice shorter, than original

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
let cartesianProduct l1 l2 =
    List.map (fun x -> (List.map (fun y -> x * y) l2)) l1 |> List.concat

let isPalindromic n = 
    let isAnagram (s: string) =
        new string(s.ToCharArray() |> Array.rev) = s
    isAnagram(string n)

cartesianProduct [999..-1..100] [999..-1..100]
|> List.filter isPalindromic
|> List.max
|> printfn "Project Euler Problem 4 Answer: %d"
val cartesianProduct : l1:int list -> l2:int list -> int list

Full name: Script.cartesianProduct
val l1 : int list
val l2 : int list
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val map : mapping:('T -> 'U) -> list:'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.map
val x : int
val y : int
val concat : lists:seq<'T list> -> 'T list

Full name: Microsoft.FSharp.Collections.List.concat
val isPalindromic : n:int -> bool

Full name: Script.isPalindromic
val n : int
val isAnagram : (string -> bool)
val s : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
System.String.ToCharArray() : char []
System.String.ToCharArray(startIndex: int, length: int) : char []
module Array

from Microsoft.FSharp.Collections
val rev : array:'T [] -> 'T []

Full name: Microsoft.FSharp.Collections.Array.rev
val filter : predicate:('T -> bool) -> list:'T list -> 'T list

Full name: Microsoft.FSharp.Collections.List.filter
val max : list:'T list -> 'T (requires comparison)

Full name: Microsoft.FSharp.Collections.List.max
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn

More information

Link:http://fssnip.net/12
Posted:6 years ago
Author:Nick Canzoneri
Tags: sequence , project euler problem