def main(): import InputArgs data = InputArgs.getStrArray("6 3 7 2 0 1 9") print "ORIG:", " ".join(map(str, data)) Sort(data) print "SORT:", " ".join(map(str, data))
def main(): import InputArgs a = InputArgs.getStrArray("to be or not to be") print a s = ResizingArrayStack() while a: item = a.pop() print item if item != "-": s.push(item) elif not s.isEmpty(): print s.pop(), " " sys.stdout.write("({}) left on stack)".format(s.size())) for S in s: print S
def main(): import InputArgs import sys # read in the data a = InputArgs.getStrArray("a b c d e f") # shuffle the array shuffle(a) # print results. sys.stdout.write('{}\n'.format(' '.join(map(str, a))))
def default_examples(): import InputArgs as IA bag = run( IA.get_seq__int_or_str("1 2 3 4 5 6 7 8 9") )
self._current = self._current._next return item # Unit tests the <tt>Bag</tt> data type. def run(item_list): import sys bag = Bag() for item in item_list: bag.add(item) sys.stdout.write("size of bag = {}\n".format(bag.size())) for s in bag: sys.stdout.write(" BAG CONTAINS: {}\n".format(s)) def default_examples(): import InputArgs as IA bag = run( IA.get_seq__int_or_str("1 2 3 4 5 6 7 8 9") ) if __name__ == '__main__': import InputArgs as IA import sys if len(sys.argv) == 1: default_examples() else: run( IA.get_list_from_args() ) # Copyright (C) 2002-2010, Robert Sedgewick and Kevin Wayne. # Java last updated: Tue Mar 25 04:52:35 EDT 2014.
def run(item_list): import sys sys.stdout.write("\nRUNNING: {}\n".format(' '.join(item_list))) q = ResizingArrayQueue() for item in item_list: if item != "-": q.enqueue(item) else: sys.stdout.write(" DEQUEUE: {}\n".format(q.dequeue())) sys.stdout.write("({} left on queue): {}\n".format(q.size(), q)) if __name__ == '__main__': import InputArgs as IA import sys # If user did not provide a sequence. if len(sys.argv) == 1: run( IA.get_seq__int_or_str("a b c d - - e f - - g h i -") ) run( IA.get_seq__int_or_str("a - b - c d - - e f - - g h i -") ) # If user provided a sequence in the runtime arguments. else: run( IA.get_list_from_args() ) ########################################################################### # Lecture Week 2 Generics (9:26) ########################################################################### # ------------------------------------------------------------------------- # BAD: Before Java 1.5 (2004-09-29) # GRRRR JAVA(<1.5 2004), NO GENERIC SUPPORT = Separate container class for every type. # 02:00 BAD: Casting in client code: # # StackOfObjects s = new StackOfObjects();
def main(): import InputArgs a = InputArgs.getStrArray("S O R T E X A M P L E") Sort(a) print ' '.join(map(str,a))
def main(): import InputArgs a = InputArgs.getStrArray() Sort(a) print ' '.join(a)
def run_timed_fin(fin): """Run BinarySearch using integers stored in a column in a file.""" sys.stdout.write("\nRunning BinarySearch on data in: {}\n".format(fin)) run_timed(InputArgs.get_ints_from_file(fin))
class simturing: impArgs = InputArgs.InputArgs() impFile = InputFile.InputFile() outLine = Output.Output() machine = Machine.Machine() regex = Regex.Regex() prints = [] numSteps = 0 print( 'Simulador de Máquina de Turing - Version 2.0\nDesenvolvido como trabalho prático para a disciplina de Teoria da Computação.\nAna Paula Silva Cunha, IFMG, 2018.\nRodrigo Sousa Alves, IFMG, 2018.\n' ) # --------------------------------------------------------------- # --- 1. Ler argumentos (-r,-v,-s,-h, pathFile) via linha de comando paramArgs = impArgs.inputs() print('Argumentos de Entrada: ') print(paramArgs) # extrai parametros recebidos via argumento for p in paramArgs: if (p[0] == 'r') or (p[0] == 'v'): opcao = p[0] pathFile = p[1] elif (p[0] == 's'): opcao = p[0] steps = int(p[1]) pathFile = p[2] elif (p[0] == 'h'): head = p[1] if paramArgs is None: print( 'Informe os parâmentros de entrada, não há registro dos últimos parâmetros.' ) exit() palavra = input('Forneça a palavra inicial: ') # palavra = 'baab' if palavra == '': print('Forneça uma palavra.') exit(1) # --------------------------------------------------------------- # --- 2. Rodar baseado nesses argumentos # leitura do arquivo de entrada linesFile = impFile.inputs(pathFile) # executa e imprime apenas o final da fita prints = machine.run(palavra, head, linesFile) if opcao == 'r': # Executa a maquina print(prints.pop()) # executa e imprime passo a passo a fita elif opcao == 'v': # prints = machine.run(palavra, head, linesFile) for p in prints: print(p) # executa e imprime n passos da fita elif opcao == 's': # prints = machine.run(palavra, head, linesFile) if prints == None: print('500 interações') else: steps = int(steps) if steps > int(len(prints)): steps = len(prints) - 1 cont = steps for p in prints: if (cont != 0): print(p) cont -= 1 numSteps += steps while (True): op = input('\nForneça opção (-r, -v, -s) : ') print(op) if op is not '': opcao = op.split() # print('opcao: '+op) # executa e imprime apenas o final da fita if opcao[0] == '-r': # Executa a maquina # prints = machine.run(palavra, head, linesFile) print(prints.pop()) # executa e imprime passo a passo a fita elif opcao[0] == '-v': # prints = machine.run(palavra, head, linesFile) for p in prints: print(p) # executa e imprime n passos da fita elif (opcao[0] == '-s'): # prints = machine.run(palavra, head, linesFile) steps = int(opcao[1]) if steps > int(len(prints)): steps = len(prints) - 1 cont = steps cont2 = 0 for p in prints: if cont2 <= numSteps: cont2 += 1 else: # print('if not none -s') if (cont != 0): print(p) cont -= 1 numSteps += steps else: exit(1) else: # print('op '+op) # print('con '+str(cont)) # if len(opcao) > 1: # cont = int(opcao[1]) # steps = cont # else: cont = steps if steps > int(len(prints)): steps = len(prints) - 1 cont = steps cont2 = 0 for p in prints: if cont2 <= numSteps: cont2 += 1 else: # print('if not none -s')/ if (cont != 0): print(p) cont -= 1 numSteps += steps # print(outLine.newLineClear()) # line = [model, self.bloco, self.estado, self.esquerda, self.cabecote, self.direita] # line1 = outLine.newLine('main','1','E','()','ba') # print(line1[0]) # bloco = 'main' # estado = '10' # esquerda = '' # line = outLine.newLine(bloco,estado,esquerda,head,palavra) # print(line[0]) # line = outLine.moveCabecote(line,'d') # print(line[0]) # line = outLine.moveCabecote(line,'d') # print(line[0]) # line = outLine.alteraCabecote(line,'d','D') # print(line[0]) # line = outLine.moveCabecote(line,'e') # print(line[0]) # line = outLine.moveCabecote(line,'e') # print(line[0]) # line = 'bloco main 1 !' # par = regex.extraiParam(line) # print(par) # line = '10 moveFim 11' # par = regex.extraiParam(line) # print(par) # line = 'fim' # par = regex.extraiParam(line) # print(par) # line = '12 a -- A i 30' # par = regex.extraiParam(line) # print(par) # print('Cabecote: '+outLine.getCabecote(line)) # --- 3. Solicitar novos argumentos (-r,-v,-s) # --- 4. Rodar baseado nesses argumentos # # # extrairParam e executaParam parametros em funcoes separadas? # classe Machine com funcoes do tipo # modoR # Executa tudo # Imprime resultado # modoV # Executa tudo # exibe o passo a passo # modoS # executa n vezes # exibe passo a passo
def run_timed_fin(fin, cnt_fnc=count_enumerate): """Run ThreeSum using integers stored in a column in a file.""" sys.stdout.write('\nRunning ThreeSum on data in: {}\n'.format(fin)) run_timed(InputArgs.get_ints_from_file(fin), cnt_fnc)
def run(seqstr): import InputArgs as IA return run_list( IA.get_seq__int_or_str(seqstr) )