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,13 @@
proc lcs(x, y): string =
if x == "" or y == "":
return ""
if x[0] == y[0]:
return x[0] & lcs(x[1..x.high], y[1..y.high])
let a = lcs(x, y[1..y.high])
let b = lcs(x[1..x.high], y)
result = if a.len > b.len: a else: b
echo lcs("1234", "1224533324")
echo lcs("thisisatest", "testing123testing")

View file

@ -0,0 +1,28 @@
proc lcs(a, b): string =
var ls = newSeq[seq[int]] a.len+1
for i in 0 .. a.len:
ls[i].newSeq b.len+1
for i, x in a:
for j, y in b:
if x == y:
ls[i+1][j+1] = ls[i][j] + 1
else:
ls[i+1][j+1] = max(ls[i+1][j], ls[i][j+1])
result = ""
var x = a.len
var y = b.len
while x > 0 and y > 0:
if ls[x][y] == ls[x-1][y]:
dec x
elif ls[x][y] == ls[x][y-1]:
dec y
else:
assert a[x-1] == b[y-1]
result = a[x-1] & result
dec x
dec y
echo lcs("1234", "1224533324")
echo lcs("thisisatest", "testing123testing")