Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Created March 17, 2014 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadbrewbaker/9605909 to your computer and use it in GitHub Desktop.
Save chadbrewbaker/9605909 to your computer and use it in GitHub Desktop.
avoidence.rb Transformation pattern avoidence
counting_numbers = Enumerator.new do |yielder|
(0..1.0/0).each do |number| yielder.yield number
end
end
def nilstuff(a,stuff="")
if(a.nil?)
return stuff
else
return a
end
end
def canon_trans(trans)
vals = trans.uniq.sort
val_hash ={}
vals.each_with_index{ |n, idx|
val_hash[n]=idx
}
canon =[]
trans.each{|elt| canon.push(val_hash[elt])}
return canon
end
def contains(pattern, trans)
#iterate a k-subset window, sort the subset elts puts it in canonical form for comparison
trans.combination(pattern.length){|c|
if canon_trans(c).inspect == pattern.inspect
#puts c.inspect
return c.inspect
end
}
return nil
end
oeis_hash ={}
seen_hash = {}
2.upto(4) do |patt_size|
counting_numbers.take(patt_size).repeated_permutation(patt_size).each { |p|
puts "pattern #{p.inspect}"
if (seen_hash[canon_trans(p).inspect] == nil)
seen_hash[canon_trans(p).inspect] = true
seen_hash[canon_trans(p).reverse.inspect] = true
else
puts "seen"
next
end
catatrans=[]
0.upto(7) do |tran_size|
avoid = 0
counting_numbers.take(tran_size).repeated_permutation(tran_size).each { |x|
if (contains(canon_trans(p), x))
else
avoid = avoid +1
end
}
catatrans.push(avoid)
end
s = catatrans.inspect
oeis_hash[s] = nilstuff(oeis_hash[s]) + "|" + p.inspect
puts oeis_hash.keys.inspect
puts oeis_hash.inspect
}
end
@chadbrewbaker
Copy link
Author

Output, the Wilf classes for n up to 7 and k = 2,3,4:
{"[1, 1, 2, 6, 24, 120, 720, 5040]"=>"|[0, 0]", "[1, 1, 3, 10, 35, 126, 462, 1716]"=>"|[0, 1]", "[1, 1, 4, 24, 204, 2220, 29520, 463680]"=>"|[0, 0, 0]", "[1, 1, 4, 24, 186, 1745, 19090, 237594]"=>"|[0, 0, 1]|[0, 1, 0]|[0, 1, 1]|[1, 0, 1]", "[1, 1, 4, 26, 210, 1897, 18368, 186636]"=>"|[0, 1, 2]|[0, 2, 1]|[1, 0, 2]", "[1, 1, 4, 27, 252, 3020, 44220, 765030]"=>"|[0, 0, 0, 0]", "[1, 1, 4, 27, 250, 2935, 41676, 693798]"=>"|[0, 0, 0, 1]|[0, 0, 1, 0]|[0, 1, 1, 1]|[1, 0, 1, 1]", "[1, 1, 4, 27, 250, 2915, 40806, 664944]"=>"|[0, 0, 1, 1]", "[1, 1, 4, 27, 252, 2935, 40351, 633864]"=>"|[0, 0, 1, 2]|[0, 0, 2, 1]|[0, 1, 2, 2]|[1, 0, 2, 2]", "[1, 1, 4, 27, 250, 2915, 40746, 661304]"=>"|[0, 1, 0, 1]", "[1, 1, 4, 27, 252, 2935, 40330, 632408]"=>"|[0, 1, 0, 2]|[0, 2, 1, 2]", "[1, 1, 4, 27, 250, 2915, 40766, 662494]"=>"|[0, 1, 1, 0]|[1, 0, 0, 1]", "[1, 1, 4, 27, 252, 2935, 40330, 632352]"=>"|[0, 1, 1, 2]|[0, 1, 2, 1]|[0, 2, 1, 1]|[0, 2, 2, 1]|[1, 0, 0, 2]|[1, 0, 1, 2]|[1, 0, 2, 1]|[1, 1, 0, 2]", "[1, 1, 4, 27, 252, 2935, 40336, 632870]"=>"|[0, 1, 2, 0]|[2, 0, 1, 2]", "[1, 1, 4, 27, 255, 3028, 41979, 647790]"=>"|[0, 1, 2, 3]|[0, 1, 3, 2]|[0, 3, 2, 1]|[1, 0, 2, 3]|[1, 0, 3, 2]|[2, 1, 0, 3]", "[1, 1, 4, 27, 252, 2935, 40300, 630392]"=>"|[0, 2, 0, 1]|[1, 2, 0, 2]", "[1, 1, 4, 27, 255, 3028, 41979, 647826]"=>"|[0, 2, 1, 3]", "[1, 1, 4, 27, 255, 3028, 41972, 647034]"=>"|[0, 2, 3, 1]|[2, 0, 1, 3]", "[1, 1, 4, 27, 255, 3028, 41972, 647006]"=>"|[0, 3, 1, 2]|[1, 2, 0, 3]", "[1, 1, 4, 27, 255, 3028, 41966, 646404]"=>"|[1, 3, 0, 2]"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment