Created
May 23, 2017 23:30
-
-
Save tenebrousedge/209f68faf7fb0a1c9fcae0b128453004 to your computer and use it in GitHub Desktop.
HackerRank - Beautiful Quadruples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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