Created
September 27, 2013 01:27
-
-
Save syusui-s/6722989 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
| 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