Skip to content

Instantly share code, notes, and snippets.

@LCamel
Created November 27, 2011 14:09
Show Gist options
  • Save LCamel/1397607 to your computer and use it in GitHub Desktop.
Save LCamel/1397607 to your computer and use it in GitHub Desktop.
N = 49
M = 7
def l(n, i) # left
(i == M - 1) ? n : l(n, i + 1) / (N - (i + 1))
end
def b(n, i) # branch
l(n, i) % (N - i)
end
def u(n, i, j) # used
s = 0
for k in 0 .. i - 1
if p(n, k) <= j
s += 1
end
end
return s
end
def p(n, i) # permutation
b0 = b(n, i)
for j in b0 .. N - 1
if u(n, i, j) + b0 == j
return j
end
end
end
n = rand(49 * 48 * 47 * 46 * 45 * 44 * 43)
for i in 0 .. M - 1
puts p(n, i) + 1
end
__END__
N = 5
M = 3
for n in 0 .. 5 * 4 * 3 - 1
for i in 0 .. M - 1
#print b(n, i), " "
print p(n, i), " "
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment