Exemplo n.º 1
0
def test1():
  icObj = ic.IndicesCombiner(5,3, False)
  print 'icObj', icObj
  print 'icObj.current()', icObj.current()
  print 'icObj.next()', icObj.next()
  print 'icObj.next()', icObj.moveToLastOne()
  #print 'icObj.nextZeroless()', icObj.nextZeroless()
  print 'icObj.allSets()', icObj.allSets()
  
  icObj = ic.IndicesCombiner(4,3, False)
  result = ic.createWorkSetsWithIndicesCombiner([12, 15, 19, 21, 32], icObj)
  print 'result', result
  
  tupleWorkSetPlusQuantity = ([11, 37], 1); workSet = tupleWorkSetPlusQuantity[0]; quantity=tupleWorkSetPlusQuantity[1]
  icObj = ic.IndicesCombiner(len(workSet)-1, quantity, False)
  result = ic.createWorkSetsWithIndicesCombiner(workSet, icObj)
  print 'result', result
  
  print 'setCombinerObj = ic.SetsCombiner()'
  setCombinerObj = ic.SetsCombiner()
  setCombinerObj.addSetWithQuantities(([12, 15, 19, 21, 32, 33, 45], 3))
  setCombinerObj.addSetWithQuantities(([8, 25, 27, 28, 49], 2))
  setCombinerObj.addSetWithQuantities(([11, 37], 1))
  print 'setCombinerObj.combineSets()'
  setCombinerObj.combineSets()
  totalOfSets = len(setCombinerObj)
  print setCombinerObj.allCombinations
  print 'totalOfSets = len(setCombinerObj) =', totalOfSets
Exemplo n.º 2
0
 def mountFirstSets(self):
   betJogos = []; jogosStrDict = {}
   tilObj = LFClasses.Til(5); nOfLgi = 0; totalLgis = len(self.chosenLgis); lgisAlreadyGenerated = []
   for chosenLgi in self.chosenLgis:
     nOfLgi += 1
     print 'chosenLgi', chosenLgi, 'n.', nOfLgi, 'of', totalLgis
     setsForMultiply = []
     faixaIndex = 0
     for char in chosenLgi:
       digit = int(char)
       dezenas = tilObj.getDezenasNaFaixa(faixaIndex)
       faixaIndex += 1
       sets = []
       if digit == 0 or len(dezenas) < digit:
         continue
       elif len(dezenas) == digit:
         sets = [dezenas]
       else:
         sets = ic.setCombine(dezenas, digit)
       if len(sets) > 0:
         setsForMultiply.append(sets)
     icSet = ic.setMultiply(setsForMultiply)
     jogosStrDict = extractJogosFrom3DList(icSet, jogosStrDict)
     #jogosEncDict = extractJogosFrom3DList(icSet, jogosEncDict)
   return jogosStrDict
Exemplo n.º 3
0
def testLgiOf():
  jogo = [10, 8, 7, 5, 3, 2]
  print 'jogo', jogo
  lgiObj = lgicomb.LgiCombiner(ic.comb(60, 6)-1,-1,jogo)
  lgi = lgiObj.getLgi()
  print 'lgi', lgi
  jogo = filterMinusOne(jogo)
  print 'jogo', jogo
  lgiObj = lgicomb.LgiCombiner(ic.comb(60, 6)-1,-1,jogo)
  lgi = lgiObj.getLgi()
  print 'lgi', lgi
Exemplo n.º 4
0
 def getLgi(self):
   lgi = 0
   for i in range(self.size):
     value =  self.iArray[i]
     posInv = self.size - i
     lgi += comb.comb(value, posInv)
   return lgi
Exemplo n.º 5
0
def checkUpAmountInArrayCarried(carriedArray, lgi):
  size = len(carriedArray); soma = 0
  for i in range(size):
    value = carriedArray[i]
    posInv = size - i
    soma += comb.comb(value, posInv)
  if soma <> lgi:
    msg = 'checkUpAmountInCarriedArray() ==>> soma (=%d) não igual a lgi (=%d) %s' %(soma, lgi, str(carriedArray))
    raise ValueError, msg
Exemplo n.º 6
0
 def __init__(self, upLimit=0, size=1, iArrayIn=[0]):
   if size < 1:
     size = 1
   if upLimit < 0:
     upLimit = 0
   self.upLimit = upLimit
   # yet to be checked True
   self.stillFirst  = False
   if iArrayIn == [0] and size > 1:
     self.iArray = range(size-1, -1, -1)
     self.stillFirst  = True
   else:
     self.iArray      = list(iArrayIn)
     if self.iArray == range(size-1, -1, -1):
       self.stillFirst  = True
   self.size        = len(self.iArray)
   self.checkArrayConsistency()
   self.nOfCombines = comb.comb(self.upLimit+1, self.size)
   self.iArrayGiven = list(self.iArray)
Exemplo n.º 7
0
  def approach(self, lgi, pointInf, pointSup, pos, arrayCarried, amount=0):
    global counter
    if pos == self.size:
      msg = 'Well, failed to get the LG Index. Reason: pos surpasses all available slots. (pos=%d, size=%d, pointInf=%d, pointSup=%d)' %(pos, self.size, pointInf, pointSup)
      print msg
      sys.exit(0)
      #raise ValueError, msg
    pointMid = pointInf + (pointSup - pointInf) / 2
    posInv = self.size - pos
    parcel = comb.comb(pointMid, posInv)
    amountCompare = amount + parcel

    parcelSup = comb.comb(pointSup, posInv)
    amountCompareSup = amount + parcelSup

    parcelInf = comb.comb(pointInf, posInv)
    amountCompareInf = amount + parcelInf

    #msg = 'i=%d inf=%d/%d mid=%d/%d sup=%d/%d pos=%d %s press [ENTER]' %(lgi, pointInf, amountCompareInf, pointMid, amountCompare, pointSup, amountCompareSup, pos, str(arrayCarried))
    #ans=raw_input(msg)
    #counter+=1 # global
    #print counter, msg
    if amountCompareSup < lgi:
      amount += parcelSup
      arrayCarried[pos] = pointSup
      pos += 1
      # renew pointInf and pointSup
      pointInf = self.size - 1 - pos
      pointSup = pointSup - 1 # limiteSup
      return self.approach(lgi, pointInf, pointSup, pos, arrayCarried, amount)

    if amountCompareSup == lgi: # ok, game over
      arrayCarried[pos] = pointSup
      # check for consistency
      checkUpAmountInArrayCarried(arrayCarried, lgi)
      return arrayCarried

    if amountCompare > lgi:
      # the following check avoids an infinite recursion and logically complements the desired functionality
      if pointMid >= pointSup-1 and parcelInf < lgi:
        amount += parcelInf
        arrayCarried[pos] = pointInf
        pos += 1
        # renew pointInf and pointSup
        pointSup = pointInf - 1 # limiteSup
        pointInf = self.size - 1 - pos
        return self.approach(lgi, pointInf, pointSup, pos, arrayCarried, amount)
      pointSup = pointMid
      return self.approach(lgi, pointInf, pointSup, pos, arrayCarried, amount)
    elif amountCompare < lgi:
      if pointMid >= pointSup - 1:
        if amountCompareSup < lgi:
          amount += parcelSup
          arrayCarried[pos] = pointSup
          pointSup = pointSup - 1 # limiteSup
        else:
          amount += parcel
          arrayCarried[pos] = pointMid
          pointSup = pointMid - 1 # limiteSup
        pos += 1
        # renew pointInf and pointSup
        pointInf = self.size - 1 - pos
        return self.approach(lgi, pointInf, pointSup, pos, arrayCarried, amount)
      pointInf = pointMid
      # pointSup is the same
      return self.approach(lgi, pointInf, pointSup, pos, arrayCarried, amount)
    else:  # ie, amountCompare == lgi ie, element has just been FOUND!
      arrayCarried[pos] = pointMid
      # check for consistency
      checkUpAmountInArrayCarried(arrayCarried, lgi)
      return arrayCarried
Exemplo n.º 8
0
  #read:
  fd = open('myfile.dat', 'rb')
  read_data = scipy.io.numpyio.fread(fd, 1, 'i')
  print 'read_data', read_data

  read_data = scipy.io.numpyio.fread(fd, 1, 'i')
  print 'read_data', read_data

mask = [0]*4
mask[0] = 2**8 - 1 # ie, 255
for i in range(1,4):
  mask[i] = mask[i-1] << 8 

maxInt = 2**16 - 1
import IndicesCombiner
c25to15 = IndicesCombiner.comb(25,15)

def m4():
  randomLgis = []
  tmpfile = "tmp.bin"
  fileobj = open(tmpfile, 'wb')
  nOfBytes = 3
  
  for i in range(5):
    lgi = random.randint(0,c25to15)
    randomLgis.append(lgi)
    print 'lgi', lgi
    bytes = binDec.packByteInt(lgi, nOfBytes)
    for byte in bytes:
      #print 'byte', byte
      fileobj.write(chr(byte))
Exemplo n.º 9
0
def testSetCombine():
  sets = ic.testSetCombine([10,12,15,17, 3],3)
  print sets