#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np
import math


# In[2]:



fileObj = open('../data/advent_of_code_input_day_three.txt', "r") #opens the file in read mode.
items = fileObj. read(). splitlines() #puts the file into an array.


# In[3]:


#print (items)

def split(line): 
    return list(line)

holding = []
for i, line in enumerate(items):
    result = split(line)
    holding.append(result)

holding = np.array(holding)
holding[holding == '.'] = 0
holding[holding == '#'] = 1

holding = holding.astype(int)
print (holding)


# In[7]:



def dup_and_count(rightstep, downstep, basedata):
    needed_slope_elements = math.floor(basedata.shape[0]/downstep)
    replications_needed = (needed_slope_elements* rightstep)/basedata.shape[1]
    duplicated = np.tile(basedata, math.ceil(replications_needed))
    right = np.arange(0,(needed_slope_elements)*rightstep, rightstep).astype(int)
    down = np.arange(0,(needed_slope_elements)*downstep,downstep).astype(int)
    
    moves = []

    for ii in range(len(right)):
        moves.append(duplicated[down[ii], right[ii]])
    
    hits = np.sum(moves)
    return hits

down1_right3 = dup_and_count(3,1,holding)
down1_right1 = dup_and_count(1,1,holding)
down1_right5 = dup_and_count(5,1,holding)
down1_right7 = dup_and_count(7,1,holding)
down2_right1 = dup_and_count(1,2,holding)

results = np.array([down1_right3, down1_right1, down1_right5, down1_right7, down2_right1], dtype=np.int64)
print(results) 
product = np.prod(results)
print (product)


# In[ ]:





[((32, 10, 32, 27), 'numpy.array', 'np.array', ({(32, 19, 32, 26): 'holding'}, {}), '(holding)', True, 'import numpy as np\n'), ((65, 10, 65, 106), 'numpy.array', 'np.array', (), '', True, 'import numpy as np\n'), ((67, 10, 67, 26), 'numpy.prod', 'np.prod', ({(67, 18, 67, 25): 'results'}, {}), '(results)', True, 'import numpy as np\n'), ((45, 28, 45, 66), 'math.floor', 'math.floor', ({(45, 39, 45, 65): 'basedata.shape[0] / downstep'}, {}), '(basedata.shape[0] / downstep)', False, 'import math\n'), ((56, 11, 56, 24), 'numpy.sum', 'np.sum', ({(56, 18, 56, 23): 'moves'}, {}), '(moves)', True, 'import numpy as np\n'), ((47, 35, 47, 65), 'math.ceil', 'math.ceil', ({(47, 45, 47, 64): 'replications_needed'}, {}), '(replications_needed)', False, 'import math\n'), ((48, 12, 48, 69), 'numpy.arange', 'np.arange', ({(48, 22, 48, 23): '0', (48, 24, 48, 57): 'needed_slope_elements * rightstep', (48, 59, 48, 68): 'rightstep'}, {}), '(0, needed_slope_elements * rightstep, rightstep)', True, 'import numpy as np\n'), ((49, 11, 49, 65), 'numpy.arange', 'np.arange', ({(49, 21, 49, 22): '0', (49, 23, 49, 55): 'needed_slope_elements * downstep', (49, 56, 49, 64): 'downstep'}, {}), '(0, needed_slope_elements * downstep, downstep)', True, 'import numpy as np\n')]