Last active
December 16, 2015 08:18
-
-
Save funny-falcon/5404475 to your computer and use it in GitHub Desktop.
This file contains 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
require 'rational' | |
ONE = Rational(1) | |
def draw(arr) | |
print "N = #{arr.size}\n" | |
arr.each_with_index do |ar, i| | |
print "#{i}: (#{ar.size} items)\t#{ar.inspect}\n" | |
end | |
flat = arr.flatten | |
print "\nTotal #{flat.size} items:\n" | |
p flat.sort_by{|r| r.first} | |
print "\n" | |
end | |
def build(n) | |
all = [[(0...1)]] | |
draw(all) | |
(1..(n-1)).each do |i| | |
need = ONE / (i * (i+1)) | |
add = [] | |
all.each do |ar| | |
cur_need = need | |
while true | |
rng = ar.shift | |
if rng.last - rng.first < cur_need | |
add << rng | |
cur_need -= rng.last - rng.first | |
else | |
add << (rng.first ... (rng.first + cur_need)) | |
ar.unshift((rng.first+cur_need) ... rng.last) | |
break | |
end | |
end | |
end | |
all << add.sort_by{|r| r.first} | |
draw(all) | |
end | |
end |
This file contains 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
N = 1 | |
0: (1 items) [0...1] | |
Total 1 items: | |
[0...1] | |
N = 2 | |
0: (1 items) [(1/2)...1] | |
1: (1 items) [0...(1/2)] | |
Total 2 items: | |
[0...(1/2), (1/2)...1] | |
N = 3 | |
0: (1 items) [(2/3)...1] | |
1: (1 items) [(1/6)...(1/2)] | |
2: (2 items) [0...(1/6), (1/2)...(2/3)] | |
Total 4 items: | |
[0...(1/6), (1/6)...(1/2), (1/2)...(2/3), (2/3)...1] | |
N = 4 | |
0: (1 items) [(3/4)...1] | |
1: (1 items) [(1/4)...(1/2)] | |
2: (2 items) [(1/12)...(1/6), (1/2)...(2/3)] | |
3: (3 items) [0...(1/12), (1/6)...(1/4), (2/3)...(3/4)] | |
Total 7 items: | |
[0...(1/12), (1/12)...(1/6), (1/6)...(1/4), (1/4)...(1/2), (1/2)...(2/3), (2/3)...(3/4), (3/4)...1] | |
N = 5 | |
0: (1 items) [(4/5)...1] | |
1: (1 items) [(3/10)...(1/2)] | |
2: (2 items) [(2/15)...(1/6), (1/2)...(2/3)] | |
3: (3 items) [(1/20)...(1/12), (1/6)...(1/4), (2/3)...(3/4)] | |
4: (4 items) [0...(1/20), (1/12)...(2/15), (1/4)...(3/10), (3/4)...(4/5)] | |
Total 11 items: | |
[0...(1/20), (1/20)...(1/12), (1/12)...(2/15), (2/15)...(1/6), (1/6)...(1/4), (1/4)...(3/10), (3/10)...(1/2), (1/2)...(2/3), (2/3)...(3/4), (3/4)...(4/5), (4/5)...1] | |
N = 6 | |
0: (1 items) [(5/6)...1] | |
1: (1 items) [(1/3)...(1/2)] | |
2: (2 items) [(1/6)...(1/6), (1/2)...(2/3)] | |
3: (3 items) [(1/12)...(1/12), (1/6)...(1/4), (2/3)...(3/4)] | |
4: (4 items) [(1/30)...(1/20), (1/12)...(2/15), (1/4)...(3/10), (3/4)...(4/5)] | |
5: (5 items) [0...(1/30), (1/20)...(1/12), (2/15)...(1/6), (3/10)...(1/3), (4/5)...(5/6)] | |
Total 16 items: | |
[0...(1/30), (1/30)...(1/20), (1/20)...(1/12), (1/12)...(2/15), (1/12)...(1/12), (2/15)...(1/6), (1/6)...(1/6), (1/6)...(1/4), (1/4)...(3/10), (3/10)...(1/3), (1/3)...(1/2), (1/2)...(2/3), (2/3)...(3/4), (3/4)...(4/5), (4/5)...(5/6), (5/6)...1] | |
N = 7 | |
0: (1 items) [(6/7)...1] | |
1: (1 items) [(5/14)...(1/2)] | |
2: (1 items) [(11/21)...(2/3)] | |
3: (2 items) [(4/21)...(1/4), (2/3)...(3/4)] | |
4: (3 items) [(19/210)...(2/15), (1/4)...(3/10), (3/4)...(4/5)] | |
5: (5 items) [(1/42)...(1/30), (1/20)...(1/12), (2/15)...(1/6), (3/10)...(1/3), (4/5)...(5/6)] | |
6: (9 items) [0...(1/42), (1/30)...(1/20), (1/12)...(19/210), (1/12)...(1/12), (1/6)...(1/6), (1/6)...(4/21), (1/3)...(5/14), (1/2)...(11/21), (5/6)...(6/7)] | |
Total 22 items: | |
[0...(1/42), (1/42)...(1/30), (1/30)...(1/20), (1/20)...(1/12), (1/12)...(1/12), (1/12)...(19/210), (19/210)...(2/15), (2/15)...(1/6), (1/6)...(4/21), (1/6)...(1/6), (4/21)...(1/4), (1/4)...(3/10), (3/10)...(1/3), (1/3)...(5/14), (5/14)...(1/2), (1/2)...(11/21), (11/21)...(2/3), (2/3)...(3/4), (3/4)...(4/5), (4/5)...(5/6), (5/6)...(6/7), (6/7)...1] | |
N = 8 | |
0: (1 items) [(7/8)...1] | |
1: (1 items) [(3/8)...(1/2)] | |
2: (1 items) [(13/24)...(2/3)] | |
3: (2 items) [(5/24)...(1/4), (2/3)...(3/4)] | |
4: (3 items) [(13/120)...(2/15), (1/4)...(3/10), (3/4)...(4/5)] | |
5: (4 items) [(7/120)...(1/12), (2/15)...(1/6), (3/10)...(1/3), (4/5)...(5/6)] | |
6: (9 items) [(1/56)...(1/42), (1/30)...(1/20), (1/12)...(19/210), (1/12)...(1/12), (1/6)...(1/6), (1/6)...(4/21), (1/3)...(5/14), (1/2)...(11/21), (5/6)...(6/7)] | |
7: (8 items) [0...(1/56), (1/42)...(1/30), (1/20)...(7/120), (19/210)...(13/120), (4/21)...(5/24), (5/14)...(3/8), (11/21)...(13/24), (6/7)...(7/8)] | |
Total 29 items: | |
[0...(1/56), (1/56)...(1/42), (1/42)...(1/30), (1/30)...(1/20), (1/20)...(7/120), (7/120)...(1/12), (1/12)...(19/210), (1/12)...(1/12), (19/210)...(13/120), (13/120)...(2/15), (2/15)...(1/6), (1/6)...(4/21), (1/6)...(1/6), (4/21)...(5/24), (5/24)...(1/4), (1/4)...(3/10), (3/10)...(1/3), (1/3)...(5/14), (5/14)...(3/8), (3/8)...(1/2), (1/2)...(11/21), (11/21)...(13/24), (13/24)...(2/3), (2/3)...(3/4), (3/4)...(4/5), (4/5)...(5/6), (5/6)...(6/7), (6/7)...(7/8), (7/8)...1] | |
N = 9 | |
0: (1 items) [(8/9)...1] | |
1: (1 items) [(7/18)...(1/2)] | |
2: (1 items) [(5/9)...(2/3)] | |
3: (2 items) [(2/9)...(1/4), (2/3)...(3/4)] | |
4: (3 items) [(11/90)...(2/15), (1/4)...(3/10), (3/4)...(4/5)] | |
5: (4 items) [(13/180)...(1/12), (2/15)...(1/6), (3/10)...(1/3), (4/5)...(5/6)] | |
6: (8 items) [(13/315)...(1/20), (1/12)...(19/210), (1/12)...(1/12), (1/6)...(1/6), (1/6)...(4/21), (1/3)...(5/14), (1/2)...(11/21), (5/6)...(6/7)] | |
7: (8 items) [(1/72)...(1/56), (1/42)...(1/30), (1/20)...(7/120), (19/210)...(13/120), (4/21)...(5/24), (5/14)...(3/8), (11/21)...(13/24), (6/7)...(7/8)] | |
8: (9 items) [0...(1/72), (1/56)...(1/42), (1/30)...(13/315), (7/120)...(13/180), (13/120)...(11/90), (5/24)...(2/9), (3/8)...(7/18), (13/24)...(5/9), (7/8)...(8/9)] | |
Total 37 items: | |
[0...(1/72), (1/72)...(1/56), (1/56)...(1/42), (1/42)...(1/30), (1/30)...(13/315), (13/315)...(1/20), (1/20)...(7/120), (7/120)...(13/180), (13/180)...(1/12), (1/12)...(1/12), (1/12)...(19/210), (19/210)...(13/120), (13/120)...(11/90), (11/90)...(2/15), (2/15)...(1/6), (1/6)...(1/6), (1/6)...(4/21), (4/21)...(5/24), (5/24)...(2/9), (2/9)...(1/4), (1/4)...(3/10), (3/10)...(1/3), (1/3)...(5/14), (5/14)...(3/8), (3/8)...(7/18), (7/18)...(1/2), (1/2)...(11/21), (11/21)...(13/24), (13/24)...(5/9), (5/9)...(2/3), (2/3)...(3/4), (3/4)...(4/5), (4/5)...(5/6), (5/6)...(6/7), (6/7)...(7/8), (7/8)...(8/9), (8/9)...1] | |
N = 10 | |
0: (1 items) [(9/10)...1] | |
1: (1 items) [(2/5)...(1/2)] | |
2: (1 items) [(17/30)...(2/3)] | |
3: (2 items) [(7/30)...(1/4), (2/3)...(3/4)] | |
4: (3 items) [(2/15)...(2/15), (1/4)...(3/10), (3/4)...(4/5)] | |
5: (4 items) [(1/12)...(1/12), (2/15)...(1/6), (3/10)...(1/3), (4/5)...(5/6)] | |
6: (7 items) [(3/35)...(19/210), (1/12)...(1/12), (1/6)...(1/6), (1/6)...(4/21), (1/3)...(5/14), (1/2)...(11/21), (5/6)...(6/7)] | |
7: (7 items) [(13/420)...(1/30), (1/20)...(7/120), (19/210)...(13/120), (4/21)...(5/24), (5/14)...(3/8), (11/21)...(13/24), (6/7)...(7/8)] | |
8: (9 items) [(1/90)...(1/72), (1/56)...(1/42), (1/30)...(13/315), (7/120)...(13/180), (13/120)...(11/90), (5/24)...(2/9), (3/8)...(7/18), (13/24)...(5/9), (7/8)...(8/9)] | |
9: (11 items) [0...(1/90), (1/72)...(1/56), (1/42)...(13/420), (13/315)...(1/20), (13/180)...(1/12), (1/12)...(3/35), (11/90)...(2/15), (2/9)...(7/30), (7/18)...(2/5), (5/9)...(17/30), (8/9)...(9/10)] | |
Total 46 items: | |
[0...(1/90), (1/90)...(1/72), (1/72)...(1/56), (1/56)...(1/42), (1/42)...(13/420), (13/420)...(1/30), (1/30)...(13/315), (13/315)...(1/20), (1/20)...(7/120), (7/120)...(13/180), (13/180)...(1/12), (1/12)...(1/12), (1/12)...(1/12), (1/12)...(3/35), (3/35)...(19/210), (19/210)...(13/120), (13/120)...(11/90), (11/90)...(2/15), (2/15)...(2/15), (2/15)...(1/6), (1/6)...(4/21), (1/6)...(1/6), (4/21)...(5/24), (5/24)...(2/9), (2/9)...(7/30), (7/30)...(1/4), (1/4)...(3/10), (3/10)...(1/3), (1/3)...(5/14), (5/14)...(3/8), (3/8)...(7/18), (7/18)...(2/5), (2/5)...(1/2), (1/2)...(11/21), (11/21)...(13/24), (13/24)...(5/9), (5/9)...(17/30), (17/30)...(2/3), (2/3)...(3/4), (3/4)...(4/5), (4/5)...(5/6), (5/6)...(6/7), (6/7)...(7/8), (7/8)...(8/9), (8/9)...(9/10), (9/10)...1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment