소스 검색

Day 5.

master
Chris Smith 6 년 전
부모
커밋
7c01d4305c
2개의 변경된 파일1068개의 추가작업 그리고 0개의 파일을 삭제
  1. 12
    0
      05.py
  2. 1056
    0
      data/05.txt

+ 12
- 0
05.py 파일 보기

@@ -0,0 +1,12 @@
1
+def execute(instructions, incrementor, position=0):
2
+    while 0 <= position < len(instructions):
3
+        next_position = position + instructions[position]
4
+        instructions[position] += incrementor(instructions[position])
5
+        position = next_position
6
+        yield position
7
+
8
+
9
+with open('data/05.txt', 'r') as file:
10
+    instructions = list(map(int, file.readlines()))
11
+    print(f'Part one: {sum(1 for _ in execute(list(instructions), lambda x: 1))}')
12
+    print(f'Part two: {sum(1 for _ in execute(list(instructions), lambda x: -1 if x >= 3 else 1))}')

+ 1056
- 0
data/05.txt
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


Loading…
취소
저장