Created
October 27, 2019 04:14
-
-
Save hopewise/7c349a89238aacf3fd0df0129ae263f1 to your computer and use it in GitHub Desktop.
New Year Chaos, I don't know why it fails at case: `1 2 5 3 7 8 6 4` ?
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
#!/bin/ruby | |
require 'json' | |
require 'stringio' | |
# Complete the minimumBribes function below. | |
def minimumBribes(q) | |
too = false | |
bs = 0 | |
(1..q.count).each do |i| | |
a = q[i-1] | |
brides = a - i | |
#p "#{a} at #{i} is #{brides}" | |
if brides > 2 | |
bs = 0 | |
puts "Too chaotic" | |
break | |
else | |
bs = bs + brides if brides > 0 | |
end | |
end | |
puts (bs) if bs > 0 | |
end | |
t = gets.to_i | |
t.times do |t_itr| | |
n = gets.to_i | |
q = gets.rstrip.split(' ').map(&:to_i) | |
minimumBribes q | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment