mirror of
https://github.com/thib8956/advent-of-code.git
synced 2025-01-15 06:11:06 +00:00
accept input file as cmdline argument
This commit is contained in:
parent
89b6b5e107
commit
87871aed4d
@ -17,6 +17,8 @@ def main(inp):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
with open("input.txt") as inp:
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
with open(infile) as inp:
|
||||||
main(inp.readlines())
|
main(inp.readlines())
|
||||||
|
|
||||||
|
@ -32,10 +32,13 @@ def test_part2():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Part 1 - total mass: ", calculate_total_fuel_mass("./input.txt"))
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
|
||||||
|
print("Part 1 - total mass: ", calculate_total_fuel_mass(infile))
|
||||||
|
|
||||||
test_part2()
|
test_part2()
|
||||||
print(
|
print(
|
||||||
"Part 2 -- total mass: ",
|
"Part 2 -- total mass: ",
|
||||||
calculate_total_fuel_mass("./input.txt", calculate_fuel_iterative),
|
calculate_total_fuel_mass(infile, calculate_fuel_iterative),
|
||||||
)
|
)
|
||||||
|
@ -54,7 +54,9 @@ def run_program(memory, noun, verb):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
tests()
|
tests()
|
||||||
with open("input.txt") as inp:
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
with open(infile) as inp:
|
||||||
memory = [int(x) for x in inp.readline().strip().split(",")]
|
memory = [int(x) for x in inp.readline().strip().split(",")]
|
||||||
# Pass a copy to avoid modifying the original memory
|
# Pass a copy to avoid modifying the original memory
|
||||||
print("Part 1 answer: ", run_program(memory[:], 12, 2))
|
print("Part 1 answer: ", run_program(memory[:], 12, 2))
|
||||||
|
@ -70,8 +70,9 @@ def tests():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
tests()
|
tests()
|
||||||
|
import sys
|
||||||
with open("input.txt") as raw_input:
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
with open(infile) as raw_input:
|
||||||
lines = raw_input.readlines()
|
lines = raw_input.readlines()
|
||||||
wire1, wire2 = [line.strip("\n").split(",") for line in lines]
|
wire1, wire2 = [line.strip("\n").split(",") for line in lines]
|
||||||
print("Part 1 -- distance = ", find_min_distance(wire1, wire2))
|
print("Part 1 -- distance = ", find_min_distance(wire1, wire2))
|
||||||
|
@ -40,5 +40,7 @@ def part2(infile):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
part1("./input.txt")
|
import sys
|
||||||
part2("./input.txt")
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
part1(infile)
|
||||||
|
part2(infile)
|
||||||
|
@ -39,4 +39,6 @@ def main(input_file):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main("input.txt")
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
main(infile)
|
||||||
|
@ -64,4 +64,6 @@ def main(input_file):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main("input.txt")
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
main(infile)
|
||||||
|
@ -94,4 +94,6 @@ def main(input_file):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main("input.txt")
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
main(infile)
|
||||||
|
@ -35,7 +35,7 @@ def main(infile):
|
|||||||
print(res)
|
print(res)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main("input.txt")
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
main(infile)
|
||||||
|
@ -23,4 +23,6 @@ def main(infile):
|
|||||||
print(f"Part 2, {res}")
|
print(f"Part 2, {res}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main("input.txt")
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
main(infile)
|
||||||
|
@ -26,8 +26,10 @@ def part2(crabs):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
with open("input.txt") as infile:
|
import sys
|
||||||
crabs = [int(x) for x in infile.readline().split(",")]
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
with open(infile) as f:
|
||||||
|
crabs = [int(x) for x in f.readline().split(",")]
|
||||||
part1(crabs)
|
part1(crabs)
|
||||||
part2(crabs)
|
part2(crabs)
|
||||||
|
|
||||||
|
@ -43,4 +43,6 @@ def main(infile):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main("input.txt")
|
import sys
|
||||||
|
infile = sys.argv[1] if len(sys.argv) > 1 else "example.txt"
|
||||||
|
main(infile)
|
||||||
|
Loading…
Reference in New Issue
Block a user