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.2.1.180 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/pythagorean-triplet/Example.fs