Skip to content

Instantly share code, notes, and snippets.

@syusui-s
Created September 27, 2013 01:27
Show Gist options
  • Select an option

  • Save syusui-s/6722989 to your computer and use it in GitHub Desktop.

Select an option

Save syusui-s/6722989 to your computer and use it in GitHub Desktop.
やっぱりこのソートも実装しないとね。
ary = [9,2,4,5,1,2,4,5,1,8]
def is_sorted?(array)
arr = array.clone
fst = arr.pop
while not arr.empty? and fst >= (nxt=arr.pop)
fst = nxt
end
return (arr.empty? and fst >= nxt) ? true : false
end
loop do
ary.shuffle!
if is_sorted?(ary)
puts ary.to_s
exit 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment