Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
36
Task/Wireworld/Nim/wireworld.nim
Normal file
36
Task/Wireworld/Nim/wireworld.nim
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import strutils, os
|
||||
|
||||
var world, world2 = """
|
||||
+-----------+
|
||||
|tH.........|
|
||||
|. . |
|
||||
| ... |
|
||||
|. . |
|
||||
|Ht.. ......|
|
||||
+-----------+"""
|
||||
let h = world.splitLines.len
|
||||
let w = world.splitLines[0].len
|
||||
|
||||
template isH(x, y): int = int(s[i+ w*y + x] == 'H')
|
||||
|
||||
proc next(o: var string, s: string, w: int) =
|
||||
for i, c in s:
|
||||
o[i] = case c
|
||||
of ' ': ' '
|
||||
of 't': '.'
|
||||
of 'H': 't'
|
||||
of '.':
|
||||
if (isH(-1, -1) + isH(0, -1) + isH(1, -1) +
|
||||
isH(-1, 0) + isH(1, 0) +
|
||||
isH(-1, 1) + isH(0, 1) + isH(1, 1)
|
||||
) in 1..2: 'H' else: '.'
|
||||
else: c
|
||||
|
||||
while true:
|
||||
echo world
|
||||
stdout.write "\x1b[",h,"A"
|
||||
stdout.write "\x1b[",w,"D"
|
||||
sleep 100
|
||||
|
||||
world2.next(world, w)
|
||||
swap world, world2
|
||||
Loading…
Add table
Add a link
Reference in a new issue