def main(): minterms = [] kmap_vars = 0 minterms, kmap_vars = get_input() print("Number of variables: ", kmap_vars) print("Minterm values: ", ', '.join(map(str, minterms))) if kmap_vars == 2: kmap2 = BuildMap().two_var_kmap() map_minterms(minterms, kmap2) two_variable_setup(kmap2) elif kmap_vars == 3: kmap3 = BuildMap().three_var_kmap() map_minterms(minterms, kmap3) three_variable_setup(kmap3) elif kmap_vars == 4: kmap4 = BuildMap().four_var_kmap() map_minterms(minterms, kmap4) four_variable_setup(kmap4)
return position = self.cur_x_pos % self.width check_pos = string_copy[position] if check_pos == '#': string_copy = string_copy[:position] + 'X' + string_copy[position + 1:] self.map[self.cur_line] = string_copy self.no_of_trees += 1 elif check_pos == '.': string_copy = string_copy[:position] + 'O' + string_copy[position + 1:] self.map[self.cur_line] = string_copy if __name__ == '__main__': map = get_input() ex_line: str = map[0] width = ex_line.find('\n') max_lines = len(map) list_of_res = [] for traj in list_of_trajectories: traveler = Traveler(width=width, max_lines=max_lines, map=copy(map), trajectory=traj) print(f"- Right {traj['Right']}, down {traj['Down']}") trees_hit = traveler.go() print(f"trees hit: {trees_hit}") list_of_res.append(trees_hit) print(f"{list_of_res} multiplied together:")
def check_tree(self): try: string_copy: str = copy(self.map[self.cur_line]) except IndexError: self.out = True self.show_map() print(f"number of trees hit: {self.no_of_trees}") return position = self.cur_x_pos % self.width check_pos = string_copy[position] if check_pos == '#': string_copy = string_copy[:position] + 'X' + string_copy[position + 1:] self.map[self.cur_line] = string_copy self.no_of_trees += 1 elif check_pos == '.': string_copy = string_copy[:position] + 'O' + string_copy[position + 1:] self.map[self.cur_line] = string_copy if __name__ == '__main__': in_txt = get_input() ex_line: str = in_txt[0] dude = Traveler(width=ex_line.find('\n'), max_lines=len(in_txt), map=in_txt) # dude.show_map() while not dude.out: dude.move()
def display_seats(): global count count += 1 print(f'-----------------{count}-----------------') for row in seats_matrix: if row.endswith('\n'): print(row, end='') else: print(row) def count_occupied(): cnt = 0 for row in seats_matrix: cnt += Counter(row)['#'] return cnt if __name__ == '__main__': in_txt = make_seats_occupied_for_some_reason(get_input()) seats_matrix = in_txt old_seating = [] make_seat_objects() while not old_seating == seats_matrix: old_seating = copy(seats_matrix) apply_rule_on_all_seats() display_seats() print(f'Number of occupied seats are now: {count_occupied()}')
from input_getter import get_input import re if __name__ == '__main__': password_list = get_input() ok_passwords = 0 for line in password_list: match = re.findall(r'(\d*)-(\d*) (.): (.*)', line)[0] print(f"{line[:-1]}") lower = int(match[0]) higher = int(match[1]) letter = match[2] password = match[3] instances = 0 for char in password: if char == letter: instances += 1 print(f"instances of '{letter}' is {instances}") if instances < lower: print("too few") continue elif instances > higher: print("too many!") continue print("ok!") ok_passwords += 1 print(f"total ok: {ok_passwords}")
def get_row(row_c: str) -> int: binary_version = row_c.replace('F', '0') binary_version = binary_version.replace('B', '1') binary_value = int(binary_version, 2) return binary_value def get_column(row_c: str) -> int: binary_version = row_c.replace('L', '0') binary_version = binary_version.replace('R', '1') binary_value = int(binary_version, 2) return binary_value if __name__ == '__main__': ticket_list = get_input() seats_matrix = [['E'] * 128 for i in range(8)] for ticket in ticket_list: row_code = ticket[:7] column_code = ticket[7:] column_code = column_code.replace('\n', '') row = get_row(row_code) col = get_column(column_code) try: seats_matrix[col][row] = 'X' except IndexError: print(f"row:{row} col:{col} is out of range") raise seat_id = row * 8 + col