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.6.20 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.19 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.18 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.17 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.16 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.15 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.14 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.13 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.12 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.11 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.10 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.9 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.8 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.7 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.6 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.5 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.4 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.3 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.2 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.6.1 tracks/fsharp/exercises/pythagorean-triplet/Example.fs