omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / eliuds-eggs / .meta / example.om
| 1 | note Exercism-style exercise "eliuds-eggs": https://exercism.org/tracks/python/exercises/eliuds-eggs |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note eggcount is the number of 1 bits in the binary representation of n. |
| 4 | note Check it with: sh exercise.sh exercises/eliuds-eggs |
| 5 | om2 |
| 6 | fn eggcount n ulong to ulong |
| 7 | c = ulong 0 |
| 8 | v = n |
| 9 | while ne v 0 bound 64 |
| 10 | c = add c and v 1 |
| 11 | v = shr v 1 |
| 12 | end |
| 13 | ret c |
| 14 | end |