Created
May 19, 2011 14:29
-
-
Save tana/980867 to your computer and use it in GitHub Desktop.
Sleep Sortみたいなの
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
| # 元ネタ: http://dis.4chan.org/read/prog/1295544154 | |
| # Sleep Sortみたいなものを時間待ちも無ければプロセス生成も無い方法で | |
| class A | |
| def initialize(a) | |
| @a = a | |
| @b = a | |
| end | |
| def next | |
| @a = @a - 1 | |
| SleepSort.add(@b) if @a == 0 | |
| end | |
| end | |
| module SleepSort | |
| @list = [] | |
| def SleepSort.add(a) | |
| @list << a | |
| end | |
| def SleepSort.sort(arr) | |
| hoge = [] | |
| arr.each {|a| | |
| hoge << A.new(a) | |
| } | |
| while true | |
| hoge.each {|a| | |
| a.next | |
| } | |
| break if arr.length == @list.length | |
| end | |
| list = @list | |
| @list = [] | |
| return list | |
| end | |
| end | |
| p SleepSort.sort([23,1,53,3,1,3,6,13,3,6,1,3,7,1,3,6,1,3,7,133,63,137]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment