Skip to content

Instantly share code, notes, and snippets.

@ztane
Created December 2, 2016 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ztane/6223e979d72ace99b070510a69945aca to your computer and use it in GitHub Desktop.
Save ztane/6223e979d72ace99b070510a69945aca to your computer and use it in GitHub Desktop.
Advent of Code helpers for Python 3
# 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