-
-
Save narimiran/ccc87223aeb319115fe3628a2cf4d2dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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