diff options
Diffstat (limited to 'challenge-243/deadmarshal/ruby')
| -rw-r--r-- | challenge-243/deadmarshal/ruby/ch1.rb | 15 | ||||
| -rw-r--r-- | challenge-243/deadmarshal/ruby/ch2.rb | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-243/deadmarshal/ruby/ch1.rb b/challenge-243/deadmarshal/ruby/ch1.rb new file mode 100644 index 0000000000..cfc0a26c39 --- /dev/null +++ b/challenge-243/deadmarshal/ruby/ch1.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +def reverse_pairs(arr) + count = 0 + (0...arr.length-1).each do |i| + (i+1...arr.length).each do |j| + count += 1 if arr[i] > (2 * arr[j]) + end + end + return count +end + +p reverse_pairs([1,3,2,3,1]) +p reverse_pairs([2,4,3,5,1]) + diff --git a/challenge-243/deadmarshal/ruby/ch2.rb b/challenge-243/deadmarshal/ruby/ch2.rb new file mode 100644 index 0000000000..8f6fd403ef --- /dev/null +++ b/challenge-243/deadmarshal/ruby/ch2.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +def floor_sum(arr) + sum = 0 + (0...arr.length).each do |i| + (0...arr.length).each do |j| + sum += (arr[i] / arr[j]) + end + end + return sum +end + +p floor_sum([2,5,9]) +p floor_sum([7,7,7,7,7,7,7]) + |
