omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / acronym / .meta / example.om
| 1 | note Exercism-style exercise "acronym": https://exercism.org/tracks/python/exercises/acronym |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note abbreviate writes the upper-case acronym of phrase s into o and returns its length. Words are |
| 4 | note separated by spaces, hyphens and other punctuation; an apostrophe does not start a new word. |
| 5 | note Check it with: sh exercise.sh exercises/acronym |
| 6 | om2 |
| 7 | fn abbreviate s view uchar * o edit uchar * to ulong |
| 8 | p = ulong 0 |
| 9 | prev = false |
| 10 | for i ulong len s |
| 11 | c = get s i |
| 12 | up = and ge c 65 le c 90 |
| 13 | lo = and ge c 97 le c 122 |
| 14 | if or up lo |
| 15 | if not prev |
| 16 | if lo |
| 17 | c = sub c 32 |
| 18 | end |
| 19 | put o p c |
| 20 | p = add p 1 |
| 21 | end |
| 22 | prev = true |
| 23 | else |
| 24 | prev = eq c 39 |
| 25 | end |
| 26 | end |
| 27 | ret p |
| 28 | end |