Compare commits
No commits in common. "57a2d60dc08aa126f3fa0a45a9199dea79c06118" and "0f1bc9cf2a3029b1c701e0b93aa97b67381dd2cb" have entirely different histories.
57a2d60dc0
...
0f1bc9cf2a
|
@ -1,32 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import itertools
|
|
||||||
import sys
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
|
|
||||||
def solve(input: List[str]) -> int:
|
|
||||||
x, y = 0, 0
|
|
||||||
|
|
||||||
for instruction in input:
|
|
||||||
dir, length = instruction.split(" ")
|
|
||||||
length = int(length)
|
|
||||||
if dir == "forward":
|
|
||||||
x += length
|
|
||||||
elif dir == "down":
|
|
||||||
y += length
|
|
||||||
elif dir == "up":
|
|
||||||
y -= length
|
|
||||||
else:
|
|
||||||
assert False
|
|
||||||
|
|
||||||
return x * y
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
input = [line.strip() for line in sys.stdin.readlines()]
|
|
||||||
print(solve(input))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
1000
2021/d02/ex1/input
1000
2021/d02/ex1/input
File diff suppressed because it is too large
Load diff
|
@ -1,33 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import itertools
|
|
||||||
import sys
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
|
|
||||||
def solve(input: List[str]) -> int:
|
|
||||||
x, y, aim = 0, 0, 0
|
|
||||||
|
|
||||||
for instruction in input:
|
|
||||||
dir, length = instruction.split(" ")
|
|
||||||
length = int(length)
|
|
||||||
if dir == "forward":
|
|
||||||
x += length
|
|
||||||
y += length * aim
|
|
||||||
elif dir == "down":
|
|
||||||
aim += length
|
|
||||||
elif dir == "up":
|
|
||||||
aim -= length
|
|
||||||
else:
|
|
||||||
assert False
|
|
||||||
|
|
||||||
return x * y
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
input = [line.strip() for line in sys.stdin.readlines()]
|
|
||||||
print(solve(input))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
1000
2021/d02/ex2/input
1000
2021/d02/ex2/input
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue