Created
July 10, 2015 03:28
-
-
Save oieioi/cd21fd7610d1a67489ce to your computer and use it in GitHub Desktop.
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
#raw_list = STDIN.gets.chomp.split("\n").collect {|item| item.to_i} | |
raw_list = [] | |
while str = STDIN.gets#.chomp | |
break if str.empty? | |
raw_list.push str.to_i | |
end | |
count_changed = 0 | |
raw_list.each_with_index do |item, index| | |
if item != (index + 1) then | |
item_index = raw_list.find_index(index + 1) | |
raw_list[item_index] = item | |
raw_list[index] = index + 1 | |
count_changed += 1 | |
end | |
end | |
p count_changed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment