-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.lean
30 lines (27 loc) · 1.02 KB
/
Main.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import «LeanSorting».Total
import «LeanSorting».Unsafe
import «LeanSorting».Partial
import Mathlib.Data.BinaryHeap
def getLines : IO (Array String) := do
let stdin ← IO.getStdin
let mut lines : Array String := #[]
let mut currLine ← stdin.getLine
while !currLine.isEmpty do
-- Drop trailing newline
lines := lines.push (currLine.dropRight 1)
currLine ← stdin.getLine
pure lines
def mainSort (sort : Array String → Array String) : IO Unit := do
let lines ← getLines
for line in sort lines do
IO.println line
def main (args : List String) : IO UInt32 := do
match args with
| ["--mergeSort"] => mainSort Array.mergeSort; pure 0
| ["--mergeSortPartial"] => mainSort Array.mergeSortPartial; pure 0
| ["--mergeSortUnsafe"] => mainSort Array.mergeSortUnsafe; pure 0
| ["--heapSort"] => mainSort (Array.heapSort · (· < ·)); pure 0
| ["--qsort"] => mainSort (Array.qsort · (· < ·)); pure 0
| _ =>
IO.println "Expected single argument, either \"--msort\" or \"--qsort\""
pure 1