Example #1
0
    def solution(self, inputList):
        inputNumbers = common.pullNumbersFromList(inputList, True)

        count = 1
        lastDiff = 0
        while (True):
            aboveThreshold = self.progressOneSecond(inputNumbers)

            if aboveThreshold:
                minX = min(x[0] for x in inputNumbers)
                minY = min(x[1] for x in inputNumbers)
                maxX = max(x[0] for x in inputNumbers)
                maxY = max(x[1] for x in inputNumbers)
                diff = maxX - minX

                if diff < 100:
                    if lastDiff < diff:
                        self.progressOneSecond(inputNumbers, True)
                        self.drawStars(inputNumbers, minX, maxX, minY, maxY)
                        print('Count %d' % count)
                        break

                lastDiff = diff

            count += 1
Example #2
0
    def solution(self, inputList):
        nums = common.pullNumbersFromList(inputList, True)
        unassigned = deque(nums)

        consts = defaultdict(list)
        count = 0
        #first pass
        while len(unassigned):
            i = unassigned.popleft()
            if len(consts) == 0:
                consts[0].append(i)
                count += 1
                continue

            found = -1
            keys = list(consts.keys())
            for k in keys:
                v = consts[k]
                for coord in v:
                    if self.calcManhatten(i, coord) <= 3:
                        if found < 0:
                            consts[k].append(i)
                            found = k
                        else:
                            consts[found].extend(consts[k])
                            del (consts[k])
                        break

            if found < 0:
                consts[count].append(i)
                count += 1

        print('Solution Here %s' % len(consts))
        return len(consts)
Example #3
0
    def solution(self, inputList):
        inputNumbers = common.pullNumbersFromList(inputList, True)
        mr = max(inputNumbers, key=operator.itemgetter(3))

        results = list(
            filter(
                lambda x: abs(x[0] - mr[0]) + abs(x[1] - mr[1]) + abs(x[
                    2] - mr[2]) <= mr[3], inputNumbers))
        #test = list(filter(lambda x: x[0] >= 0, inputNumbers))

        print('Solution Here')
        return len(results)
Example #4
0
    def solution(self, inputList):
        inputNumbers = deque(common.pullNumbersFromList(
            inputList, True,
            False))  #True = include signs, False: all numbers are positive
        print(inputNumbers)

        tree = {'meta': list(), 'children': list()}

        total = self.processNode(tree, inputNumbers)

        print('Solution Here %d' % total)
        return total
Example #5
0
	def solution(self, inputList):
		nums = common.pullNumbersFromList(inputList, True)
		unassigned = deque(nums)
		
		
		consts = defaultdict(list)
		
		#first pass
		while len(unassigned):
			i = unassigned.popleft()
			if len(consts) == 0:
				consts[0].append(i)
				continue

			found = False			
			for k,v in consts.items():
				for coord in v:
					if self.calcManhatten(i, coord) <= 3:
						consts[k].append(i)
						found = True
						break
				if found == True:
					break
			
			if not found:
				consts[len(consts)].append(i)
		
		
		#merge lists if possible
		for k in range(0, len(consts)):
			v = consts[k]
			groups = list(consts.values())
			groups.remove(v)
			match = False
			for coord1 in v:
				for list2 in groups:
					for coord2 in list2:
						if self.calcManhatten(coord1, coord2) <= 3:
							list2.extend(v)
							del(consts[k])
							match = True
							break
					if match:
						break
				if match:
					break
		
		print('Solution Here %s' % len(consts))
		return len(consts)
Example #6
0
    def solution(self, inputList):
        inputNumbers = common.pullNumbersFromList(inputList, True)
        #mr = max(inputNumbers, key=operator.itemgetter(3))
        matches = defaultdict(int)
        for i in range(0, len(inputNumbers)):
            item = inputNumbers[i]
            for y in inputNumbers:
                if abs(item[0] - y[0]) + abs(item[1] - y[1]) + abs(
                        item[2] - y[2]) <= item[3]:
                    matches[i] += 1

        bestCount = 0
        bestDist = 0
        for k, v in matches.items():
            if v > bestCount:
                item = inputNumbers[k]
                bestCount = v
                bestDist = abs(item[0]) + abs(item[1]) + abs(item[2])

        #results = list(filter(lambda x: abs(x[0]-mr[0]) + abs(x[1]-mr[1]) + abs(x[2]-mr[2]) <= mr[3], inputNumbers))
        #test = list(filter(lambda x: x[0] >= 0, inputNumbers))

        print('Solution Here')
        return len(bestDist)
Example #7
0
import sys
sys.path.append('../')
from scaffolding import common

inputList = common.loadInput('input.txt', True)  #True = split, False = string
inputNumbers = common.pullNumbersFromList(
    inputList, True)  #True = include signs, False: all numbers are positive

print("Advent 6b.")

gridSize = max(
    max(inputNumbers,
        key=lambda x: max(x))) + 1  #one bigger as the gridcount starts at 0
maxDistance = 10000
regionSize = 0

for n in range(gridSize):
    for m in range(gridSize):
        count = 0

        for point in inputNumbers:
            count = count + abs(n - point[0]) + abs(m - point[1])

            if count >= maxDistance:
                continue

        if count < maxDistance:
            regionSize = regionSize + 1

#print(max(sizes.iteritems(), key=operator.itemgetter(1))[0])