Skip to content

Instantly share code, notes, and snippets.

@miry
Created September 13, 2013 13:07
Show Gist options
  • Save miry/6550449 to your computer and use it in GitHub Desktop.
Save miry/6550449 to your computer and use it in GitHub Desktop.
HackerRank: Sherlock and The Beast
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