1 people like it.
Like the snippet!
Project Euler #4
My take at Project Euler #4
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
|
[<RequireQualifiedAccess>]
module Array =
[<RequireQualifiedAccess>]
module Parallel =
let filter predicate array =
array |> Array.Parallel.choose (fun x -> if predicate x then Some x else None)
module NumericLiteralG =
let inline FromZero () = LanguagePrimitives.GenericZero
let inline FromOne () = LanguagePrimitives.GenericOne
let inline isNumPalindrome number =
let ten =
let two = 1G + 1G
let three = two + 1G
let five = three + two
five + five
let hundred = ten * ten
let rec findHighDiv div =
let div' = div * ten
match number / div' with
| x when x = 0G -> div
| _ -> findHighDiv div'
let rec impl n = function
| x when x = 0G -> true
| div -> match n / div, n % ten with
| a, b when a <> b -> false
| _ -> impl (n % div / ten) (div / hundred)
impl number (findHighDiv 1G)
Array.Parallel.init 900 ((+) 100 >> fun n -> Array.init (1000 - n) ((+) n >> (*) n))
|> Array.concat
|> Array.Parallel.filter isNumPalindrome
|> Array.max
|> stdout.WriteLine
|
Multiple items
type RequireQualifiedAccessAttribute =
inherit Attribute
new : unit -> RequireQualifiedAccessAttribute
Full name: Microsoft.FSharp.Core.RequireQualifiedAccessAttribute
--------------------
new : unit -> RequireQualifiedAccessAttribute
module Array
from Microsoft.FSharp.Collections
module Parallel
from Script.Array
val filter : predicate:('a -> bool) -> array:'a [] -> 'a []
Full name: Script.Array.Parallel.filter
val predicate : ('a -> bool)
Multiple items
val array : 'a []
--------------------
type 'T array = 'T []
Full name: Microsoft.FSharp.Core.array<_>
module Parallel
from Microsoft.FSharp.Collections.ArrayModule
val choose : chooser:('T -> 'U option) -> array:'T [] -> 'U []
Full name: Microsoft.FSharp.Collections.ArrayModule.Parallel.choose
val x : 'a
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val FromZero : unit -> 'a (requires member get_Zero)
Full name: Script.NumericLiteralG.FromZero
module LanguagePrimitives
from Microsoft.FSharp.Core
val GenericZero<'T (requires member get_Zero)> : 'T (requires member get_Zero)
Full name: Microsoft.FSharp.Core.LanguagePrimitives.GenericZero
val FromOne : unit -> 'a (requires member get_One)
Full name: Script.NumericLiteralG.FromOne
val GenericOne<'T (requires member get_One)> : 'T (requires member get_One)
Full name: Microsoft.FSharp.Core.LanguagePrimitives.GenericOne
val isNumPalindrome : number:'a -> bool (requires member ( / ) and member ( % ) and member ( % ) and member get_One and member ( / ) and member get_Zero and member ( * ) and equality and member ( * ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_Zero and equality)
Full name: Script.isNumPalindrome
val number : 'a (requires member ( / ) and member ( % ) and member ( % ) and member get_One and member ( / ) and member get_Zero and member ( * ) and equality and member ( * ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_Zero and equality)
val ten : 'd (requires member ( * ) and member ( * ) and member ( % ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member ( / ) and member get_One and member get_Zero and member ( % ) and member ( / ) and equality and member get_Zero and equality)
val two : 'g (requires member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member ( + ) and member ( * ) and member ( * ) and member ( % ) and member ( / ) and member ( / ) and member get_One and member get_Zero and member ( % ) and member ( / ) and equality and member get_Zero and equality)
val three : 'f (requires member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member ( + ) and member ( * ) and member ( * ) and member ( % ) and member ( / ) and member ( / ) and member get_One and member get_Zero and member ( % ) and member ( / ) and equality and member get_Zero and equality)
val five : 'e (requires member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member ( * ) and member ( * ) and member ( % ) and member ( / ) and member ( / ) and member get_One and member get_Zero and member ( % ) and member ( / ) and equality and member get_Zero and equality)
val hundred : 'c (requires member ( / ) and member ( * ) and member ( * ) and member ( % ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_One and member get_Zero and member ( % ) and member ( / ) and equality and member get_Zero and equality)
val findHighDiv : ('b -> 'b) (requires member get_One and member ( / ) and member get_Zero and member ( % ) and member ( / ) and member ( * ) and equality and member ( * ) and member ( % ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_Zero and equality)
val div : 'b (requires member get_One and member ( / ) and member get_Zero and member ( % ) and member ( / ) and member ( * ) and equality and member ( * ) and member ( % ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_Zero and equality)
val div' : 'b (requires member get_One and member ( / ) and member get_Zero and member ( % ) and member ( / ) and member ( * ) and equality and member ( * ) and member ( % ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_Zero and equality)
val x : 'k (requires member get_Zero and equality and member ( / ) and member ( % ) and member ( % ) and member get_One and member ( / ) and member get_Zero and member ( * ) and equality and member ( * ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One)
val impl : ('a -> 'b -> bool) (requires member ( / ) and member ( % ) and member ( % ) and member get_One and member ( / ) and member get_Zero and member ( * ) and equality and member ( * ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_Zero and equality)
val n : 'a (requires member ( / ) and member ( % ) and member ( % ) and member get_One and member ( / ) and member get_Zero and member ( * ) and equality and member ( * ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_Zero and equality)
val x : 'b (requires member get_One and member ( / ) and member get_Zero and member ( % ) and member ( / ) and member ( * ) and equality and member ( * ) and member ( % ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One and member get_Zero and equality)
val a : 'k (requires member get_Zero and equality and member ( / ) and member ( % ) and member ( % ) and member get_One and member ( / ) and member get_Zero and member ( * ) and equality and member ( * ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One)
val b : 'k (requires member get_Zero and equality and member ( / ) and member ( % ) and member ( % ) and member get_One and member ( / ) and member get_Zero and member ( * ) and equality and member ( * ) and member ( / ) and member ( + ) and member ( + ) and member ( + ) and member get_One and member ( + ) and member get_One and member get_One)
Multiple items
module Array
from Script
--------------------
module Array
from Microsoft.FSharp.Collections
Multiple items
module Parallel
from Script.Array
--------------------
module Parallel
from Microsoft.FSharp.Collections.ArrayModule
val init : count:int -> initializer:(int -> 'T) -> 'T []
Full name: Microsoft.FSharp.Collections.ArrayModule.Parallel.init
val n : int
val init : count:int -> initializer:(int -> 'T) -> 'T []
Full name: Microsoft.FSharp.Collections.Array.init
val concat : arrays:seq<'T []> -> 'T []
Full name: Microsoft.FSharp.Collections.Array.concat
val max : array:'T [] -> 'T (requires comparison)
Full name: Microsoft.FSharp.Collections.Array.max
val stdout<'T> : System.IO.TextWriter
Full name: Microsoft.FSharp.Core.Operators.stdout
More information