Skip to content

Instantly share code, notes, and snippets.

@tenebrousedge
Created May 23, 2017 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenebrousedge/209f68faf7fb0a1c9fcae0b128453004 to your computer and use it in GitHub Desktop.
Save tenebrousedge/209f68faf7fb0a1c9fcae0b128453004 to your computer and use it in GitHub Desktop.
HackerRank - Beautiful Quadruples
#!/bin/ruby
A = gets.strip.split(' ').map(&:to_i)
Array.class_eval do
def valid?
(0..3).all? {|i| 1 <= self[i] && self[i] <= A[i] }
end
end
puts A.repeated_permutation(4).map(&:sort).uniq.select {|e| !(e.reduce(:^).zero?) && e.valid?}.length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment