Luna Lailatova
3 years ago
4 changed files with 258 additions and 0 deletions
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
import sys |
||||
|
||||
class img: |
||||
def __init__(self): |
||||
self.y = [] |
||||
|
||||
def addline(self, line): |
||||
self.y.append(line) |
||||
|
||||
def get_num(self,y,x, test): |
||||
number='' |
||||
if y != 0 and x != 0: number += self.y[y - 1][x - 1] |
||||
else: number += test |
||||
if y !=0: number += self.y[y - 1][x] |
||||
else: number += test |
||||
if y != 0 and x != len(self.y[0]) - 1: number += self.y[y - 1][x + 1] |
||||
else: number += test |
||||
if x != 0: number += self.y[y][x - 1] |
||||
else: number += test |
||||
number += self.y[y][x] |
||||
if x != len(self.y[0]) - 1: number += self.y[y][x + 1] |
||||
else: number += test |
||||
if y != len(self.y) - 1 and x != 0: number += self.y[y + 1][x - 1] |
||||
else: number += test |
||||
if y != len(self.y) - 1: number += self.y[y + 1][x] |
||||
else: number += test |
||||
if y != len(self.y) - 1 and x != len(self.y[0]) - 1: number += self.y[y + 1][x + 1] |
||||
else: number += test |
||||
number = number.replace('.', '0') |
||||
number = number.replace('#', '1') |
||||
|
||||
return (int(number, 2)) |
||||
|
||||
def enhance(self, test): |
||||
new_image = [] |
||||
self.y.insert(0, test*len(self.y[0])) |
||||
self.y.append(test*len(self.y[0])) |
||||
for i in range(len(self.y)): |
||||
self.y[i] = test + self.y[i] + test |
||||
for i in range(len(self.y)): |
||||
new_line = '' |
||||
for t in range(len(self.y[i])): |
||||
num = self.get_num(i,t,test) |
||||
new_line += algorithm[num] |
||||
new_image.append(new_line) |
||||
self.y = new_image.copy() |
||||
|
||||
def count(self): |
||||
counter = 0 |
||||
for f in self.y: |
||||
for g in f: |
||||
if g == '#': |
||||
counter += 1 |
||||
return(counter) |
||||
|
||||
|
||||
image = img() |
||||
|
||||
with open(sys.argv[1], 'r') as f: |
||||
toggle = False |
||||
for g in f.readlines(): |
||||
g = g.strip() |
||||
if g == '': |
||||
toggle = True |
||||
if not toggle: |
||||
algorithm = g |
||||
if toggle and g != '': |
||||
image.addline(g) |
||||
|
||||
for i in range(25): |
||||
image.enhance('.') |
||||
image.enhance('#') |
||||
|
||||
print(image.count()) |
||||
|
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
import sys |
||||
|
||||
class img: |
||||
def __init__(self): |
||||
self.y = [] |
||||
|
||||
def addline(self, line): |
||||
self.y.append(line) |
||||
|
||||
def get_num(self,y,x): |
||||
number='' |
||||
if y != 0 and x != 0: number += self.y[y - 1][x - 1] |
||||
else: number += '.' |
||||
if y !=0: number += self.y[y - 1][x] |
||||
else: number += '.' |
||||
if y != 0 and x != len(self.y[0]) - 1: number += self.y[y - 1][x + 1] |
||||
else: number += '.' |
||||
if x != 0: number += self.y[y][x - 1] |
||||
else: number += '.' |
||||
number += self.y[y][x] |
||||
if x != len(self.y[0]) - 1: number += self.y[y][x + 1] |
||||
else: number += '.' |
||||
if y != len(self.y) - 1 and x != 0: number += self.y[y + 1][x - 1] |
||||
else: number += '.' |
||||
if y != len(self.y) - 1: number += self.y[y + 1][x] |
||||
else: number += '.' |
||||
if y != len(self.y) - 1 and x != len(self.y[0]) - 1: number += self.y[y + 1][x + 1] |
||||
else: number += '.' |
||||
number = number.replace('.', '0') |
||||
number = number.replace('#', '1') |
||||
|
||||
return (int(number, 2)) |
||||
|
||||
def enhance(self): |
||||
new_image = [] |
||||
self.y.insert(0, '.'*len(self.y[0])) |
||||
self.y.append('.'*len(self.y[0])) |
||||
for i in range(len(self.y)): |
||||
self.y[i] = '.' + self.y[i] + '.' |
||||
for i in range(len(self.y)): |
||||
new_line = '' |
||||
for t in range(len(self.y[i])): |
||||
num = self.get_num(i,t) |
||||
new_line += algorithm[num] |
||||
new_image.append(new_line) |
||||
self.y = new_image.copy() |
||||
|
||||
def count(self): |
||||
counter = 0 |
||||
for f in self.y: |
||||
for g in f: |
||||
if g == '#': |
||||
counter += 1 |
||||
return(counter) |
||||
|
||||
|
||||
image = img() |
||||
|
||||
with open(sys.argv[1], 'r') as f: |
||||
toggle = False |
||||
for g in f.readlines(): |
||||
g = g.strip() |
||||
if g == '': |
||||
toggle = True |
||||
if not toggle: |
||||
algorithm = g |
||||
if toggle and g != '': |
||||
image.addline(g) |
||||
|
||||
image.enhance() |
||||
image.enhance() |
||||
|
||||
print(image.count()) |
||||
|
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
#.#.....##...##..#.#......#.#...#.#.#...###.##......###.##.##..##.#...#.....###.#.....#.#.#...#.#..###.###..###..#..##..###..##..##.##.#..###########.##....#.#......#...#.###..###...#.####..########.#####.#.#..##.##.##..###.##.####.#..##.##..#...#####..#.#.##.##...##..#..##.....###.#.#....####.##.#...##.########.#.##.#.....###....#..###.####....############.#.##...#.####...#...##.#.#..#..#......#..##...#.########.#.#...#####..#..######.#.#.....#####...##.###.#.#.##.........#.#.##..##.#..#..##..##.###.##.##. |
||||
|
||||
#.#...##.#.##.##...#......##....##...#.#....##.##.#.##....###.#####.#......###......#.#.##.####..#.# |
||||
#.#...###.#.#.#...##...###....#####.#...#.####..########.#.#.#..#.###..##..#.####....#.#..#..##.#### |
||||
.....#.######..#.#.....#..#..####.########..#.#.####..#####..##.#..##..##.##.#..###.#.#.#.#...#..### |
||||
#.#........#.###.#..######.##..#.##...#.....#.#.......#.##.....#.###.##.#..##..#.##...##...##.####.. |
||||
#...#.#.##..###..#..####..#####.##...###.#....#..###..#.#....####..####.####..#..###.####.###.#..### |
||||
#..###..##.#....#.##..##.#..#.##....#.#.#.##..#.#.##..#..##.....#####..#..##.##.##..#.#####.###.#... |
||||
..####..##...#....##.#...#######..#....##.###...#.#.........##........###.#.##....#.#.###...#...###. |
||||
#######..#......##...##..###..##.#..##.#...###..##..#.#.##....##...##.#..##..##....#..###...##...#.. |
||||
.###.....#..#..##....#...#.##.#..#.#.#...#..#...#..#.#.###.####..#.###.###.###.#.#..#....#.#.#.#.##. |
||||
...##.#.#.#..#..#..#.#.##..#.....#...#####..#####..#.#..#...##..#..#...###.....#...#.#.#....#..##.## |
||||
.#####.##.##..#...###.#....##...###..#..#...#...########..#.#...#.#..####........####...###...##.... |
||||
.#..#..#.#....##..#.###...#..#.###...##.###.##.#...#####....#.###..#.#..#....#.##..#.......#.....#.# |
||||
.#..##..#..####..##.#.#..##..###..#.......#...#...#.####.#.#.#..#.##......#.##.###.###.####.##.#.### |
||||
.##..##.#..##..#.##.###...#.#####.#.#.#.##...#..#...##..##...#..###.###.##..##.#######.###....###### |
||||
....#.#..##...#..#####...##.#.##......#.###.#.#.###..#...###..##.#..#..####..#.#....#..#.####...#..# |
||||
.#..##..##...#.####.#####.#######.######.####.......#.#.###.##.#.#.#.#.##.....#....#....#..###....## |
||||
###.##..#.#.#.#.#..#######.#.########.#.#.#..####.#####.#.#..##..#..##.....#...#....#.##.##.#....#.# |
||||
#..#.####.####.##.####...#.###.#.##......###..##.####..#..####..##.#.#....##..##.######...#..##..... |
||||
#.##...#...#..##...#.#......#..######.#.###.####..#######..#.##...#.#...#.##..###.#####..#...#.####. |
||||
##.###.#.######.#...#..##.#...#..##.##.....###..#.##.#..#..####....#.##.##..#.#..#.#....#.....####.. |
||||
.#.##.##.###..#...#.#.#.#.#.......#.####.#####..####.#....##.#...##.##.#.#.##.#..#.###.##..###...#.# |
||||
#.###.#.##.#.........#..#.#.#.#..##.#..##.#####.###.#.#..#.#.#..##..###..#.##.####.#..#...###.....## |
||||
##..#####.#...#.....###.#.#...##.####..#..###....##...#.##.##.##...#.###..#.##...........###.####.## |
||||
.###....###.#..#.#..#..#.###..########..##......########.#..#######...#........#.#######..####..#..# |
||||
####......#...#..#...#.######..#.##.#.##....#.##.#.#.##.#....##...###..##....#.#.##.##.....###.#.##. |
||||
.#.####.##..##.#.#.#.##.###.##....#..#...#.###.#.#...#.....##..##.####....#..######.#.#.#.##...#...# |
||||
...#.##...##..##.###..###....#..##.....#####.#.#..#.....##..##.###..##..##.##.....#.#..##.#..###..#. |
||||
..##....####...##.....###.#...#.###...##.#.#..##.###....###.##........#.#..#..##..#.######..##...... |
||||
###.##.##.#...##.#...###.##.##.######.###.###..###.#....#.#....#.#.#...###..###.#.#...######.#...### |
||||
..#.####.########.####.#.#...#..##...##...###..####.###..##..#.##..###..#.####.###..#.#.#.#######..# |
||||
###..#.##.##.#..#..#.#..#.###...#...#.##.#####.#.###.#.###.#.##..#...#.#...##...###.....#..###....## |
||||
..####.#....####..#.##.....#..#.#.###.###.#.#......#.....####.......##.#.######..####..#######.#..## |
||||
.##.#.#..#..###....#....#...##.##.###..##.##...#.######......##....##..#.#.#..##..#####....#.#...#.. |
||||
##...##..#...#.#######..#.....#..##.....#####..#...##.###.####.###..###...#..###........###.##.#.### |
||||
...###.#....#...##.....##.####..##.##.#.#..##.######.#..###.##.....##.####..#..##.###.##..###.###..# |
||||
#.#...##....#....#.##....##...##..#.#...######..###.#.#..#.#.###.#####.#..###....#.##...####..####.. |
||||
#....###.###.#...########.##.##.######.##....#...##.#.#.#..#.##.#.....#..#.....#..........#.##..#... |
||||
.#.#.#.#.##.##.###...#.#.#...##...#.##.##..#..#...##...##..#.##.#.##....#.###....####..#..###.#..### |
||||
...#.#..##.#..##.#.##.####.#.#...###...#.#.###..########.#...###...###..#..#.###..####..##.#..#...#. |
||||
##.#...#######.....#.###..#.#..####.##..##.#..##...#.##..##.#####......######.#.#.##.#..####..#.#### |
||||
#.......#.#########...#...#####...##.###.#..##..##..#...##..##.#.#.###.#.##..#...#....##..#.#.#...#. |
||||
###..###..#...##.#...####.###..##.###..##..##.##.....#.#.#.####.######........#...#####.....#..##### |
||||
##.#.#.########..#.#.##.#####..##.###...#...#.#.##...###.#.###..#..##.#......#.#.#.##.#.#.#....###.# |
||||
#.##.#..#...##..###..##..#..##..##.###...#.##.##.#.#..........##...##.##..##..#....##.#####..##..#.. |
||||
.#...##.##.#..#.##....#..##.##...#...####.###..##...#...#.##...######.#.##.#.#.##.####.##..#.###.### |
||||
##.#.#..#.#.###.#..#.##.#....#....####..#.#..##.#######..##..#...#..####.#####....#.####.#..#.#.###. |
||||
....##.##..#.#####.###.#.###.#.#.#.#..#.###.#..######....##.##.....#.#.#...###..###..#..###....##.## |
||||
#.#######.#..#.#.##.##...#.#..###.##.##..#..###...#.#...#..##.##..##.#.#.##.##.#######.#..#.#..#.#.# |
||||
###.....#####..####..#...#..##.#....##.##...##...##..###...#..##..##..####.#.....##.####..#...##.... |
||||
####..##..##.#...#.###.##...###.#..#...##.##.#...#.##....####.#.#..#...##..##.##..###.......#..#..#. |
||||
#.#.#####..#....#.#...#..##.##..##..#.####..###.####.####.#####.#.#..###.##....#....#.#.###.#.#..##. |
||||
...##...#.#.#####.#.#....##.##..#...##...........#.#....#.##.##.....##..###...#.#####..........##.## |
||||
.#..#..#.#...#.........####....##........##...#...#######.####.###.###...#....###..#.###.##.#.####.# |
||||
..#.#.....#...###.####......###.#..#.#.#.#...####...#####.#..#....#.#.#....#.##.###....#..#....##.## |
||||
##.#...##....###.#......####.#.####.##...#..#.#.#.#...#####.#..#..##.#.#...#.####....###.####.#.#.## |
||||
.#.#..#....#.####.#..#.###..#.#.#.#.#.###...#.##.##.#.##...####..######....####...##.##.#..##.#.#..# |
||||
..##.#...##.####..#.###..##..#.###.#.##..##.###.#.#####..#.##.#.....#.#####.####..#.#.######.#.##.#. |
||||
#.....##..###..###.....###.##.###.#..##.#..##.###....#..#.#.##....#.##.##.#...###.###.#......#..#... |
||||
.##.#..#...#...#.#..##.....#..#.###....###..#.##...#.##.#.##..##......#.#.#.####.#..#..##...##..##.# |
||||
####...##...#......##.##..#######....###.##.#.###.#.#.###...####..#..#.#.##.........#.##.#....#####. |
||||
.####.#####..##..###..#.##.##.####.......#.###.#####.#..#...#..#..####.#.....#.####.#.....###...#### |
||||
#.##......#.#.#.##....#.#.##..#...#.#.#..#...##..#.##.##..#..#####..###.##.#...##...#..#...##.##..#. |
||||
.##.#.#.###..###.##....#...###...####...####..##.###.####.###.#..#.###.#..#.....#.##.#..#.##.#.#.#.# |
||||
...#.###.#..#..#.###.#....##..##.#..###.######.#...##..#.#...###.....#.###.#.#....##...##.###.#.#### |
||||
.#..#..#....###..##..#....##.##..####.#.#.#..#.######....####.##.##....##.#.#.####.#..#.##.##....#.. |
||||
#..##.#...#.###..#.###..###..#.##.#.######.#.#.####....###.##....#.##.#......##.##...##....#.#.###.# |
||||
#...##.#.####...#######..#....##.#...##..#.#....#.#.#####.####.##...#.###.##.#.#.##...##.#....##..## |
||||
....#.##.#.##.##.#.#..###...##.#.#.#....#...#..........###.#####.##...##..#..#.##.#...#..###..#####. |
||||
###..###.##..#.###.#.#.#...##.#.###.##.###...##.###.....####.#...##.#.#.#..#.##...#.....#..#.#.#...# |
||||
####...#.####.#.#.#..#.##.##.##.#.#.####...#...#.#..###....##.##..##.###...##.#...#####.###.#..#.... |
||||
##..##...###..###.#.###.##.####.#..#.#..####.##.#...#..#..#.....##.#.#####...##.....#.#.#..#..##..#. |
||||
.....#......#..##..#...#.#.#.######....###.##.##..#.###...#...#.####.##.##.###.#.######.#..#.#.##... |
||||
#.#.#.###........#..#.#.#.#....##..##..###...##.#.##.#..#######.#..###.###.#.###.###.#.#.#.....##..# |
||||
#.##....####.......#..##.####.#.##..###.##.###.#.#.###...###.....######...######.#.....###.##....... |
||||
#.##..#...#..#..#....#.##...#..#.###...#...#########.#.#...#.....#...#..#.#...#.#.#...#.###.####..## |
||||
.#..##........###.#.#....#.......##.#..#.#.#.##.......#.#.#.#..#.#.....#....#.###.#.##...###.....#.. |
||||
.#.#...##...#....#.##..##.#...#.##..#..##.#..###.#####..##.#.##.####.####.###...##....##......###..# |
||||
#..##....##.###.##.....#.#.....#.#...#..##....##.###.#....###.....######.#.##.###..#..#.#...#.....#. |
||||
....#.####.....#..#..#...#.###.#####..##...#.#..###.#...#...##.###.##..#.######..####.#.#....#.#..## |
||||
##.#..##.#.#.##..##..#...###..##.##..#.###..#...###..##.#.###.####...#..#.#######.##.###.###.#.#..#. |
||||
...##...##.#.#.##.#.##.###..##...##.#..#..##.##.##.##.#.####..##.######....#..#.#.#....###.#.##.#.#. |
||||
.#.....#.###...##.#.##.#..###.##..####.###..#.#.....#..##.#.#..##...##.#..#.##..#########..#.#.##.#. |
||||
####.#..#.#..##...#..#.##..#..#...#.###.....#..##...#..####....#######.....#.##.##..##...#.##..####. |
||||
########...#.#.####..####.#.#.#..##.#.#.##...#...#..#...#..###.#.#..##..#####.#.#.#.##.#.###...#.##. |
||||
.#....#..######.#.#.#..##.#.#...#####....##..##.##.#####....#.##..#..#.#.#.###..#.####.###.........# |
||||
...####..##......###..#..###..#.#.###.#...#..####.#.#..###....#..##.####.#..#.....#.........##..###. |
||||
.####...##...#####.##.##...##...##..##...#.#####...#...##...#.####..####.###.....##.##...##.#######. |
||||
##..####....#.#..#.#....##..#####....#.#...#.####..#######..##.#####.#.#.#.##.#.#..#...#.###.##.#.## |
||||
#.####....#..##########...###.#..#####.#.#.##....#..#....######.....#...#.##.##.#.##..#.###..###..#. |
||||
##.#.##.###..#.###.....##..#.###.#....#####.###...#.#.##.#..#.###.#.#.#####.#.##.##.##.#.#.###.###.. |
||||
.###.#.#.##.######.#.#..##.#..####..#....##......#...##.##.#.......#.#.#.####.#.#.##....##.####..#.# |
||||
####..#...##....#.#.#....#.#####...#..#....##..#..####...#..###...........####.###.###......#..##..# |
||||
..##.####.##....####....#.#.####..#...###.#....#.##.###.#.##..####.#..###..#...#..#####..#...##...#. |
||||
...#..#....#.#..##.#.####....#..####...##.#..#####.###..#.##..###.######...#...#...######.##....##.. |
||||
..#########.#####.#####.###.##.#.###.###..#.#.#.#.###.#...###........####..#####.#.##.##.#..#..#.##. |
||||
#..###.##.###.#...#.#.#.##.###........#.#.#.#..#..##.##.#.....#.#.....##...#..#.##..#..#..#......#.# |
||||
...##..#...##.....##...####.....#.##..###.....#..#.###.#..#.#...#..#.#.....###.###.##.#.#.#..#.#.... |
||||
#...#...#.#.#...#####.####..#....##...##.##.##.#...#.#.#..#...##....#...###.#.##.##....########..#.. |
||||
.#.####....#.#.....########.#....######.#.#######...##..#.###.#.###..###.#..###....#.#.###.....###.# |
||||
..#.##.##....#..#...#..#.#.#...###...#..#.#.#.####.#.#####.####....##..#..###.#.#..####....##.####.. |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# |
||||
|
||||
#..#. |
||||
#.... |
||||
##..# |
||||
..#.. |
||||
..### |
Loading…
Reference in new issue