Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
#A straight forward implementation of N. Johnston's algorithm. I prefer to look at this as 2n+1 where
|
||||
#the second n is first n reversed, and the 1 is always the second symbol. This algorithm will generate
|
||||
#just the left half of the result by setting l to [1,2] and looping from 3 to 6. For the purpose of
|
||||
#this task I am going to start from an empty array and generate the whole strings using just the
|
||||
#rules.
|
||||
#
|
||||
#Nigel Galloway: December 16th., 2014
|
||||
#
|
||||
l = []
|
||||
(1..6).each{|e|
|
||||
a, i = [], e-2
|
||||
(0..l.length-e+1).each{|g|
|
||||
if not (n = l[g..g+e-2]).uniq!
|
||||
a.concat(n[(a[0]? i : 0)..-1]).push(e).concat(n)
|
||||
i = e-2
|
||||
else
|
||||
i -= 1
|
||||
end
|
||||
}
|
||||
a.each{|n| print n}; puts "\n\n"
|
||||
l = a
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
def superperm(n)
|
||||
return [1] if n==1
|
||||
superperm(n-1).each_cons(n-1).with_object([]) do |sub, ary|
|
||||
next if sub.uniq!
|
||||
i = ary.empty? ? 0 : sub.index(ary.last)+1
|
||||
ary.concat(sub[i..-1] + [n] + sub)
|
||||
end
|
||||
end
|
||||
|
||||
def to_16(a) a.map{|x| x.to_s(16)}.join end
|
||||
|
||||
for n in 1..10
|
||||
ary = superperm(n)
|
||||
print "%3d: len =%8d :" % [n, ary.size]
|
||||
puts n<5 ? ary.join : to_16(ary.first(20)) + "...." + to_16(ary.last(20))
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue