Beispiel #1
0
 def set_sequences(self, a1, a2, a3, a4, a5, a6, a7, a8, c1, c2, c3, c4, v1,
                   v2, v3, v4):
     # create circular lists for each set with corresponding edges
     self.all_edges_in_order = CircularList(
         (a1, a2, a3, a4, a5, a6, a7, a8))
     self.ceiling_edges_clockwise = CircularList((c1, c2, c3, c4))
     self.vertical_edges_up = CircularList((v1, v2, v3, v4))
def get_basic_section(start, classified_pixels, start_back=None):
    # 'gradient' vector
    delta = np.array([0, 0])

    last_gradients = CircularList()

    section = []
    section.append(start)

    x, y = start
    next, next_value = get_max_neighbor(classified_pixels, x, y, start_back)
    delta = np.subtract(next, start)

    while next_value == 2:  # edge pixel
        last_gradients.insert((delta[0], delta[1]))
        section.append(next)

        next = np.add(next, delta)
        next_value = classified_pixels[next[0], next[1]]

        if next_value < 2:  # blank pixel or miscellaneous pixel
            last = section[-1]  # get last element added in section
            x, y = last
            back = np.subtract(last, delta)

            # get max value in the neighborhood, unless the 'back'
            next, next_value = get_max_neighbor(classified_pixels, x, y, back)

            delta = np.subtract(next, last)

    last_gradients.insert((delta[0], delta[1]))
    section.append(next)
    last_element = next

    return section, last_gradients, last_element
Beispiel #3
0
def get_knot_hash(lengths):
    lengths.extend(LENGTHS_SUFFIX)
    skip_size = 0
    current_position = 0

    total_score = 0
    total_in_garbage = 0

    real_list = [x for x in range(256)]
    cl = CircularList(real_list)


    for length in lengths * NUM_ROUNDS:
        cl.reverse_portion(current_position, length)
        current_position += length
        current_position += skip_size
        skip_size += 1

    sparse_hashes = []

    for x in range(16):
        offset = 16 * x
        sh = 0
        for i in range(16):
            sh ^= cl[offset + i]

        sparse_hashes.append(sh)

    return "".join([format(sh, '02x') for sh in sparse_hashes])
Beispiel #4
0
 def __init__(self, cache_size=None):
     self.required_updates = []
     # they are held here until it is synced with exchange candles timeframe
     self.pending_updates = []
     self.partial_candles = []
     self.cache_size = CandleBuilder.DEFAULT_CACHE_SIZE if cache_size is None else cache_size
     self.candles_list = CircularList(self.cache_size)
Beispiel #5
0
    def christmas_animation(self, duration=3600):

        startTime = datetime.now()

        ceiling_led_list = CircularList()

        for edge in self.ceiling_edges_clockwise:
            for led_number in edge.leds:
                ceiling_led_list.append(led_number)

        # print(ceiling_led_list._data)

        last_ceiling_stamp = datetime.now()
        last_vertical_stamp = datetime.now()
        update_necessary = False

        while (datetime.now() - startTime).total_seconds() <= duration:

            if (datetime.now() - last_ceiling_stamp).total_seconds() >= 1:
                for i in ceiling_led_list:
                    color = (0, 0, 0)
                    color_pick = randint(1, 10)
                    if color_pick == 0:
                        color = (0, 0, 255)
                    elif 1 <= color_pick <= 6:
                        color = (255, 0, 0)
                    elif 7 <= color_pick <= 10:
                        color = (0, 255, 0)
                    self.set_led(i, color)

                ceiling_led_list.shiftForward()
                last_ceiling_stamp = datetime.now()
                update_necessary = True

            if (datetime.now() - last_vertical_stamp).total_seconds() >= 0.05:
                for edge in self.vertical_edges_up:
                    for i in range(edge.length):
                        offset = 2 * i
                        self.set_led(
                            edge.leds[i],
                            (255, max(0, min(255,
                                             offset + randint(-15, 15))), 0))
                last_vertical_stamp = datetime.now()
                update_necessary = True

            if update_necessary:
                update_necessary = False
                self.update()

            time.sleep(0.1)
Beispiel #6
0
    def build_list_horizontal_circle(self, include_vertical=True):
        list_of_leds = CircularList()

        if include_vertical:
            # iterate through all edges in order and add LED numbers of ceiling strips to list, add list of LEDs in
            # vertical edges as list so they function as a single LED
            for edge in self.all_edges_in_order:
                if edge in self.ceiling_edges_clockwise:
                    for led in edge.leds:
                        list_of_leds.append([led])
                else:
                    list_of_leds.append(edge.leds)
        else:
            # iterate through edges and add the led numbers to the circular list
            for edge in self.ceiling_edges_clockwise:
                for led in edge.leds:
                    list_of_leds.append([led])

        return list_of_leds
Beispiel #7
0
    def build_list_vertical_straight(self, include_horizontal=True):
        list_of_leds = CircularList()

        for i in range(0, self.vertical_edges_up[0].length):
            list_of_leds.append([
                self.vertical_edges_up[0].leds[i],
                self.vertical_edges_up[1].leds[i],
                self.vertical_edges_up[2].leds[i],
                self.vertical_edges_up[3].leds[i]
            ])

        if include_horizontal:
            all_horizontal = []
            for edge in self.ceiling_edges_clockwise:
                for n in edge.leds:
                    all_horizontal.append(n)

            list_of_leds.append(all_horizontal)

        return list_of_leds
def get_crossing_section_direction(classified_pixels, crossing_pixel,
                                   last_gradients, section):
    # counter gradients frequency
    cnt_gradient = Counter(last_gradients.get_list())
    # count in list
    grads = cnt_gradient.most_common()

    crossing_section_direction = []

    next = crossing_pixel
    next_value = classified_pixels[next[0], next[1]]

    # back is a edge pixel
    back = section[-2][0], section[-2][1]

    # avoid local minima
    iterations = 0
    loop_grads = CircularList(3)
    excluded_grad = None

    while next_value != 2:  # edge pixel
        aux_value = 0
        i = 0

        if iterations == 3:
            list_loop_grads = loop_grads.get_list()
            excluded_grad = list_loop_grads[1]
            crossing_section_direction[:] = []
            iterations = 0

        # blank pixel or miscellaneous and i < len
        while aux_value < 2 and i < len(grads):
            if grads[i][0] == excluded_grad:
                continue

            delta = grads[i][0]
            aux = np.add(next, delta)

            if aux[0] == back[0] and aux[1] == back[
                    1]:  # back[0] >= 0 and back[1] >= 0 and
                aux_value = 0
            else:
                aux_value = classified_pixels[aux[0], aux[1]]

            i += 1

        if aux_value < 2 and i == len(grads):
            delta = get_direction(classified_pixels, back, next, grads,
                                 excluded_grad)

            loop_grads.insert(delta)
            back = next[0], next[1]
            next = np.add(next, delta)
            next_value = classified_pixels[next[0], next[1]]
        else:
            loop_grads.insert(delta)
            back = next[0], next[1]
            next = aux
            next_value = aux_value

        crossing_section_direction.append(next)
        iterations += 1

    return crossing_section_direction
Beispiel #9
0
from circular_list import CircularList
NUM_ROUNDS = 64

LENGTHS_SUFFIX = [17, 31, 73, 47, 23]

skip_size = 0
current_position = 0

total_score = 0
total_in_garbage = 0

real_list = [x for x in range(256)]
cl = CircularList(real_list)

with open("input.txt", "rb") as input_file:
    line = input_file.read()[:-1]
    lengths = [c for c in line]
    lengths.extend(LENGTHS_SUFFIX)

for length in lengths * NUM_ROUNDS:
    cl.reverse_portion(current_position, length)
    current_position += length
    current_position += skip_size
    skip_size += 1

sparse_hashes = []

for x in range(16):
    offset = 16 * x
    sh = 0
    for i in range(16):
Beispiel #10
0
 def reset(self):
     '''Resets position and skip to 0'''
     self.circular_list = CircularList([i for i in range(256)])
     self.pos = 0
     self.skip = 0
Beispiel #11
0
 def __init__(self):
     self.circular_list = CircularList([i for i in range(256)])
     self.pos = 0
     self.skip = 0