Sha256: dbba47610c6fcdcd72d5155133e343f191095cf7a6be553fbfa22dfe9088c58d

Contents?: true

Size: 893 Bytes

Versions: 77

Compression:

Stored size: 893 Bytes

Contents

module SaddlePoints

let saddlePoints (matrix: int list list) = 
    match matrix with
    | []   -> []
    | [[]] -> []
    | _ ->
        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

77 entries across 77 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/saddle-points/Example.fs