Created
September 5, 2014 19:54
-
-
Save mostlyerror/c3a9463f474ce96d7693 to your computer and use it in GitHub Desktop.
Hackerrank cut_the_sticks
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
n = gets.chomp.to_i | |
sticks = gets.chomp.split.map(&:to_i) | |
until sticks.empty? do | |
new_sticks = sticks.map {|x| x - sticks.min} | |
cut = 0 | |
new_sticks.each_index {|i| cut += 1 if new_sticks[i] != sticks[i] } | |
p cut | |
sticks = new_sticks.reject(&:zero?) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
revised solution: