Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
15
Task/Sort-three-variables/Nim/sort-three-variables.nim
Normal file
15
Task/Sort-three-variables/Nim/sort-three-variables.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
proc sortThree[T](a, b, c: var T) =
|
||||
# Bubble sort, why not?
|
||||
while not (a <= b and b <= c):
|
||||
if a > b: swap a, b
|
||||
if b > c: swap b, c
|
||||
|
||||
proc testWith[T](a, b, c: T) =
|
||||
var (x, y, z) = (a, b, c)
|
||||
echo "Before: ", x, ", ", y, ", ", z
|
||||
sortThree(x, y, z)
|
||||
echo "After: ", x, ", ", y, ", ", z
|
||||
|
||||
testWith(6, 4, 2)
|
||||
testWith(0.9, -37.1, 4.0)
|
||||
testWith("lions", "tigers", "bears")
|
||||
Loading…
Add table
Add a link
Reference in a new issue