words in 012 which avoid 00, 1111 and other factors

138 days ago by zabrocki

w3 = Words([0,1,2]) 
       
w3 
       
Words over Ordered Alphabet [0, 1, 2]
Words over Ordered Alphabet [0, 1, 2]
def mycond(x): w = Word(x) return Word([0,0]).nb_factor_occurrences_in(w)==0 and Word([2,1,2]).is_subword_of(w)==False and Word([0,1,1,0,1,1]).nb_factor_occurrences_in(w)==0 
       
mycond([2,0,1,0,1,0,1,2,1,0,1]) 
       
False
False
w. 
       
 
       
for k in range(1,13): len(filter(mycond,list(w3.iterate_by_length(k)) )) 
       
3
8
22
59
159
428
1152
3101
8348
22473
Traceback (click to the left of this block for traceback)
...
__SAGE__
3
8
22
59
159
428
1152
3101
8348
22473
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_12.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("Zm9yIGsgaW4gcmFuZ2UoMSwxMyk6CiAgICBsZW4oZmlsdGVyKG15Y29uZCxsaXN0KHczLml0ZXJhdGVfYnlfbGVuZ3RoKGspKSApKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmp13hJXW/___code___.py", line 3, in <module>
    exec compile(u'for k in range(_sage_const_1 ,_sage_const_13 ):\n    len(filter(mycond,list(w3.iterate_by_length(k)) ))
  File "", line 2, in <module>
    
  File "/sagenb/sage_install/sage-4.7.2/local/lib/python2.6/site-packages/sage/combinat/words/words.py", line 1043, in iterate_by_length
    yield self(map(lambda x: self.alphabet().unrank(x), w))
  File "/sagenb/sage_install/sage-4.7.2/local/lib/python2.6/site-packages/sage/combinat/words/words.py", line 231, in __call__
    w = self._construct_word(**kwds)
  File "/sagenb/sage_install/sage-4.7.2/local/lib/python2.6/site-packages/sage/combinat/words/words.py", line 502, in _construct_word
    cls_str = 'FiniteWord_%s'%datatype
KeyboardInterrupt
__SAGE__
w = Word([1,0,1,1,2,0]) 
       
w.count(1)>=w.count(2) 
       
3
3
range(1,13) 
       
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
for k in range(13,15): len(filter(lambda x: Word([0,0]).nb_factor_occurrences_in(x)==0 and Word([1,1,1,1]).nb_factor_occurrences_in(x)==0 and Word([0,1,1,0,1,1]).nb_factor_occurrences_in(x)==0,list(w3.iterate_by_length(k)) )) 
       
Traceback (click to the left of this block for traceback)
...
MemoryError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sage/sagenb/sage_notebook/worksheets/zabrocki/1/code/5.py", line 7, in <module>
    for k in range(_sage_const_13 ,_sage_const_15 ):\u000a    len(filter(lambda x: Word([_sage_const_0 ,_sage_const_0 ]).nb_factor_occurrences_in(x)==_sage_const_0  and Word([_sage_const_1 ,_sage_const_1 ,_sage_const_1 ,_sage_const_1 ]).nb_factor_occurrences_in(x)==_sage_const_0  and Word([_sage_const_0 ,_sage_const_1 ,_sage_const_1 ,_sage_const_0 ,_sage_const_1 ,_sage_const_1 ]).nb_factor_occurrences_in(x)==_sage_const_0 ,list(w3.iterate_by_length(k)) ))
  File "", line 2, in <module>
    
  File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/combinat/words/words.py", line 606, in iterate_by_length
    for w in xmrange([self.size_of_alphabet()]*l):
  File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/misc/mrange.py", line 251, in _xmrange
    yield typ(v)   # make a copy of v!
MemoryError