omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / si / rosetta / exercises / queen-attack / .meta / example.om
| 1 | note Exercism-style exercise "queen-attack": https://exercism.org/tracks/python/exercises/queen-attack |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note Rows and columns run 0 .. 7. create checks one queen's position: 0 valid, 1 row negative, |
| 4 | note 2 row past the board, 3 column negative, 4 column past the board (row checked first). |
| 5 | note canattack is true when queens at (wr, wc) and (br, bc) share a row, column or diagonal. |
| 6 | note Check it with: sh exercise.sh exercises/queen-attack |
| 7 | om2 |
| 8 | fn create row long col long to int |
| 9 | if lt row 0 |
| 10 | ret 1 |
| 11 | end |
| 12 | if gt row 7 |
| 13 | ret 2 |
| 14 | end |
| 15 | if lt col 0 |
| 16 | ret 3 |
| 17 | end |
| 18 | if gt col 7 |
| 19 | ret 4 |
| 20 | end |
| 21 | ret 0 |
| 22 | end |
| 23 | fn canattack wr long wc long br long bc long to bool |
| 24 | dr = sub wr br |
| 25 | dc = sub wc bc |
| 26 | if lt dr 0 |
| 27 | dr = neg dr |
| 28 | end |
| 29 | if lt dc 0 |
| 30 | dc = neg dc |
| 31 | end |
| 32 | ret or or eq dr 0 eq dc 0 eq dr dc |
| 33 | end |