Skip to content

Instantly share code, notes, and snippets.

@skoji
Created September 13, 2011 03:27
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 skoji/1213057 to your computer and use it in GitHub Desktop.
Save skoji/1213057 to your computer and use it in GitHub Desktop.
GDD2011JP DevQuiz 一人ゲーム solver
gets.to_i.times do
gets
nums = gets.split(' ').map(&:to_i)
queue = [[nums, 0]]
while !queue.empty?
node, ct = queue.shift
if (node.all? { |x| x % 5 == 0})
puts ct + 1
break
end
if node.any? { |x| (x%5 == 0) && ((x/2)%5 != 0) }
queue << [node.select { |x| x%5 != 0 }, ct + 1]
end
queue << [node.map { |x| x / 2 }, ct + 1]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment