Sha256: df54d4521532b707322a0c0ab945b65dbc4d18ef5e3e31b4fbe6d4c878d98652

Contents?: true

Size: 766 Bytes

Versions: 319

Compression:

Stored size: 766 Bytes

Contents

module SaddlePoints

let saddlePoints (matrix: int list list) = 
    let rec transpose = function
        | (_::_)::_ as M -> List.map List.head M :: transpose (List.map List.tail M)
        | _ -> []

    let rows = matrix |> List.length
    let cols = matrix |> List.head |> List.length

    let rowsMax = matrix |> List.map List.max
    let colsMin = matrix |> transpose |> List.map List.min

    let rowMax x = rowsMax |> List.item x
    let colMin y = colsMin |> List.item y

    let element x y = matrix |> List.item x |> List.item y
    let isSaddlePoint x y = element x y = rowMax x && element x y = colMin y

    [for x in 0 .. (rows - 1) do
        for y in 0 .. (cols - 1) do            
            if isSaddlePoint x y then
                yield (x, y)]

Version data entries

319 entries across 319 versions & 1 rubygems

Version Path
trackler-2.0.6.3 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.6.2 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.6.1 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.6.0 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.18 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.17 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.16 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.15 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.14 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.13 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.12 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.11 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.10 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.9 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.8 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.7 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.6 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.5 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.4 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.0.5.3 tracks/fsharp/exercises/saddle-points/Example.fs