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.159 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.158 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.157 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.156 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.155 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.154 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.153 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.152 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.151 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.150 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.149 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.148 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.147 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.146 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.145 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.144 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.143 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.142 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.141 tracks/fsharp/exercises/saddle-points/Example.fs
trackler-2.2.1.140 tracks/fsharp/exercises/saddle-points/Example.fs