Vladar

seven slash display (stdout version)

Jun 13th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 1.08 KB | None | 0 0
  1. import os, terminal
  2.  
  3. iterator digit(c: char): string =
  4.   var i = 0
  5.   while i < 3:
  6.     case i:
  7.     of 0:
  8.       case c:
  9.       of '0', '2', '3', '7', '8', '9': yield "/\\"
  10.       of '1', '4': yield " \\"
  11.       of '5', '6': yield "/"
  12.       else: yield ""
  13.     of 1:
  14.       case c:
  15.       of '0': yield "\\ \\"
  16.       of '1', '7': yield "  \\"
  17.       of '2', '-': yield " /"
  18.       of '3': yield " /\\"
  19.       of '4', '5', '6', '8', '9': yield "\\/\\"
  20.       else: yield ""
  21.     of 2:
  22.       case c:
  23.       of '0', '2', '6', '8': yield " \\/"
  24.       of '3', '5', '9': yield "  /"
  25.       else: yield ""
  26.     else: discard
  27.     inc i
  28.  
  29. proc display(s: string) =
  30.   var
  31.     offset = (s.len)*2
  32.     index = s.high
  33.   if s[0] notin {'-', '0'..'9'}:
  34.     echo "Error: Not a number."
  35.     return
  36.   for c in s[1..^1]:
  37.     if c notin {'0'..'9'}:
  38.       echo "Error: Not a number."
  39.       return
  40.   while index >= 0:
  41.     for line in digit(s[index]):
  42.       terminal.setCursorXPos(offset)
  43.       echo line
  44.     terminal.cursorUp()
  45.     dec index
  46.     offset -= 2
  47.  
  48. if paramCount() > 0:
  49.   display(paramStr(1))
Advertisement
Add Comment
Please, Sign In to add comment