aboutsummaryrefslogtreecommitdiff
path: root/challenge-243/deadmarshal/ruby
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2023-11-15 21:53:10 +0330
committerdeadmarshal <adeadmarshal@gmail.com>2023-11-15 21:53:10 +0330
commit7d92a145e089e59f0f830843ba91cd7223bc6c98 (patch)
tree5e0043297d1fde64aa5c75c5e1440c4cbc393389 /challenge-243/deadmarshal/ruby
parentd20e7296170b997b7e690a58b79156f6c81f1cd2 (diff)
downloadperlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.tar.gz
perlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.tar.bz2
perlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.zip
TWC243 extra solutions
Diffstat (limited to 'challenge-243/deadmarshal/ruby')
-rw-r--r--challenge-243/deadmarshal/ruby/ch1.rb15
-rw-r--r--challenge-243/deadmarshal/ruby/ch2.rb15
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])
+