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,18 @@
def merge_sort(a : Array(Int32)) : Array(Int32)
return a if a.size <= 1
m = a.size / 2
lt = merge_sort(a[0 ... m])
rt = merge_sort(a[m .. -1])
return merge(lt, rt)
end
def merge(lt : Array(Int32), rt : Array(Int32)) : Array(Int32)
result = Array(Int32).new
until lt.empty? || rt.empty?
result << (lt.first < rt.first ? lt.shift : rt.shift)
end
return result + lt + rt
end
a = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0]
puts merge_sort(a) # => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]