omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / raindrops / .meta / example.om
| 1 | note Exercism-style exercise "raindrops": https://exercism.org/tracks/python/exercises/raindrops |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note convert writes "Pling" if n is divisible by 3, then "Plang" if by 5, then "Plong" if by 7, |
| 4 | note or the decimal digits of n when it is divisible by none of them, into o; returns the length. |
| 5 | note Check it with: sh exercise.sh exercises/raindrops |
| 6 | om2 |
| 7 | text pling "Pling" |
| 8 | text plang "Plang" |
| 9 | text plong "Plong" |
| 10 | fn app o edit uchar * p ulong s view uchar * to ulong |
| 11 | q = p |
| 12 | for i ulong len s |
| 13 | put o q get s i |
| 14 | q = add q 1 |
| 15 | end |
| 16 | ret q |
| 17 | end |
| 18 | fn appnum o edit uchar * p ulong n ulong to ulong |
| 19 | d = new uchar 20 0 |
| 20 | i = ulong 20 |
| 21 | v = n |
| 22 | while true bound 20 |
| 23 | i = sub i 1 |
| 24 | put d i uchar add rem v 10 48 |
| 25 | v = div v 10 |
| 26 | if eq v 0 |
| 27 | break |
| 28 | end |
| 29 | end |
| 30 | ret app o p part d i sub 20 i |
| 31 | end |
| 32 | fn convert n ulong o edit uchar * to ulong |
| 33 | p = ulong 0 |
| 34 | if eq rem n 3 0 |
| 35 | p = app o p pling |
| 36 | end |
| 37 | if eq rem n 5 0 |
| 38 | p = app o p plang |
| 39 | end |
| 40 | if eq rem n 7 0 |
| 41 | p = app o p plong |
| 42 | end |
| 43 | if eq p 0 |
| 44 | p = appnum o p n |
| 45 | end |
| 46 | ret p |
| 47 | end |