Skip to content

Instantly share code, notes, and snippets.

@mattmanning
Created August 2, 2012 00:14
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 mattmanning/3231802 to your computer and use it in GitHub Desktop.
Save mattmanning/3231802 to your computer and use it in GitHub Desktop.
class Array
def inc(val)
map {|e| e + val}
end
end
def add1(arr, val, n)
case n <=> 0
when 0
arr.inc(val)
when 1
arr[0..(n-1)].inc(val) + arr[n..-1]
when -1
arr[0..(n-1)] + arr[(n)..-1].inc(val)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment