-
Notifications
You must be signed in to change notification settings - Fork 0
/
countdown.nim
56 lines (38 loc) · 1018 Bytes
/
countdown.nim
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import terminal, os, strutils
import flatty
import supersnappy
type Big = array[5, string]
const numbers_compressed = slurp("numbers.bin")
let numbers = numbers_compressed.uncompress().fromFlatty(array[10, Big])
const padding = " "
proc `$`(b: seq[Big]): string {.inline.} =
for i in 0..4:
for number in b:
result &= number[i]
result &= padding & "\n"
proc toBig(n: int): string {.inline.} =
var
bigDigits: seq[Big] = @[]
temp = n
while temp != 0:
bigDigits.insert(numbers[temp mod 10])
temp = int(temp/10)
return $bigDigits
if paramCount() < 1:
quit(0)
var counter: int
try:
counter = paramStr(1).parseint()
except ValueError:
stderr.writeLine("The argument '" & paramStr(1) & "' is not a valid integer.")
quit(1)
if counter < 0:
stderr.writeLine("Argument must be positive")
quit(1)
while counter != 0:
echo toBig(counter)
sleep(1000)
cursorUp(6)
counter -= 1
echo $(@[[padding, padding, padding, padding, padding]])
cursorUp(6)