A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
7
Task/Forward-difference/Ruby/forward-difference-1.rb
Normal file
7
Task/Forward-difference/Ruby/forward-difference-1.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def dif(s)
|
||||
s.each_cons(2).collect { |x, y| y - x }
|
||||
end
|
||||
|
||||
def difn(s, n)
|
||||
n.times.inject(s) { |s, | dif(s) }
|
||||
end
|
||||
2
Task/Forward-difference/Ruby/forward-difference-2.rb
Normal file
2
Task/Forward-difference/Ruby/forward-difference-2.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
p dif([1, 23, 45, 678]) # => [22, 22, 633]
|
||||
p difn([1, 23, 45, 678], 2) # => [0, 611]
|
||||
Loading…
Add table
Add a link
Reference in a new issue