diff options
Diffstat (limited to 'challenge-199/robert-dicicco/ruby/ch-2.rb')
| -rw-r--r-- | challenge-199/robert-dicicco/ruby/ch-2.rb | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/challenge-199/robert-dicicco/ruby/ch-2.rb b/challenge-199/robert-dicicco/ruby/ch-2.rb new file mode 100644 index 0000000000..624000a2b4 --- /dev/null +++ b/challenge-199/robert-dicicco/ruby/ch-2.rb @@ -0,0 +1,81 @@ +#!/usr/bin/env ruby + +=begin + +AUTHOR: Robert DiCicco + +DATE : 2023-01-14 + +Challenge 199 Good Triplets ( Ruby ) + +=end + + + +list = [3,0,1,1,9,7] + + + +$x = 7 + +$y = 2 + +$z = 3 + + + +seen = Hash.new + + + +list.permutation(3).to_a.each do |suba| + + if seen.has_key?(suba) + + next + + else + + seen[suba] = 1 + + x1 = list.find_index(suba[0]) + + x2 = list.find_index(suba[1]) + + x3 = list.find_index(suba[2]) + + if x1 > x2 || x2 > x3 || x1 > x3 + + next + + end + + if (suba[0] - suba[1]).abs > $x || (suba[1] - suba[2]).abs > $y || (suba[0] - suba[2]).abs > $z + + next + + else + + puts("#{suba}") + + end + + end + +end + + + +=begin + +SAMPLE OUTPUT + +ruby .\GoodTriplets.rb + +[3, 0, 1] + +[3, 1, 1] + +[0, 1, 1] + +=end |
