diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-02-26 00:38:09 +0100 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-02-26 00:38:09 +0100 |
| commit | 8bcca9d60c78913ea3a4ed80d04a52f999363135 (patch) | |
| tree | df5129470575c52ccd29abb0d3d6a563c3ed76d0 /challenge-257/barroff/nim | |
| parent | 971ad418c9418efd9eb105cd114387f5ce59d6be (diff) | |
| download | perlweeklychallenge-club-8bcca9d60c78913ea3a4ed80d04a52f999363135.tar.gz perlweeklychallenge-club-8bcca9d60c78913ea3a4ed80d04a52f999363135.tar.bz2 perlweeklychallenge-club-8bcca9d60c78913ea3a4ed80d04a52f999363135.zip | |
feat: add solutions for challenge 257 from BarrOff
Diffstat (limited to 'challenge-257/barroff/nim')
| -rw-r--r-- | challenge-257/barroff/nim/ch_1.nim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-257/barroff/nim/ch_1.nim b/challenge-257/barroff/nim/ch_1.nim new file mode 100644 index 0000000000..a2c799b91f --- /dev/null +++ b/challenge-257/barroff/nim/ch_1.nim @@ -0,0 +1,26 @@ +import std/[sugar, unittest] + +from std/math import sqrt +from std/sequtils import filter, map, toSeq + +# run tests with following command: +# nim c -r ch_1.nim + +func smaller_than_current[T: SomeInteger](ints: openArray[T]): seq[int] = + for i in ints: + let + j: T = i + add(result, len(filter(ints, x => x < j))) + +suite "smaller than current": + test "[5, 2, 1, 6]": + check(smaller_than_current([5, 2, 1, 6]) == @[2, 1, 0, 3]) + + test "[1, 2, 0, 3]": + check(smaller_than_current([1, 2, 0, 3]) == @[1, 2, 0, 3]) + + test "[0, 1]": + check(smaller_than_current([0, 1]) == @[0, 1]) + + test "[9, 4, 9, 2]": + check(smaller_than_current([9, 4, 9, 2]) == @[2, 1, 2, 0]) |
