interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / saddle-points / .meta / example.om

38 lines · 1102 bytes Raw Blame History
1note Exercism-style exercise "saddle-points": https://exercism.org/tracks/python/exercises/saddle-points
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note m is a matrix of nr rows and nc columns, row after row. A saddle point is a value that is the
4note largest in its row and the smallest in its column. saddlepoints writes the 1-based row and
5note column of each saddle point into o as pairs, in row-major order, and returns the number of points.
6note Check it with: sh exercise.sh exercises/saddle-points
7om2
8fn isrowmax m view ulong * nc ulong r ulong c ulong to bool
9v = get m add mul r nc c
10for j ulong nc
11if gt get m add mul r nc j v
12ret false
13end
14end
15ret true
16end
17fn iscolmin m view ulong * nr ulong nc ulong r ulong c ulong to bool
18v = get m add mul r nc c
19for i ulong nr
20if lt get m add mul i nc c v
21ret false
22end
23end
24ret true
25end
26fn saddlepoints m view ulong * nr ulong nc ulong o edit ulong * to ulong
27k = ulong 0
28for r ulong nr
29for c ulong nc
30if and isrowmax m nc r c iscolmin m nr nc r c
31put o mul k 2 add r 1
32put o add mul k 2 1 add c 1
33k = add k 1
34end
35end
36end
37ret k
38end