Sha256: ded70161e901a05ef65f82452ea86d049a9cd793113352bf572b3112e98f47b7

Contents?: true

Size: 699 Bytes

Versions: 396

Compression:

Stored size: 699 Bytes

Contents

module PythagoreanTriplet

open System

type Triplet = { x: int; y: int; z: int }

let private square x = x * x
let private squareRoot x = Math.Sqrt(x |> float) |> Math.Floor |> int

let triplet x y z =     
    match [x; y; z] |> List.sort with
    | x'::y'::z'::_ -> { x = x' ; y = y'; z = z' }
    | _ -> failwith "Should never get here"

let isPythagorean triplet = square triplet.x + square triplet.y = square triplet.z

let pythagoreanTriplets min max = 
    [for x in min .. (max - 2) do
        for y in x .. (max - 1) do
            let target = square x + square y
            let z = squareRoot target
            if z <= max && square z = target then
                yield triplet x y z]

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.0.0.5 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.0.4 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.0.3 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.0.2 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.0.1 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.0.0 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.4.1 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.4.0 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.3.0 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.2.1 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.2.0 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.1.2 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.1.1 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.1.0 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.0.1 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-1.0.0 tracks/fsharp/exercises/pythagorean-triplet/Example.fs