aboutsummaryrefslogtreecommitdiff
path: root/challenge-277/deadmarshal/ruby
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2024-07-10 11:48:19 +0330
committerdeadmarshal <adeadmarshal@gmail.com>2024-07-10 11:48:19 +0330
commit1701193c04567d9f969f0c3eeb21d20f29c282a1 (patch)
tree37790012507ac6aaf8c1a02355fd128b0005f86d /challenge-277/deadmarshal/ruby
parent96580cd62594876fa534d57eb553637433c8ba04 (diff)
downloadperlweeklychallenge-club-1701193c04567d9f969f0c3eeb21d20f29c282a1.tar.gz
perlweeklychallenge-club-1701193c04567d9f969f0c3eeb21d20f29c282a1.tar.bz2
perlweeklychallenge-club-1701193c04567d9f969f0c3eeb21d20f29c282a1.zip
TWC277
Diffstat (limited to 'challenge-277/deadmarshal/ruby')
-rw-r--r--challenge-277/deadmarshal/ruby/ch-1.rb15
-rw-r--r--challenge-277/deadmarshal/ruby/ch-2.rb9
2 files changed, 24 insertions, 0 deletions
diff --git a/challenge-277/deadmarshal/ruby/ch-1.rb b/challenge-277/deadmarshal/ruby/ch-1.rb
new file mode 100644
index 0000000000..1f27e056d0
--- /dev/null
+++ b/challenge-277/deadmarshal/ruby/ch-1.rb
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+def count_common(arr1,arr2)
+ h = Hash.new(0)
+ (arr1 + arr2).each {|e| h[e] += 1 }
+ (h.values.select{|e| e == 2}).size
+end
+
+p count_common(['Perl','is','my','friend'],
+ ['Perl','and','Raku','are','friend'])
+p count_common(['Perl','and','Python','are','very','similar'],
+ ['Python','is','top','in','guest','languages'])
+p count_common(['Perl','is','imperative','Lisp','is','functional'],
+ ['Crystal','is','similar','to','Ruby'])
+
diff --git a/challenge-277/deadmarshal/ruby/ch-2.rb b/challenge-277/deadmarshal/ruby/ch-2.rb
new file mode 100644
index 0000000000..f7137c59c7
--- /dev/null
+++ b/challenge-277/deadmarshal/ruby/ch-2.rb
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+
+def strong_pairs(arr)
+ (arr.uniq.combination(2).select{|e| (e[0] - e[1]).abs < e.min}).size
+end
+
+p strong_pairs([1,2,3,4,5])
+p strong_pairs([5,7,1,7])
+