Created
September 13, 2013 13:07
-
-
Save miry/6550449 to your computer and use it in GitHub Desktop.
HackerRank: Sherlock and The Beast
This file contains hidden or 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
def validate(count) | |
result = nil | |
count.downto(0).each do |j| | |
i = count - j | |
if j == count && j % 3 == 0 | |
result = Array.new(j, 5) | |
elsif i % 5 == 0 && j % 3 == 0 | |
result = Array.new(j, 5) + Array.new(i, 3) | |
elsif i == count && i % 5 == 0 | |
result = Array.new(i, 3) | |
end | |
break if result | |
end | |
if result.nil? | |
puts -1 | |
else | |
puts result.join() | |
end | |
end | |
number = gets.to_i | |
number.times do |i| | |
validate gets.to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment