def insert_script(script_number): ''' insert messages into messages table from script file. :parameter {chaptor_id} : chaptor index. :parameter {charactor_id} : charactor index. :parameter {message} : message. :return {} : None ''' lines = get_lines('scripts/%02d.txt' % script_number) count = 0 for line in lines: charactor, message = parse_line(line) if message is None: continue insert_script_with_charactor_name(1, charactor, message) print(count) count += 1
if path[i] in d[path[i-1]]: length += d[path[i-1]][path[i]] return length def shortest_hamiltonian_path(d): return min(map(lambda x: path_length(d, x), itertools.permutations(sorted(d.keys())))) def buildGraph(lines): d = {} for line in lines: f, (t, l) = parseLine(line) if not f in d.keys(): d[f] = {} if not t in d.keys(): d[t] = {} d[f][t] = l d[t][f] = l return shortest_hamiltonian_path(d) def solve(lines): d = buildGraph(lines) return d if __name__ == '__main__': lines = (get_lines('input9.txt')) print(solve(lines))
#!/usr/bin/python3 from parse import get_lines def diffLine(line): return len(line.strip()) - len(eval(line.strip())) def solve(lines): return sum(map(diffLine, lines)) if __name__ == '__main__': lines = (get_lines('input8.txt')) print(solve(lines))
with open(filename, 'r') as f: while True: line = f.readline().rstrip('\n') if line == '': break lines.append(line) except EOFError: pass return lines def solve(line): data = line.split(' ') out = data[0][0] for c in data[0][1:]: if ord(c) >= ord(out[0]): out = c + out else: out = out + c return out if __name__ == '__main__': lines = (get_lines('A-large.in')) cases = int(lines[0]) with open("outputA-large.txt", "w") as f: for case in range(0, cases): out = ("Case #%d: " % (case + 1)) + solve(lines[case + 1]) print(out) f.write(out + '\n')
#!/usr/bin/python3 import re from parse import get_lines def solve(lines): s = re.sub(r'[^0-9-]+', ' ', lines[0]) return sum(map(int, s.strip().split(' '))) if __name__ == '__main__': lines = (get_lines('input12.txt')) print(solve(lines))
def shortest_hamiltonian_path(d): return max( map(lambda x: path_length(d, x), itertools.permutations(sorted(d.keys())))) def buildGraph(lines): d = {} for line in lines: f, (t, l) = parseLine(line) if not f in d.keys(): d[f] = {} if not t in d.keys(): d[t] = {} d[f][t] = l d[t][f] = l return shortest_hamiltonian_path(d) def solve(lines): d = buildGraph(lines) return d if __name__ == '__main__': lines = (get_lines('input9.txt')) print(solve(lines))