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 / si / rosetta / exercises / largest-series-product / .meta / example.om

43 lines · 940 bytes Raw Blame History
1note Exercism-style exercise "largest-series-product": https://exercism.org/tracks/python/exercises/largest-series-product
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note largestproduct is the largest product of span adjacent decimal digits of s (1 for span 0); or
4note -1 when span is negative, -2 when span is longer than s, -3 when s holds a non-digit.
5note Check it with: sh exercise.sh exercises/largest-series-product
6om2
7fn alldigits s view uchar * to bool
8for i ulong len s
9c = get s i
10if or lt c 48 gt c 57
11ret false
12end
13end
14ret true
15end
16fn window s view uchar * k ulong w ulong to long
17p = long 1
18for j ulong w
19p = mul p long sub get s add k j 48
20end
21ret p
22end
23fn largestproduct s view uchar * span long to long
24if lt span 0
25ret -1
26end
27w = ulong span
28n = len s
29if gt w n
30ret -2
31end
32if not alldigits s
33ret -3
34end
35best = long 0
36for k ulong add sub n w 1
37p = window s k w
38if gt p best
39best = p
40end
41end
42ret best
43end