Add game of life algorithm for fun
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
|
||||
|
||||
def enhance(algorithm, in_image, boundary):
|
||||
@@ -30,9 +31,9 @@ def show(image):
|
||||
for y in range(min_y, max_y):
|
||||
for x in range(min_x, max_x):
|
||||
if (x, y) in image:
|
||||
print('#', end='')
|
||||
print('█', end='')
|
||||
else:
|
||||
print('.', end='')
|
||||
print('░', end='')
|
||||
print()
|
||||
|
||||
|
||||
@@ -59,9 +60,22 @@ def part_2(input):
|
||||
print("Part 2 result:", result)
|
||||
|
||||
|
||||
def game_of_life(input):
|
||||
result = 0
|
||||
algorithm = '.......#...#.##....#.###.######....#.##..##.#....######.###.#......#.##..##.#....######.###.#....##.#...#.......###.#...#..........#.##..##.#....######.###.#....##.#...#.......###.#...#........##.#...#.......###.#...#.......#...............#..................#.##..##.#....######.###.#....##.#...#.......###.#...#........##.#...#.......###.#...#.......#...............#................##.#...#.......###.#...#.......#...............#...............#...............#...............................................'
|
||||
image = set([(x, y) for y, line in enumerate(input[2:])
|
||||
for x, c in enumerate(line) if c == '#'])
|
||||
while True:
|
||||
image = enhance(algorithm, image, 0)
|
||||
show(image)
|
||||
print()
|
||||
sleep(0.1)
|
||||
|
||||
|
||||
input = list()
|
||||
p = Path(__file__).with_name('input.txt')
|
||||
p = Path(__file__).with_name('input2.txt')
|
||||
with open(p) as f:
|
||||
input = f.readlines()
|
||||
part_1(input)
|
||||
part_2(input)
|
||||
# game_of_life(input)
|
||||
|
||||
Reference in New Issue
Block a user