예제 #1
0
def calc(word):
	array = arrayify(word)
	hashes = []
	count = 0
	for i in array:
		hashes.append(hexToBin(Day10.calc2Main(list(range(0, 256)), i)))
	for i in hashes:
		count += i.count('1')
	return count
예제 #2
0
	def test3(self):
		t = 'flqrgnkx-0'
		t = Day10.calc2Main(list(range(0, 256)), t)
		self.assertTrue(t.startswith('d4f76'))
		t = hexToBin(t)
		self.assertEqual(t[:8], '11010100')
		t = 'flqrgnkx-1'
		t = Day10.calc2Main(list(range(0, 256)), t)
		self.assertTrue(t.startswith('55eab3'))
		t = hexToBin(t)
		self.assertEqual(t[:8], '01010101')
		t = 'flqrgnkx-2'
		t = Day10.calc2Main(list(range(0, 256)), t)
		t = hexToBin(t)
		self.assertEqual(t[:8], '00001010')
		t = 'flqrgnkx-127'
		t = Day10.calc2Main(list(range(0, 256)), t)
		self.assertTrue(t.startswith('3ecaf0'))
		t = hexToBin(t)
		self.assertEqual(t[:8], '00111110')
def main():
    Day0.run()
    Day1.run()
    Day2.run()
    Day3.run()
    Day4.run()
    Day5.run()
    Day6.run()
    Day7.run()
    Day8.run()
    Day9.run()
    Day10.run()
    Day11.run()
    Day12.run()
    Day13.run()
    Day14.run()
    Day15.run()
    Day16.run()
    Day17.run()
    Day18.run()
    Day19.run()
예제 #4
0
def calc2(word):
	array = arrayify(word)
	hashes = []
	for i in array:
		hashes.append(hexToBin(Day10.calc2Main(list(range(0, 256)), i)))
	count = 0
	sets = []
	for i in range(len(hashes)):
		for j in range(len(hashes[i])):
			setOfGroup = group(j, i, hashes, set())
			if setOfGroup:
				count += 1
				sets.append(setOfGroup)
				hashes = purgeGroup(setOfGroup, hashes)
	return count
예제 #5
0
파일: Day14.py 프로젝트: crashb/AoC-2017
	for row in range(0, 128):
		for col in range(0, 128):
			if hashBits[row][col] != 0 and (row, col) not in visited:
				# mark bit as visited and traverse region
				regions += 1
				visited.append((row, col))
				getRegion(hashBits, row, col, visited)
	return regions
	
if __name__ == "__main__":
	# part 1 - get number of 'on' bits in an array of 128 knot hashes
	# rank: 105
	input = "stpzcrnm"
	hashes = []
	print("Finding number of on bits...")
	for i in range(0, 128):
		rowName = input + "-" + str(i)
		inputBytes = bytearray(rowName, "ascii")
		hashes.append(Day10.getKnotHash(inputBytes))
	onBits = 0
	for i in range(0, 128):
		for byte in hashes[i]:
			onBits += popcount(byte)
	print("On bits: " + str(onBits))
	
	# part 2: get number of regions of 'on' bits in the array
	# rank: 304
	print("Finding number of regions...")
	hashBits = getBitArray(hashes)
	numRegions = getNumRegions(hashBits)
	print("Regions: " + str(numRegions))
예제 #6
0
 def test_puzzledata(self):
     self.assertEqual(Day10.solve("puzzledata.txt"), 10136)
예제 #7
0
 def test_testdata1(self):
     self.assertEqual(Day10.solve("testdata1.txt"), 3)
예제 #8
0
 def test_case_11(self):
     self.assertEqual("21", Day10.lookandsay("11", reps=1))
예제 #9
0
 def test_case_1_5x(self):
     self.assertEqual("312211", Day10.lookandsay("1", reps=5))
예제 #10
0
	def test1(self):
		t = Day10.calc2Main(list(range(0, 256)), Day10.loadString('Day10.txt'))
		self.assertEqual(t, '7adfd64c2a03a4968cf708d1b7fd418d')