def read_matrix(fname: str) -> Matrix: lines: List[str] = helper.read_lines(fname) matrix = [] for line in lines: matrix.append(tuple(list(line))) # return tuple(matrix)
def main() -> None: # lines = helper.read_lines("example.txt") lines: List[str] = helper.read_lines("input.txt") timestamp: int = int(lines[0]) buses: Tuple[int, ...] = tuple( int(item) for item in lines[1].split(",") if item != 'x') print(timestamp) print(buses) print("----------") can_go = True counter = timestamp while can_go: for n in buses: if counter % n == 0: print(counter) print(n) print("----------") result = (counter - timestamp) * n print("result:", result) can_go = False break # # counter += 1
def main() -> None: # lines = helper.read_lines("example2.txt") lines = helper.read_lines("input.txt") prg = Program(lines) prg.start() print(prg.get_result())
def main() -> None: # lines = helper.read_lines("example0.txt") # lines = helper.read_lines("example.txt") lines = helper.read_lines("input.txt") hexa = Hexa(lines) # hexa.show_directions() hexa.start()
def main() -> None: # lines = helper.read_lines("example.txt") lines = helper.read_lines("input.txt") ship = Ship(lines) ship.start() print(ship.get_result())
def main() -> None: # lines = helper.read_lines("example0.txt") # lines = helper.read_lines("example.txt") lines = helper.read_lines("input.txt") hexa = Hexa(lines) # hexa.show_directions() hexa.start() # pprint(hexa.d) print(hexa.get_result())
def main() -> None: # lines = helper.read_lines("example.txt") lines = helper.read_lines("input.txt") grid = Layout(lines) while grid.evolve(): pass # print(grid.number_of_seats())
def main(): # lines = helper.read_lines("example.txt") # lines = helper.read_lines("example2.txt") lines = helper.read_lines("input.txt") foods = part1.Foods(lines) foods.start() # print("Part 1:", foods.get_result()) part2 = Part2(foods) part2.start()
def main(): # lines = helper.read_lines("example.txt") # lines = helper.read_lines("example2.txt") lines = helper.read_lines("input.txt") foods = Foods(lines) foods.start() # for f in foods.foods: # print(f) # print("-----------------") # for f in foods.backup_foods: # print(f) print(foods.get_result())
def main() -> None: # lines = helper.read_lines("example.txt") lines = helper.read_lines("input.txt") cube = Cube(lines) for i in range(0, 6+1): # cube.show() print("Cycle:", i) print(cube.get_number_of_active_cubes()) print("------------") if i == 6: break cube.evolve()
def main() -> None: line = helper.read_lines("input.txt")[0] program = tuple([int(n) for n in line.split(",")]) ampl = Amplifier(program) size = 50 for y in range(size): for x in range(size): ampl.reset() ampl.set_input([x, y]) ampl.run() out = ampl.get_output() print(out, end="") # print()
def create_fields_csv(self, text_logfile, logfile): self.logger.info("Create fields csv.") try: self.logger.info("get logfile [%s] content.%s" % (logfile, text_logfile)) log_lines = helper.read_lines(text_logfile) return [ reduce(lambda x, y: x + self.log_split_symbol + y, field) for field in [[ self.logbee_ealsticsearch_index, self.log_work_name, os.path.basename(logfile), helper.get_str_time(), line ] for line in log_lines if line] ] except Exception as e: self.logger.error("get logfile [%s] content fail.%s \n %s" % (logfile, text_logfile, e)) return []
def main() -> None: # line = "1 + 2 * 3 + 4 * 5 + 6" # 71 # line = "1 + (2 * 3) + (4 * (5 + 6))" # 51 # line = "2 * 3 + (4 * 5)" # 26 # line = "5 + (8 * 3 + 9 + 3 * 4 * 3)" # 437 # line = "5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))" # 12240 # line = "((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2" # 13632 # hw = Homework(line) # print(hw) # print(hw.get_value()) lines: List[str] = helper.read_lines("input.txt") total = 0 for line in lines: hw = Homework(line) total += hw.get_value() # print(total)
def __work_for_fail(self, lock): self.logger.info("work for send redis fail content.") if os.path.exists(self.work_cache_file) and os.path.isfile( self.work_cache_file): self.logger.info("scan fail log file %s" % self.work_cache_file) lock.acquire(1) content_list = helper.read_lines(self.work_cache_file) self.logger.debug("clean fail log file %s" % self.work_cache_file) self.logbee_work_fileio.clear() # common.write_file(self.work_cache_file) # os.system("echo ''>%s"%work_fail_log_dir) lock.release() for content in content_list: if re.match( '^%s%s%s(.){1,}' % (self.logbee_ealsticsearch_index, self.log_split_symbol, self.log_work_name), content): self.logger.info("send fail field log to redis.") try: self.work_redis_connetion_pool.lpush( self.logbee_ealsticsearch_index, content) except Exception as e: self.logger.warning("send to redis fail.%s" % e) self.to_send_redis_fail_fileio(content, lock)
def main(): lines = helper.read_lines("example.txt") # lines = helper.read_lines("input.txt") for line in lines: print(line)