interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / all-your-base / .meta / example.om

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