Exemplo n.º 1
0
def main():
    argMap = {}
    argMap = cmdArgs.parseCmdLine(dbg=0)
    print('argMap={}'.format(argMap))
    inFileNames = argMap['']
    print('inFileNames={}'.format(inFileNames))
    try:
        for f in range(len(inFileNames)):
            with open(inFileNames[f] + '.in', 'r') as inFile:
                print('reading file {}'.format(inFileNames[f]))
                numLeaves = int(inFile.readline().strip().split(' ')[0])
                print('numLeaves={}'.format(numLeaves))
                traitDict = {}
                leaves = []
                for i in range(numLeaves):
                    line = inFile.readline().strip()
                    tokens = line.split(' ')
                    traitList = tokens[1:]
                    leaves.append(traitList)
                    for t in traitList:
                        if t in traitDict:
                            traitDict[t] = traitDict[t] + 1
                        else:
                            traitDict[t] = 1
                    print('leaf[{}]: nt={} {}'.format(i, tokens[0], traitList))
                print('traitDict={}'.format(traitDict))
                print('leaves={}'.format(leaves))
    except FileNotFoundError as e:
        print('init() Exception: {} - {}'.format(e, sys.exc_info()[0]))
Exemplo n.º 2
0
def main():
    fileName = 'names.in'
    try:
        with open(fileName, 'r') as inFile:
            print('reading file {}'.format(fileName))
            line = inFile.readline().strip()
            names = line.split(' ')
            print('{} {}'.format(len(names), names))
            names.sort()
            print('{} {}'.format(len(names), names))
    except FileNotFoundError as e:
        print('init() Exception: {} - {}'.format(e, sys.exc_info()[0]))
    argMap = {}
    argMap = cmdArgs.parseCmdLine(dbg=0)
    print('argMap={}'.format(argMap))
    inFileNames = argMap['']
    print('inFileNames={}'.format(inFileNames))
    try:
        for i in range(len(inFileNames)):
            with open(inFileNames[i] + '.in', 'r') as inFile:
                print('reading file {}'.format(inFileNames[i]))
                line = inFile.readline().strip()
                tokens = line.split(' ')
                ruleCnt = int(tokens[0])
                print('{}'.format(ruleCnt))
                matesDict = {}
                for j in range(ruleCnt):
                    line = inFile.readline().strip()
                    tokens = line.split(' ')
                    raw = [tokens[0], tokens[len(tokens) - 1]]
                    sorted = list(raw)
                    sorted.sort()
                    if sorted[0] not in matesDict:
                        matesDict[sorted[0]] = [sorted[1]]
                    else:
                        tmp = [matesDict[sorted[0]][0], sorted[1]]
                        tmp.sort()
                        matesDict[sorted[0]] = tmp
                    print('{} => {}'.format(raw, sorted))
                print('{}'.format(matesDict))
                print(names)
                for k in matesDict:
                    print('matesDict[{}]={}'.format(k, matesDict[k]))
                    if len(matesDict[k]) == 1:
                        print('    len=1, moving {} to after {}'.format(
                            matesDict[k][0], k))
                        names.remove(matesDict[k][0])
                        names.insert(names.index(k) + 1, matesDict[k][0])
                    elif len(matesDict[k]) == 2:
                        print(
                            '    len=2, moving {} to between {} and {}'.format(
                                k, matesDict[k][0], matesDict[k][1]))
                        names.remove(k)
                        names.insert(names.index(matesDict[k][1]), k)
                    print(names)
    except FileNotFoundError as e:
        print('init() Exception: {} - {}'.format(e, sys.exc_info()[0]))
Exemplo n.º 3
0
def main():
    argMap = {}
    argMap = cmdArgs.parseCmdLine(dbg=0)
    print('argMap={}'.format(argMap))
    inFileNames = argMap['']
    print('inFileNames={}'.format(inFileNames))
    try:
        for f in range(len(inFileNames)):
            with open(inFileNames[f] + '.in', 'r') as inFile:
                print('reading file {}'.format(inFileNames[f]))
                line = inFile.readline().strip()
                tokens = line.split(' ')
                K = int(tokens[0])
                N = int(tokens[1])
                cowList = []
                print('K={}, N={}'.format(K, N))
                for i in range(K):
                    line = inFile.readline().strip()
                    tokens = line.split(' ')
                    print('{} {}'.format(i, tokens))
                    tmp = []
                    for k in range(len(tokens)):
                        tmp.append(int(tokens[k]))
                    cowList.append(tmp)
                print('{}'.format(cowList))
                for i in range(K):
                    for j in range(N):
                        print('{}'.format(cowList[i][j]), end=' ')
                    print()
                pairs = []
                for i in range(K):
                    tmp = []
                    for j in range(N - 1):
                        for k in range(j, N - 1):
                            p = [cowList[i][j], cowList[i][k + 1]]
                            tmp.append(p)
                            print('[{} {}]'.format(p[0], p[1]), end=' ')
                    pairs.append(tmp)
                    print()
                for i in range(K):
                    print('{} {}'.format(i, pairs[i]))
                found = 0
                for j in range(len(pairs[0])):
                    cnt = 0
                    for i in range(1, K):
                        if pairs[0][j] in pairs[i]:
                            cnt += 1
                    print('{} checking {}'.format(j, pairs[0][j]))
                    if cnt == K - 1:
                        found += 1
                        print('{} found {}'.format(j, pairs[0][j]))
                print('found {} pairs'.format(found))
    except FileNotFoundError as e:
        print('init() Exception: {} - {}'.format(e, sys.exc_info()[0]))
Exemplo n.º 4
0
    def __init__(self):
        global FULL_SCREEN, SUBPIX, ORDER_GROUP
        SNAP_GLOB_ARG = str(BASE_PATH / SNAP_DIR / BASE_NAME) + SFX + '.*' + SNAP_SFX
        FILE_GLOB     = glob.glob(SNAP_GLOB_ARG)
        self.log('(BGN) VRSN={} VRSNX=({}) {}'.format(VRSN, VRSNX, Tabs))
        self.log('globPathArg={}'.format(SNAP_GLOB_ARG))
        for _F in FILE_GLOB:
            self.log('{}  {}'.format(os.path.basename(_F), _F), ind=0)
            pathlib.Path(_F).unlink()
        self.ww, self.hh  = 640, 480
        self.n, self.i, self.x, self.y, self.w, self.h, self.o, self.g = [12, 12, 0, 0], [0, 0, 0, 0], [4, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 0, 0], []
        self.argMap = cmdArgs.parseCmdLine(dbg=1)
        if 'n' in self.argMap and len(self.argMap['n'])  > 0: self.n            = [int(self.argMap['n'][i]) for i in range(len(self.argMap['n']))]
        if 'i' in self.argMap and len(self.argMap['i'])  > 0: self.i            = [int(self.argMap['i'][i]) for i in range(len(self.argMap['i']))]
        if 'x' in self.argMap and len(self.argMap['x'])  > 0: self.x            = [int(self.argMap['x'][i]) for i in range(len(self.argMap['x']))]
        if 'y' in self.argMap and len(self.argMap['y'])  > 0: self.y            = [int(self.argMap['y'][i]) for i in range(len(self.argMap['y']))]
        if 'w' in self.argMap and len(self.argMap['w'])  > 0: self.ww           =  int(self.argMap['w'][0])
        if 'h' in self.argMap and len(self.argMap['h'])  > 0: self.hh           =  int(self.argMap['h'][0])
        if 'o' in self.argMap and len(self.argMap['o'])  > 0: self.o            = [int(self.argMap['o'][i]) for i in range(len(self.argMap['o']))]
        if 'f' in self.argMap and len(self.argMap['f']) == 0: FULL_SCREEN       = 1
        if 'g' in self.argMap and len(self.argMap['g']) == 0: ORDER_GROUP       = 1
        if 's' in self.argMap and len(self.argMap['s']) == 0: SUBPIX            = 1
#        if 't' in self.argMap and len(self.argMap['t']) == 0: TEST              = 1
        self.log('[n]            n={}'.format(self.n))
        self.log('[i]            i={}'.format(self.i))
        self.log('[x]            x={}'.format(self.x))
        self.log('[y]            y={}'.format(self.y))
        self.log('[w]           ww={}'.format(self.ww))
        self.log('[h]           hh={}'.format(self.hh))
        self.log('[o]            o={}'.format(self.o))
        self.log('[f]  FULL_SCREEN={}'.format(FULL_SCREEN))
        self.log('[g]  ORDER_GROUP={}'.format(ORDER_GROUP))
        self.log('[s]       SUBPIX={}'.format(SUBPIX))
#        self.log('[t]         TEST={}'.format(TEST))
        if len(self.n) == K: self.n.append(self.n[C] + CCC)  ;  self.log('[n] +=n[C]+CCC n={}'.format(self.n))
        self._initWindowA()
        super().__init__(screen=self.screens[1], fullscreen=FULL_SCREEN, resizable=True, visible=False)
        self._initWindowB()
        self.symb, self.symbStr, self.mods, self.modsStr, self.kbk = 0, '', 0, '', 0
        self.ci = 0
        self.cursor, self.caret = None, None
        self.data, self.sprites, self.blankCol = [], [], ''
        self._initTestColors()
        self.log('(END) VRSN={} VRSNX=({}) {}'.format(VRSN, VRSNX, Tabs))
        text = '\n' + '###   __init__   ###' * 18 + '\n'
        self.log(text, ind=0)
Exemplo n.º 5
0
def main():
    argMap = {}
    argMap = cmdArgs.parseCmdLine(dbg=0)
    print('argMap={}'.format(argMap))
    inFileNames = argMap['']
    print('inFileNames={}'.format(inFileNames))
    try:
        for f in range(len(inFileNames)):
            with open(inFileNames[f] + '.in', 'r') as inFile:
                print('reading file {}'.format(inFileNames[f]))
                line = inFile.readline().strip()
                tokens = line.split(' ')
                N = int(tokens[0])
                print('{}'.format(N))
                m = inFile.readline().strip()
                print('     {}'.format(m))
                max, imax, jmax = '', 0, 0
                for i in range(N-2):
                    s1, found = '', 0
                    for j in range(i, N-1):
                        s1 = m[i:j+1]
                        if j + 1 < N:
                            s2 = m[j+1:N]
                        k = s2.count(s1)
                        print('{} {} {} {} {}'.format(i, j, s1, s2, k))
                        if found== 0 and k == 0:
                            bgn, end = i, j
                            if len(s1) > len(max): 
                                max, imax, jmax = s1, i, j
                            found = 1
                            print('{} {} {} {}'.format(bgn, end, s1, len(s1)))
                    print('{} {} {} {}'.format(imax, jmax, max, len(max)))
                print('{}'.format(m))
                n, indent = [],''
                for i in range(N-len(max)+1):
                    n.append(m[i:i+len(max)])
                    print('{}{}'.format(indent, m[i:i+len(max)]))
                    indent += ' '
                n.sort()
                for i in n:
                    print('{}'.format(i))
    except FileNotFoundError as e:
        print('init() Exception: {} - {}'.format(e, sys.exc_info()[0]))
Exemplo n.º 6
0
 def __init__(self):
     global FULL_SCREEN, SUBPIX, ORDER_GROUP, TEST
     self.ww, self.hh  = 640, 480
     if TEST: self.n, self.i, self.x, self.y, self.w, self.h, self.o, self.g = [12, 12, 0, 0], [0, 0, 0, 0], [4, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 0, 0], []
     else:    self.n, self.i, self.x, self.y, self.w, self.h, self.o, self.g =  [1, 2, 6, 20], [0, 0, 0, 0], [0, 4, 0, 0], [0, 4, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [2, 0, 0, 3], []
     self.argMap = cmdArgs.parseCmdLine(dbg=1)
     print('__init__(BGN) argMap={}'.format(self.argMap), file=DBG_FILE)
     if 'n' in self.argMap and len(self.argMap['n'])  > 0: self.n            = [int(self.argMap['n'][i]) for i in range(len(self.argMap['n']))]
     if 'x' in self.argMap and len(self.argMap['x'])  > 0: self.x            = [int(self.argMap['x'][i]) for i in range(len(self.argMap['x']))]
     if 'y' in self.argMap and len(self.argMap['y'])  > 0: self.y            = [int(self.argMap['y'][i]) for i in range(len(self.argMap['y']))]
     if 'w' in self.argMap and len(self.argMap['w'])  > 0: self.ww           =  int(self.argMap['w'][0])
     if 'h' in self.argMap and len(self.argMap['h'])  > 0: self.hh           =  int(self.argMap['h'][0])
     if 'o' in self.argMap and len(self.argMap['o'])  > 0: self.o            = [int(self.argMap['o'][i]) for i in range(len(self.argMap['o']))]
     if 'i' in self.argMap and len(self.argMap['i'])  > 0: self.i            = [int(self.argMap['i'][i]) for i in range(len(self.argMap['i']))]
     if 'f' in self.argMap and len(self.argMap['f']) == 0: FULL_SCREEN       = 1
     if 'g' in self.argMap and len(self.argMap['g']) == 0: ORDER_GROUP       = 1
     if 's' in self.argMap and len(self.argMap['s']) == 0: SUBPIX            = 1
     if 't' in self.argMap and len(self.argMap['t']) == 0: TEST              = 1
     print('[n]            n={}'.format(self.n),          file=DBG_FILE)
     print('[x]            x={}'.format(self.x),          file=DBG_FILE)
     print('[y]            y={}'.format(self.y),          file=DBG_FILE)
     print('[w]           ww={}'.format(self.ww),         file=DBG_FILE)
     print('[h]           hh={}'.format(self.hh),         file=DBG_FILE)
     print('[o]            o={}'.format(self.o),          file=DBG_FILE)
     print('[i]            i={}'.format(self.i),          file=DBG_FILE)
     print('[f]  FULL_SCREEN={}'.format(FULL_SCREEN),     file=DBG_FILE)
     print('[g]  ORDER_GROUP={}'.format(ORDER_GROUP),     file=DBG_FILE)
     print('[s]       SUBPIX={}'.format(SUBPIX),          file=DBG_FILE)
     print('[t]         TEST={}'.format(TEST),            file=DBG_FILE)
     self.fontBold, self.fontItalic = 1, 1
     self.fontNameIndex, self.fontColorIndex, self.fontSizeIndex, self.fontDpiIndex = 0, 0, len(FONT_SIZES)//3, 3
     self._initWindowA()
     super().__init__(screen=self.screens[1], fullscreen=FULL_SCREEN, resizable=True, visible=False)
     self._initWindowB()
     self.symb, self.symbStr, self.mods, self.modsStr, self.kbk = 0, '', 0, '', 0
     self.sprites = []
     self._init() if not TEST else self._initTestColors()
     print('__init__(END)'.format(), file=DBG_FILE)