interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tests / compiler / progs / isort.osc

39 lines · 962 bytes Raw Blame History
1// entry: sort_main
2// expect-run: sort_main 1 1 1 -> 255868620
3// insertion sort over own [i64; 16] filled from the parameters.
4fn fill(a: &mut [i64; 16], s: i64, m: i64, t: i64) {
5 let mut x: i64 = s;
6 for i in 0 .. 16 {
7 x = (x * m + t) % 1000003;
8 a[i] = x;
9 }
10}
11
12fn sort(a: &mut [i64; 16]) {
13 for i in 1 .. 16 {
14 let key: i64 = a[i];
15 let mut j: i64 = i - 1;
16 while j >= 0 && a[j] > key bound 16 {
17 a[j + 1] = a[j];
18 j = j - 1;
19 }
20 a[j + 1] = key;
21 }
22}
23
24fn is_sorted(a: &[i64; 16]) -> bool {
25 for i in 1 .. 16 {
26 if a[i - 1] > a[i] { return false; }
27 }
28 return true;
29}
30
31fn sort_main(s: i32, m: i16, t: i32) -> i64 {
32 let a: own [i64; 16] = alloc(0);
33 fill(&mut a, s as i64, m as i64, t as i64);
34 sort(&mut a);
35 if !is_sorted(&a) { return -1; }
36 let mut h: i64 = 0;
37 for i in 0 .. 16 { h = (h * 31 + a[i]) % 1000000007; }
38 return h;
39}