Skip to content

Instantly share code, notes, and snippets.

@Xpktro
Last active December 3, 2017 07:10
Show Gist options
  • Save Xpktro/851c9549f8b17d11fc78efaf1f53c00b to your computer and use it in GitHub Desktop.
Save Xpktro/851c9549f8b17d11fc78efaf1f53c00b to your computer and use it in GitHub Desktop.
Advent of code 2017 solutions
captcha = """"""
def is_valid(captcha_to_solve):
def validator(item):
position, number = item
return number == captcha_to_solve[position + 1]
return validator
def solve(captcha_to_solve):
return sum(
map(
lambda i: int(i[1]),
filter(is_valid(captcha_to_solve), enumerate(captcha_to_solve[:-1]))
)
)
print(solve(captcha + captcha[0]))
captcha = """"""
def is_valid(captcha_to_solve, padding):
def validator(item):
position, number = item
return number == captcha_to_solve[position + padding]
return validator
def solve(captcha_to_solve):
length = int(len(captcha_to_solve) / 2)
return sum(
map(
lambda i: int(i[1]),
filter(
is_valid(captcha_to_solve, int(length / 2)),
enumerate(captcha_to_solve[:length])
)
)
)
print(solve(captcha * 2))
spreadsheet = """"""
spreadsheet = map(lambda r: list(map(int, r.split('\t'))), spreadsheet.split('\n'))
print(sum(map(lambda line: max(line) - min(line), spreadsheet)))
spreadsheet = """"""
spreadsheet = map(lambda r: list(map(int, r.split('\t'))), spreadsheet.split('\n'))
def number_evenly_divisible(row):
def is_number_divisible(number):
return len(list(filter(lambda row_number: number / row_number == number // row_number or row_number / number == row_number // number, row))) == 2
return is_number_divisible
def get_evenly_divisibles(row):
return list(filter(number_evenly_divisible(row), row))
print(sum(map(lambda line: max(line) / min(line), list(map(get_evenly_divisibles, spreadsheet)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment