Exemple #1
0
            for p in distance_ordered:
                if p_last:
                    if p_last and p_last.pos[X] == p.pos[X] and p_last.pos[Y] == p.pos[Y] and p_last.pos[Z] == p.pos[Z]:  # collision
                        collided += 1
                        to_remove.append(p_last)
                        to_remove.append(p)
                p_last = p

            # remove culled
            [plist.remove(p) for p in to_remove if p in plist]
            if collided:
                print(f"{collided} collided - {len(plist)} remaining")
            i += 1
            self.diverging_bound -= 1

            if self.diverging_bound < 1:
                # failed
                print(f"Failed, diverging bound went to zero after {i} iterations")

        # part I
        # if len(plist) > 1:
            # print(f"Failed, {len(self.plist)} > 1")
        return len(plist)
        # return self.plist[0].id_

    def run_part2(self):
        return 0

if __name__ == '__main__':
    main(DayN)
Exemple #2
0
        if not key_ascii:
            key_ascii = list(
                map(ord,
                    "83,0,193,1,254,237,187,40,88,27,2,255,149,29,42,100"))
            self.lengths = key_ascii[:]
        orig = self.lengths[:] + [17, 31, 73, 47, 23]
        for r in range(0, 64):
            self.lengths = orig[:]
            while self.lengths:
                self.one_loop()

        c = self.get_c()

        # xor combine 16 item blocks
        dense_hash = []
        for i in range(0, 16):
            block = c[i * 16:i * 16 + 16]
            reduced = reduce(lambda x, y: x ^ y, block)
            dense_hash.append(reduced)

        h = ""
        for d in dense_hash:
            h_ = "{:02x}".format(d)
            h += h_

        return h


if __name__ == '__main__':
    main(DayN, size=256)
Exemple #3
0
    def swap_ele(self, a, b):
        a = self.index(a)
        b = self.index(b)
        self.l_[b], self.l_[a] = self.l_[a], self.l_[b]

    def __repr__(self):
        r = ""
        for i in self.l_:
            r += chr(i + ord('a'))
        return r

    def run_part1(self):
        for inst in self.insts:
            self.do_inst(inst)
        return str(self)

    def run_part2(self):
        sl = []
        for n in range(0, self.moves):
            s = self.run_part1()
            sl.append(s)

            if s in self.seen:
                return sl[self.moves % (n - 1)]
            else:
                self.seen[s] = 1


if __name__ == '__main__':
    main(DayN, moves=1000000000)