Skip to content

Instantly share code, notes, and snippets.

@inage
Created December 7, 2013 14:04
Show Gist options
  • Select an option

  • Save inage/7841759 to your computer and use it in GitHub Desktop.

Select an option

Save inage/7841759 to your computer and use it in GitHub Desktop.
Best Cow Line (POJ 3617)
## Best Cow Line (POJ 3617)
## http://rubyfiddle.com/riddles/f878f
s = "ACDBCB"
n = s.length #文字の長さ。"ACDBCB"の場合は6。
t = ""
i=0
loop do
break if s.size == 1
case s[0..i] <=> s[s.size-1-i..s.size-1]
when 1
t += s.slice!(s.size-1-i..s.size-1).reverse
i=0
when -1
t += s.slice!(0..i)
i=0
when 0
i += 1
end
end
puts t+s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment