Created
December 2, 2016 10:58
-
-
Save ztane/6223e979d72ace99b070510a69945aca to your computer and use it in GitHub Desktop.
Advent of Code helpers for Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# advent of code helpers for Python 3 | |
def input_file(filename='input'): | |
""" | |
Read the input from current working directory, | |
return as a string stripped | |
""" | |
with open(input) as f: | |
return f.read().strip() | |
def input_lines(filename='input'): | |
""" | |
Return the input lines as a list | |
""" | |
return list(filter(bool, map(str.strip, input_file(filename).splitlines()))) | |
def clamp(value, min_, max_): | |
""" | |
Clamp the given value so that min_ <= value <= max_ | |
""" | |
if value < min_: | |
return min_ | |
if value > max_: | |
return max_ | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment