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 / all-your-base / .meta / example.om
| 1 | note Exercism-style exercise "all-your-base": https://exercism.org/tracks/python/exercises/all-your-base |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note rebase converts the number whose digits ds are in base ib (most significant first) to base ob, |
| 4 | note writes its digits into o and returns how many (the number 0 is the single digit 0); or -1 when |
| 5 | note ib < 2, -3 when ob < 2, -2 when a digit is outside 0 .. ib-1. |
| 6 | note Check it with: sh exercise.sh exercises/all-your-base |
| 7 | om2 |
| 8 | fn rebase ib long ds view long * ob long o edit long * to long |
| 9 | if lt ib 2 |
| 10 | ret -1 |
| 11 | end |
| 12 | if lt ob 2 |
| 13 | ret -3 |
| 14 | end |
| 15 | v = long 0 |
| 16 | for i ulong len ds |
| 17 | d = get ds i |
| 18 | if or lt d 0 ge d ib |
| 19 | ret -2 |
| 20 | end |
| 21 | v = add mul v ib d |
| 22 | end |
| 23 | tmp = new long 64 0 |
| 24 | k = ulong 0 |
| 25 | while true bound 64 |
| 26 | put tmp k rem v ob |
| 27 | k = add k 1 |
| 28 | v = div v ob |
| 29 | if eq v 0 |
| 30 | break |
| 31 | end |
| 32 | end |
| 33 | for j ulong k |
| 34 | put o j get tmp sub sub k 1 j |
| 35 | end |
| 36 | ret long k |
| 37 | end |