def feasible_association_events(measurements, targets, gating=True):
    '''
	Finds all feasible association event, that is
	the combinations of all targets and measurements.
	value "0" indicates invalid detection.
	One target can only be associated to a single measurement. 
	'''
    meas_linspace = np.arange(len(measurements) + 1)
    padding = np.zeros(max(len(measurements), len(targets)), dtype=np.int16)
    meas_linspace = np.append(meas_linspace, padding)
    perm_obj = multiset_permutations(meas_linspace, size=len(targets))
    permutations = []
    for p in perm_obj:
        check = True
        if gating:
            for t, m in enumerate(p):
                if m != 0 and dist(measurements[m - 1],
                                   targets[t]) > targets[t].gate_size**2:
                    check = False
                    break
        if check:
            permutations.append(p)

    # No viable measurements if all measurements outside of gates
    if len(permutations) == 0:
        print("No viable measurements")
        measurements.clear()

    return np.array(permutations)
Example #2
0
    def permute(self, nums):
        if nums is None:
            return []
        if nums == []:
            return [[]]
        nums = sorted(nums)
        permutation = []
        stack = [-1]
        permutations = []
        while len(stack):
            index = stack.pop()
            index += 1
            while index < len(nums):
                if nums[index] not in permutation:
                    break
                index += 1
            else:
                if len(permutation):
                    permutation.pop()
                continue

            stack.append(index)
            stack.append(-1)
            permutation.append(nums[index])
            if len(permutation) == len(nums):
                permutations.append(list(permutation))
        return permutations
def phelper(array, currentval, permutations):
	if not len(array) and len(currentval): # iterate till the list is empty, append final value
		permutations.append(currentval)
	else:
		for i in range(len(array)):
			newarray = array[:i] + array[i + 1 :]
			newpermutation = currentval + [array[i]]
			phelper(newarray, newpermutation, permutations)
Example #4
0
        def helper(permutation):
            if len(permutation) == permutationLength:
                permutations.append(permutation)
                return

            for i in range(len(nums)):
                temp = nums.popleft()
                helper(permutation + [temp])
                nums.append(temp)
Example #5
0
def same_necklace_long(str1, str2):
    if str1 == "" and str2 == "": print(True)
    else:
        permutations = list()
        for i in range(len(str1)):
            perm = rotate_right(str1, i)
            if perm not in permutations:
                permutations.append(perm)
        print(str1 in permutations and str2 in permutations)
def kth_perm_v1(n, k):
    TOTAL_NUM_PERMS = [1, 2, 6, 24, 120, 720, 5040, 40320, 362880][:n]
    digits = [1, 2, 3, 4, 5, 6, 7, 8, 9][:n]
    permutations = []
    while digits:
        n -= 1
        digit = digits[(k - 1) // TOTAL_NUM_PERMS[n - 1]]
        digits.remove(digit)
        permutations.append(str(digit))
        k = k % TOTAL_NUM_PERMS[n - 1]
    return ''.join(permutations)
Example #7
0
 def perm(data, n):
     if n == 1:
         a = copy.deepcopy(data)
         permutations.append(a)
     else:
         for i in range(0, n - 1):
             perm(data, n - 1)
             if n % 2 == 0:
                 swap(data, i, n - 1)
             else:
                 swap(data, 0, n - 1)
         perm(data, n - 1)
Example #8
0
def external_use(sentences, order):
	if order == 'minLA':
		method = 'sum'
	else:
		method = 'max'
	permutations = []
	for sentence in tqdm(sentences):
		s = nlp(sentence)
		t2i, i2t = make_dictionaries(s)
		graph = make_graph(s, t2i)
		i2p, perm = find_permutation(graph, method, verbose=False) 
		permutations.append(perm)
	return permutations
Example #9
0
def solve():
    txt = [x for x in input().strip()]
    rev = False
    p = dq()

    for x in txt:
        if x == "R":
            rev = not rev
        elif rev:
            if len(p) > 0 and p[0] == x:
                p.popleft()
            else:
                p.appendleft(x)
        else:
            if len(p) > 0 and p[-1] == x:
                p.pop()
            else:
                p.append(x)
    if rev:
        p.reverse()
        print("".join(p))
    else:
        print("".join(p))
def solve():
    n=ii()
    arr=li()
    p=[]
    for a,b in enumerate(arr):
        p.append((b,a))
    p.sort(reverse=True)
    #print(p)
    ans=[]
    s=sum(arr)
    for x in range(n):
        if x==n-1:
            if s==p[x][0]:
                ans.append(p[x][1]+1)
        else:
            s-=p[x][0]
            if s<p[x][0]:
                ans.append(p[x][1]+1)
                break
            else:
                ans.append(p[x][1]+1)
    ans.sort()                                                      
    print(len(ans))
    print(*ans)
Example #11
0
def solve():
    n, k = mi()
    arr = li()
    p = [0]
    c = 0
    for x in range(1, n - 1):
        if arr[x] > arr[x - 1] and arr[x] > arr[x + 1]:
            c += 1
        p.append(c)
    p.append(c)
    #print(p)
    s, f = 0, k - 2
    ans = 0
    tot = 0
    while f < n:
        #print(p[f]-p[s])
        if p[f] - p[s] > tot:
            tot = p[f] - p[s]
            ans = s + 1
        s += 1
        f += 1
    if c == 0:
        ans = 1
    print(tot + 1, ans)
Example #12
0
def S(maxNum, split_temp=[]):
    permutations = []
    f = open("D:\\ResearchFall19\\n13.bin", "rb")
    #x = f.readline()
    #x = x.split(" ")
    if maxNum < 13:
        x = list(f.read(13))
        while x[maxNum] == maxNum + 1:
            perm = x[:maxNum]
            if valid_perm(perm, split_temp):
                permutations.append(perm)
            x = list(f.read(13))
        #print(permutations)
        return permutations
    if maxNum == 13:
        counter = 0
        perm = list(f.read(13))
        while perm:
            counter += 1
            if counter % 10000 == 0:
                print(counter)
            if valid_perm(perm, split_temp):
                permutations.append(perm)
            perm = list(f.read(13))
        return permutations
    if maxNum > 13:
        perm = list(f.read(13))
        while perm:
            new_perm = []
            for i in range(14, maxNum + 1):
                new_perm.append([
                    perm[j:] + [i] + mylist[:j]
                    for j in xrange(len(perm), -1, -1)
                ])
                permutations = new_perm
                new_perm = []
            for perm in permutations:
                if valid_perm(perm, split_temp):
                    permutations.append(perm)
            perm = list(f.read(13))
        return permutations
Example #13
0
from itertools import permutations

x = list(permutations('0123456789'))
permutations = []

for perm in x:
    string = ''
    for i in perm:
        string += i
    permutations.append(string)

permutations.sort()
permutations[(1000000 - 1)]
Example #14
0
# print(perms[:10])

# find the 'arms' that are of equal magnitude and create valid_perms
valid_perms = []
for p in perms:
    tot_arm_1 = int(p[0]) + int(p[1]) + int(p[2])
    tot_arm_2 = int(p[3]) + int(p[2]) + int(p[4])
    tot_arm_3 = int(p[5]) + int(p[4]) + int(p[1])
    if tot_arm_1 == tot_arm_2 == tot_arm_3:
        temp = [p[0] + p[1] + p[2], p[3] + p[2] + p[4], p[5] + p[4] + p[1]]
        temp.sort()
        valid_perms.append(temp)

# need to remove duplicates (from internet)
permutations = []
[permutations.append(x) for x in valid_perms if x not in permutations]
# print(permutations)

# we can sort the permutations as each starting arm is unique.
# N.B. as question says we want the highest starting permutation, so we simply sort and take highest
permutations.sort()
highest = permutations[-1]
print(highest)

# In 'highest', we need to check if the elements are in correct sequence. (First one is fine.)
if highest[0][2] != highest[1][1]:
    temp = [highest[0], highest[2], highest[1]]
    highest = temp
print("Highest sequence is {}".format(highest))

Example #15
0
    def permutations(self):
        if self.permutation == 1:
            permutations = []
            x_y = self.points
            x_negative = []
            y_negative = []
            x_y_negative = []
            x_y_inverse = []
            x_negative_inverse = []
            y_negative_inverse = []
            x_y_negative_inverse = []

            shape_1 = self

            for point in self.points:
                #x_negative
                new_x = (point.x * -1) + (self.width - 1)
                new_y = point.y
                new_point = Point(new_x, new_y)
                x_negative.append(new_point)
                shape_2 = Shape(self.width, self.height, sorter(x_negative),
                                self.area, self.number, 2)
                #y_negative
                new_x = point.x
                new_y = (point.y * -1) + (self.height - 1)
                new_point = Point(new_x, new_y)
                y_negative.append(new_point)
                shape_3 = Shape(self.width, self.height, sorter(y_negative),
                                self.area, self.number, 3)
                #x_y_negative
                new_x = (point.x * -1) + (self.width - 1)
                new_y = (point.y * -1) + (self.height - 1)
                new_point = Point(new_x, new_y)
                x_y_negative.append(new_point)
                shape_4 = Shape(self.width, self.height, sorter(x_y_negative),
                                self.area, self.number, 4)
                #x_y_inverse
            for point in shape_1.points:
                new_x = point.y
                new_y = point.x
                new_point = Point(new_x, new_y)
                x_y_inverse.append(new_point)
                shape_5 = Shape(self.height, self.width, sorter(x_y_inverse),
                                self.area, self.number, 5)
                #x_negative_inverse
            for point in shape_2.points:
                new_x = point.y
                new_y = point.x
                new_point = Point(new_x, new_y)
                x_negative_inverse.append(new_point)
                shape_6 = Shape(self.height, self.width,
                                sorter(x_negative_inverse), self.area,
                                self.number, 6)
                #y_negative_inverse
            for point in shape_3.points:
                new_x = point.y
                new_y = point.x
                new_point = Point(new_x, new_y)
                y_negative_inverse.append(new_point)
                shape_7 = Shape(self.height, self.width,
                                sorter(y_negative_inverse), self.area,
                                self.number, 7)
                #x_y_negative_inverse
            for point in shape_4.points:
                new_x = point.y
                new_y = point.x
                new_point = Point(new_x, new_y)
                x_y_negative_inverse.append(new_point)
                shape_8 = Shape(self.height, self.width,
                                sorter(x_y_negative_inverse), self.area,
                                self.number, 8)

            permutations.append(shape_1)
            permutations.append(shape_2)
            permutations.append(shape_3)
            permutations.append(shape_4)
            permutations.append(shape_5)
            permutations.append(shape_6)
            permutations.append(shape_7)
            permutations.append(shape_8)
            return trimmer(permutations)
        else:
            return None