def get_map_array(map): array = [] for map_row in map: array.append(functions.split_string(map_row)) return array
def function(input): group_answers = functions.get_data_from_string(input, '\n\n') yes_answers = [] sum = 0 for group_answer in group_answers: answers = functions.get_data_from_string(group_answer) yes = 0 questions = [] for i, answer in enumerate(answers): letters = functions.split_string(answer) if i == 0: yes = len(letters) for letter in letters: questions.append(letter) continue for letter in letters: if letter not in questions: questions.append(letter) yes += 1 yes_answers.append(yes) for yes_answer in yes_answers: sum += yes_answer return sum
def function(input): map = functions.get_data_from_string(input) length = 0 trees = 0 pos = 1 for i in range(len(map)): if length == 0: length = len(map[i]) if length < pos: pos -= length if i == 0: pos += 3 continue map_elements = functions.split_string(map[i]) map_element = map_elements[pos - 1] if map_element == '#': trees += 1 pos += 3 return trees
def get_seat_map(input): rows = functions.get_data_from_string(input) seat_map = dict() for i, row in enumerate(rows): seat_map[i] = dict() seats = functions.split_string(row) for j, seat in enumerate(seats): seat_map[i][j] = seat return seat_map
def function(input): seats = functions.get_data_from_string(input) seat_ids = [] missing_seat_id = 0 for seat in seats: seat_desc = functions.split_string(seat) lowest_row = 0 highest_row = 127 lowest_col = 0 highest_col = 7 rows = 128 cols = 8 row = 0 col = 0 for direction in seat_desc: if direction == 'F': rows /= 2 highest_row -= rows elif direction == 'B': rows /= 2 lowest_row += rows elif direction == 'R': cols /= 2 lowest_col += cols elif direction == 'L': cols /= 2 highest_col -= cols if highest_col == lowest_col: col = highest_col if highest_row == lowest_row: row = highest_row seat_id = row * 8 + col seat_ids.append(int(seat_id)) sorted_seat_ids = sorted(seat_ids) for i in range(sorted_seat_ids[0], sorted_seat_ids[-1] + 1): if i not in sorted_seat_ids: missing_seat_id = i break return missing_seat_id
def function(input): list_entries = functions.get_data_from_string(input) valid_passwords = 0 for entry in list_entries: parts = entry.split(' ') [pos1, pos2] = parts[0].split('-') letter = parts[1].strip(':') password_letters = functions.split_string(parts[2]) if (password_letters[int(pos1) - 1] == letter and password_letters[int(pos2) - 1] != letter) or ( password_letters[int(pos1) - 1] != letter and password_letters[int(pos2) - 1] == letter): valid_passwords += 1 return valid_passwords
def function(input): seats = functions.get_data_from_string(input) highest_seat_id = 0 for seat in seats: seat_desc = functions.split_string(seat) lowest_row = 0 highest_row = 127 lowest_col = 0 highest_col = 7 rows = 128 cols = 8 row = 0 col = 0 for direction in seat_desc: if direction == 'F': rows /= 2 highest_row -= rows elif direction == 'B': rows /= 2 lowest_row += rows elif direction == 'R': cols /= 2 lowest_col += cols elif direction == 'L': cols /= 2 highest_col -= cols if highest_col == lowest_col: col = highest_col if highest_row == lowest_row: row = highest_row seat_id = row * 8 + col if seat_id > highest_seat_id: highest_seat_id = int(seat_id) return highest_seat_id
def function(input): group_answers = functions.get_data_from_string(input, '\n\n') yes_answers = [] sum = 0 for group_answer in group_answers: answers = functions.get_data_from_string(group_answer) member = len(answers) yes = 0 questions = {} for i, answer in enumerate(answers): letters = functions.split_string(answer) if i == 0: for letter in letters: if letter not in questions: questions[letter] = 1 continue for letter in letters: if letter not in questions: questions[letter] = 1 else: questions[letter] += 1 for char in questions: num = questions[char] if num == member: yes += 1 yes_answers.append(yes) for yes_answer in yes_answers: sum += yes_answer return sum
def function(input): list_entries = functions.get_data_from_string(input) valid_passwords = 0 for entry in list_entries: parts = entry.split(' ') [min, max] = parts[0].split('-') letter = parts[1].strip(':') password_letters = functions.split_string(parts[2]) letters_count = 0 for password_letter in password_letters: if password_letter != letter: continue letters_count += 1 if letters_count > int(max): break if int(max) >= letters_count >= int(min): valid_passwords += 1 return valid_passwords
def function(input): map = functions.get_data_from_string(input) slopes = [ [ 1, 1 ], [ 3, 1 ], [ 5, 1 ], [ 7, 1 ], [ 1, 2 ] ] length = 0 trees_per_slope = [] for slope in slopes: [right, down] = slope trees = 0 pos = 1 downwards = 0 for i in range(len(map)): if length == 0: length = len(map[i]) if length < pos: pos -= length if i == 0: pos += right downwards += 1 continue if downwards < down: downwards += 1 continue else: downwards = 0 map_elements = functions.split_string(map[i]) map_element = map_elements[pos - 1] if map_element == '#': trees += 1 pos += right downwards += 1 trees_per_slope.append(trees) result = 1 for trees in trees_per_slope: result *= trees return result