Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,68 @@
import math
randomize()
type
TBoolArray = array[0..30, bool] # an array that is indexed with 0..10
TSymbols = tuple[on: char , off: char]
const
num_turns = 20
symbols:TSymbols = ('#','_')
proc `==` (x:TBoolArray,y:TBoolArray): bool =
if len(x) != len(y):
return False
for i in 0..(len(x)-1):
if x[i] != y[i]:
return False
return True
proc count_neighbours(map:TBoolArray , tile:int):int =
result = 0
if tile != len(map)-1 and map[tile+1]:
result += 1
if tile != 0 and map[tile-1]:
result += 1
proc print_map(map:TBoolArray, symbols:TSymbols) =
for i in map:
if i:
write(stdout,symbols[0])
else:
write(stdout,symbols[1])
write(stdout,"\n")
proc random_map(): TBoolArray =
var map = [False,False,False,False,False,False,False,False,False,False,False,
False,False,False,False,False,False,False,False,False,False,False,
False,False,False,False,False,False,False,False,False]
for i in 0..(len(map)-1):
map[i] = bool(random(2))
return map
proc fixed_map(): TBoolArray =
var map = [False,True,True,True,False,True,True,False,True,False,True,
False,True,False,True,False,False,True,False,False,False,False,
False,False,False,False,False,False,False,False,False]
return map
#make the map
var map:TBoolArray
#map = random_map() # uncomment for random start
map = fixed_map()
print_map(map,symbols)
for i in 0..num_turns:
var new_map = map
for j in 0..(len(map)-1):
if map[j]:
if count_neighbours(map, j) == 2 or
count_neighbours(map, j) == 0:
new_map[j] = False
else:
if count_neighbours(map, j) == 2:
new_map[j] = True
if new_map == map:
print_map(map,symbols)
break
map = new_map
print_map(map,symbols)

View file

@ -0,0 +1,26 @@
const
s_init: string = "_###_##_#_#_#_#__#__"
arrLen: int = 20
var q0: string = s_init & repeatChar(arrLen-20,'_')
var q1: string = q0
proc life(s:string): char =
var str: string = s
if len(normalize(str)) == 2: # normalize eliminates underscores
return '#'
return '_'
proc evolve(q: string): string =
result = repeatChar(arrLen,'_')
#result[0] = '_'
for i in 1 .. q.len-1:
result[i] = life(substr(q & '_',i-1,i+1))
echo(q1)
q1 = evolve(q0)
echo(q1)
while q1 != q0:
q0 = q1
q1 = evolve(q0)
echo(q1)