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.0 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.18 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.17 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.16 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.15 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.14 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.13 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.12 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.11 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.10 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.9 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.8 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.7 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.6 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.5 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.4 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.3 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.2 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.1 tracks/fsharp/exercises/pythagorean-triplet/Example.fs
trackler-2.0.5.0 tracks/fsharp/exercises/pythagorean-triplet/Example.fs