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
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 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
def test1(self): t = Day10.calc2Main(list(range(0, 256)), Day10.loadString('Day10.txt')) self.assertEqual(t, '7adfd64c2a03a4968cf708d1b7fd418d')