Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@verus
Created February 6, 2012 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verus/1750056 to your computer and use it in GitHub Desktop.
Save verus/1750056 to your computer and use it in GitHub Desktop.
def haar l
def aux l, m, n
if l.size == 1
l + n
elsif l.size == 0
aux m, [], n
elsif l.size > 1
aux l[2..-1] , [l[0] + l[1]] + m, [l[0] - l[1]] + n
else
[]
end
end
aux l, [], []
end
p ary = (1..10).map{ rand(100) }
#ary = [-1, 2]
p ary.inject(:+)
p haar(ary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment