Ejemplo n.º 1
0
 def get_next(self):
     if self.__len__() > 0:
         x = get_it(0, self.n_elements -2)
         y = get_it(x+1, self.n_elements -1)
         while (x,y) in self.set_of_provided:
             x = get_it(0, self.n_elements - 2)
             y = get_it(x+1, self.n_elements -1)
         element = x, y
         self.set_of_provided.add(element)
         # print self.set_of_provided
         return element
     else:
         return None
Ejemplo n.º 2
0
def shuffle_array(array):
    result = []
    shuffled_indices = []
    indices = range(0, len(array))
    while len(indices) > 0:
        permuted_index = get_it(0, len(indices) - 1)
        shuffled_indices.append(indices[permuted_index])
        del indices[permuted_index]

    for index in shuffled_indices:
        result.append(array[index])

    return result
Ejemplo n.º 3
0
    def get_next_spiraled(self):
        from_element = self.start_element_index
        y_f, x_f = self.union_to_work_with.array.index_map(self.beginning)

        search = True
        to_element = None
        while self.radius < self.union_to_work_with.array.size():
            if not search:
                break
            candidates_for_radius = []
            growing_radius = []
            for i in range(1, self.radius+1):
                for x_dif in range(-i, i+1):
                    for y_dif in range(-i, i+1):
                        to_element = None
                        y_s_candidate =  y_f + y_dif
                        x_s_candidate =  x_f + x_dif
                        if (y_dif**2 + x_dif**2) > self.radius**2:
                            continue
                        try:
                            to_element = self.union_to_work_with.array.get_index_by_coords(x_s_candidate, y_s_candidate)
                        except:
                            to_element = None
                            continue
                        candidates_for_radius.append(to_element)
            next_candidate = None
            while len(candidates_for_radius) > 0:
                rand_index = get_it(0, len(candidates_for_radius) - 1)
                next_candidate =  candidates_for_radius[rand_index]
                if self.union_to_work_with.connected(from_element, next_candidate):
                    next_candidate =  None
                    del candidates_for_radius[rand_index]
                else:
                    break

            if next_candidate != None:
                search = False
                to_element = next_candidate
            else:
                self.radius+=1

        if to_element != None:
            result = from_element, to_element
            self.start_element_index = to_element
        else:
            result =  0, 1
        return result