$xx={} $yy=[] $num=0 class Patterns @a = [] def initialize(x) @a = convert(x) end def convert(x) ret = [] maxnum = x.max { |a, b| a.length <=> b.length}.length z = x[0..-1] for l in 1..(maxnum) do y = x[0..-1] while y.empty? == false do bb = y[0] y = y.reject { |m| m==bb } if (bb.length < l) then next end aa=Array.new(l,1) if(l<bb.length+1) then aa=aa.concat(Array.new(bb.length-l,0)) end s=check(x,aa,bb) if s.length < 3 then next end if (s.min..s.max).to_a.all?{ |j| s.include?(j)} then pat = Pattern.new(aa,bb,s.min,s.max) ret << pat for xx in s.min..s.max do k=[] for n in 0..aa.length-1 do k[n] = aa[n]*xx+bb[n] end y.delete(k) z.delete(k) end end end end for k in 0..z.length-1 do aa = Array.new(z[k].length,0) bb = z[k] pat = Pattern.new(aa,bb,0,0) ret << pat end return ret end def check(y,a,b) ret = [] if a.length != b.length then return ret end for i in 0..(y.length-1) do $num+=1 x=(y[i][0]-b[0])/a[0] if y[i].length != a.length then next end if (0..a.length-1).to_a.all?{ |j| y[i][j]==a[j]*x+b[j] } then ret << x end end return ret end def to_s s = "[" for i in 0..(@a.length-1) do s += @a[i].to_s + "," end s = s.chop s += "]" return s end end class Pattern @a = [] @b = [] @first = 0 @last = 0 def initialize(a,b,first,last) @a = a[0..-1] @b = b[0..-1] @first = first @last = last end def to_s s = "{[" for i in 0..(@a.length-1) do s += @a[i].to_s + "x+" + @b[i].to_s + "," end s=s.chop s += "]:" s += @first.to_s + "<=x<=" + @last.to_s + "}" if @first == @last then s = @b.to_s end return s end end def lose(a) if a.length == 1 && a[0] == 1 then if $xx[[1]] == nil then $xx[[1]] = true $yy << [1] end return true end if $xx[a] == true then return $yy.include?(a) end ret = true for i in 0..(a.length-1) do for j in 1..a[i] do if i==0 && j==1 then next end $num+=1 b=a[0..-1] for k in i..(a.length-1) do $num+=1 if a[k] >= j then b[k] = j -1 end end if j==1 then b=a[0..i-1] end if ($xx[b] == nil) then if lose(b) then ret = false end else if $yy.include?(b) then ret = false end end end end if ret == true then $yy << a end $xx[a] = true return ret end m=4 n=16 #x = Array.new(m,n) x=[24,24,24] print "num=" p $num lose(x) print "num=" p $num p $xx.length p $yy.length for i in 1..x.length do tt = $yy.select { |n| n.length == i } print "count=" print tt.length print " " p tt end set = Patterns.new($yy) print "p=" p $num puts set.to_s print "p="
Standard input is empty
num=0
num=331552
2924
129
count=1 [[1]]
count=23 [[2, 1], [3, 2], [4, 3], [5, 4], [6, 5], [7, 6], [8, 7], [9, 8], [10, 9], [11, 10], [12, 11], [13, 12], [14, 13], [15, 14], [16, 15], [17, 16], [18, 17], [19, 18], [20, 19], [21, 20], [22, 21], [23, 22], [24, 23]]
count=105 [[2, 2, 1], [3, 1, 1], [4, 2, 2], [5, 3, 2], [5, 5, 3], [6, 3, 3], [6, 4, 2], [7, 4, 3], [7, 5, 2], [7, 7, 4], [8, 4, 4], [8, 6, 2], [9, 5, 4], [9, 6, 5], [9, 7, 2], [9, 9, 6], [10, 5, 5], [10, 6, 4], [10, 8, 2], [11, 6, 6], [11, 7, 5], [11, 9, 2], [12, 7, 6], [12, 8, 5], [12, 9, 7], [12, 10, 2], [12, 12, 8], [13, 7, 7], [13, 8, 6], [13, 9, 5], [13, 11, 2], [14, 8, 7], [14, 9, 8], [14, 10, 5], [14, 11, 9], [14, 12, 2], [14, 14, 10], [15, 8, 8], [15, 10, 7], [15, 11, 5], [15, 13, 2], [16, 9, 9], [16, 10, 8], [16, 11, 7], [16, 12, 5], [16, 14, 2], [17, 10, 9], [17, 11, 8], [17, 12, 7], [17, 13, 5], [17, 14, 11], [17, 15, 2], [17, 17, 12], [18, 10, 10], [18, 12, 9], [18, 13, 7], [18, 14, 5], [18, 16, 2], [19, 11, 10], [19, 12, 11], [19, 13, 9], [19, 14, 7], [19, 15, 5], [19, 16, 12], [19, 17, 2], [19, 19, 13], [20, 11, 11], [20, 12, 10], [20, 14, 9], [20, 15, 7], [20, 16, 5], [20, 18, 2], [21, 12, 12], [21, 13, 10], [21, 15, 9], [21, 16, 7], [21, 17, 5], [21, 18, 11], [21, 19, 2], [22, 13, 11], [22, 14, 12], [22, 15, 13], [22, 16, 9], [22, 17, 7], [22, 18, 5], [22, 19, 14], [22, 20, 2], [22, 22, 15], [23, 13, 12], [23, 14, 13], [23, 15, 11], [23, 16, 14], [23, 17, 9], [23, 18, 7], [23, 19, 5], [23, 20, 15], [23, 21, 2], [23, 23, 16], [24, 13, 13], [24, 15, 12], [24, 16, 11], [24, 18, 9], [24, 19, 7], [24, 20, 5], [24, 22, 2]]
p=368317
[{[1x+2,1x+1]:0<=x<=22},{[1x+4,1x+2,0x+2]:0<=x<=20},{[1x+8,1x+4,0x+4]:0<=x<=2},{[1x+11,1x+6,0x+6]:0<=x<=2},{[1x+11,1x+7,0x+5]:0<=x<=13},{[1x+15,1x+10,0x+7]:0<=x<=9},{[1x+18,1x+10,0x+10]:0<=x<=3},{[1x+18,1x+12,0x+9]:0<=x<=6},[1],[2, 2, 1],[3, 1, 1],[5, 5, 3],[6, 3, 3],[7, 4, 3],[7, 7, 4],[9, 6, 5],[9, 9, 6],[10, 5, 5],[12, 9, 7],[12, 12, 8],[13, 7, 7],[14, 8, 7],[14, 9, 8],[14, 11, 9],[14, 14, 10],[15, 8, 8],[16, 9, 9],[16, 10, 8],[17, 10, 9],[17, 11, 8],[17, 14, 11],[17, 17, 12],[19, 12, 11],[19, 16, 12],[19, 19, 13],[20, 11, 11],[21, 12, 12],[21, 18, 11],[22, 13, 11],[22, 14, 12],[22, 15, 13],[22, 19, 14],[22, 22, 15],[23, 13, 12],[23, 14, 13],[23, 15, 11],[23, 16, 14],[23, 20, 15],[23, 23, 16],[24, 13, 13],[24, 15, 12],[24, 16, 11]]
p=