Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created January 5, 2016 13:35
Show Gist options
  • Save chuck0523/1841b447b99816f58dcd to your computer and use it in GitHub Desktop.
Save chuck0523/1841b447b99816f58dcd to your computer and use it in GitHub Desktop.
patern = [
['a', 'b', 'c'],
['b', 'c', 'a'],
['c', 'a', 'b']
]
n = gets.to_i
str = gets
if n % 2 === 0 || str[str.length / 2 - 1] != 'b'
puts -1
exit
end
n.times do |t|
if str[t] != patern[n % 3][t % 3]
puts -1
exit
end
end
puts str.length / 2 - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment