def testGerador(): gerador = Gerador() # gerador = GeradorIterator() print len(gerador) #indices_position_to_move_at = [53,54,56,57,58,59] #indices_position_to_move_at = [54,55,56,57,58,59] #gerador.iterator.move_to_element_by_its_indices(indices_position_to_move_at) print 'gerador.iterator.move_to_one_before_last()' gerador.iterator.move_to_one_before_last() print '_one_before_last', gerador.iterator.get_current() # gerador.iterator.next() # print 'next/last', gerador.iterator.get_current() gerador.iterator.move_to_last() print 'move_to_last', gerador.iterator.get_current() #gerador.iterator.next() # exception will be raised # print 'next after last', gerador.iterator.get_current() gerador.iterator.restart() print 'restart', gerador.iterator.get_current() gerador.iterator.next() print 'next after restart', gerador.iterator.get_current() for jogo_as_dezenas in gerador: i = gerador.iterator.session_index if i > 10: break print i, convert_intlist_to_spaced_zfillstr(jogo_as_dezenas)
def generate_all_combinations_against_excluding_tilrpatterns(): # the excluding list was constructed with tilrpatterns occurring less than 4 times, there are 97 excluding wpatterns in a total of 180 excluding_tilrwpatterns = ['00006', '00060', '00600', '06000', '60000', '00015', '00051', '00105', '00150', '00501', '00510', '01005', '01050', '01500', '05001', '05010', '05100', '10005', '10050', '10500', '15000', '50001', '50010', '50100', '51000', '00024', '00042', '00204', '00240', '00402', '00420', '02004', '02040', '02400', '04002', '04020', '04200', '20004', '20040', '20400', '24000', '40002', '40020', '40200', '42000', '00114', '00141', '00411', '01014', '01041', '01401', '01410', '04011', '04101', '04110', '10014', '10104', '10140', '10401', '10410', '11004', '11040', '11400', '14001', '14010', '14100', '40011', '40101', '41001', '41010', '41100', '00033', '00303', '00330', '03003', '03030', '03300', '30003', '30030', '30300', '33000', '00132', '00213', '00321', '02031', '02103', '02301', '02310', '03012', '10203', '10302', '13002', '13020', '20310', '23001', '32100', '00222'] n_slots=5; soma=6 tilstats_reused_for_excluding_wpatterns = TilR.TilStats(n_slots, soma) for wpattern in excluding_tilrwpatterns: tilstats_reused_for_excluding_wpatterns.add_pattern_as_str(wpattern) #slider = ConcursoExt() #n_last_concurso = slider.get_n_last_concurso() filename = ls.GENERATED_DATA_DIR + 'all_combinations_against_excluding_tilrpatterns.blob' fileobj = open(filename, 'w') #pickler = pickle.Pickler(fileobj, pickle.HIGHEST_PROTOCOL) gerador = Gerador() n_passed = 0 print 'Processing', len(gerador), 'games, please wait.' for jogo_as_dezenas in gerador: bool_result = filter_fd.filter_in_those_not_having_tilrwpatterns(jogo_as_dezenas, tilstats_reused_for_excluding_wpatterns, history_nDoConc_range=None) if bool_result: np_dezenas = numpy.array(jogo_as_dezenas) # pickler.dump(np_dezenas) dezenas_zfill2 = convert_intlist_to_spaced_zfillstr(np_dezenas) output_line = dezenas_zfill2 + '\n' fileobj.write(output_line) n_passed += 1 all_index = gerador.iterator.session_index diff = all_index - n_passed print bool_result, dezenas_zfill2, 'n_passed=%d, all_index=%d, diff=%d' %(n_passed, all_index, diff) output_line = 'n_passed=%d, all_index=%d, diff=%d' %(n_passed, all_index, diff) print output_line fileobj.write(output_line) fileobj.close()
def generate(wpattern): global all_generated pattern_list = map(int, wpattern) print wpattern, pattern_list # dozens_thru_slots = map(tilr.get_dozens_in_slot_n, xrange(n_slots)) # print 'dozens_thru_slots', dozens_thru_slots combiner = SetsCombiner() for slot_n in xrange(n_slots): quantity = pattern_list[slot_n] if quantity == 0: continue dozens = tilr.get_dozens_in_slot_n(slot_n) workSetWithQuantity = (dozens, quantity) print 'Adding workSetWithQuantity', workSetWithQuantity combiner.addSetWithQuantities(workSetWithQuantity) total_combinations = combiner.get_total_combinations() all_generated += total_combinations print 'total_combinations', total_combinations # sys.exit(0) for i, jogo in enumerate(combiner.next_combination()): jogo.sort() print all_generated, i, 'combining', convert_intlist_to_spaced_zfillstr(jogo)
def __str__(self): outlist = self.get_current() if outlist != None: return convert_intlist_to_spaced_zfillstr(outlist) return '<None>'