Skip to content

Instantly share code, notes, and snippets.

@narimiran
Created March 28, 2018 15:58
Show Gist options
  • Save narimiran/ccc87223aeb319115fe3628a2cf4d2dc to your computer and use it in GitHub Desktop.
Save narimiran/ccc87223aeb319115fe3628a2cf4d2dc to your computer and use it in GitHub Desktop.
type Parsed = object
first: char
second: int
xa: int
xb: int
pa: char
pb: char
proc cleanUp(instructions: seq[string]): seq[Parsed] =
result = @[]
var
element: Parsed
first: char
rem: string
x: seq[string]
a, b: int
for instr in instructions:
first = instr[0]
rem = instr[1 .. instr.high]
case first
of 's':
element = Parsed(first: first, second: rem.parseInt)
of 'x':
x = rem.split('/')
a = x[0].parseInt
b = x[1].parseInt
element = Parsed(first: first, xa: a, xb: b)
of 'p':
element = Parsed(first: first, pa: rem[0], pb: rem[^1])
else: discard
result.add(element)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment