Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- SIDE = 1000
- FORMAT: (ID @ LEFT,RIGHT: XxY)
- Part 1
- How many square inches of fabric are within two or more claims?
- Solution:
- Create 1000 arrays with 1000 indices
- Loop through each entry of the input.txt to record the positions.
- For each use, add 1 to the array indice.
- e.g. 5,5 5,5 the spaces filled would be 6=left+1 to 11=left +5, 6=top+1 to 11=top+5
- in the actual array: the first would be array[6][6] to array[11][11]
- @ space1 number comma number colon space2 number x number
- '''
- def values():
- checker = 0
- at = 0
- comma = 0
- colon = 0
- x = 0
- values = [] #array of [left, top, x, y]
- for id, line in enumerate(open('input.txt')):
- #1353 @ 743,209: 14x21
- for indice, char in enumerate(line):
- if char == '@': at = indice
- if char == ',': comma = indice
- if char == ':': colon = indice
- if char == 'x':
- x = indice
- values.append([int(line[at+2:comma]), int(line[comma+1:colon]), int(line[colon+2:x]), int(line[x+1:-1])])
- if id == checker:
- #print(values)
- checker += 1 #so array can check for values
- return values
- def createArray():
- subarray = []
- for i in range(1000): subarray.append(0)
- array = []
- for i in range(1000): array.append(subarray)
- return array
- def markArrays():
- array = createArray()
- value = values()
- for c, coords in enumerate(value):
- for i in range(coords[1], coords[1] + coords[3] + 1):
- #problem starts from 1,1 so range gets aoc values, then i and j are adjusted below
- for j in range(coords[0], coords[0] + coords[2] + 1):
- if array[i - 1][j - 1] == 1:
- array[i - 1][j - 1] = 'X'
- else:
- array[i - 1][j - 1] = 1
- print(c, i, j, array[i - 1][j - 1])
- #xarr = array[i - 1], xind = xarr[j - 1], to enter arry, go to y array (which has to be 1 less than i bc adjusting coords->array), then x indice
- return array
- def counter(array):
- counter = 0
- for set in array:
- for value in set:
- if type(value) == str:
- counter += 1
- return counter
- print(markArrays())
- print(counter(markArrays()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement