Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
0 answers
40 views

Aproximation Algorithim for Max Subset Problem

I'm looking for an approximation approach to what I am assuming is an NP hard problem. Given a list of sets F = {S1,...,Sm) that contain at most n elements from (0,...,n-1): what is the largest subset ...
user3220162's user avatar
1 vote
1 answer
86 views

Compute largest subset of a set such that all the elements of the subset would pairwise respect a certain condition

I have a set S consisting of natural numbers and a function that when given two natural numbers as an input it returns either true or false. Let's call the criteria based on which it computes the ...
H-a-y-K's user avatar
  • 152
0 votes
1 answer
60 views

Groupby a dataframe conditioned on "subset" relationship?

Generate a sample dataframe using: import pandas as pd pd.DataFrame({'A': [{'A', 'B'}, {'A', 'B', 'C', 'E'}, {'B', 'D'}, {'C', 'B'}, {'A', 'B', 'D'}, {'X'}], 'B': [111, 222, 333, 444, 555, 666]}) ...
frr0717's user avatar
  • 41
1 vote
1 answer
43 views

How can I get a random selection from one dictionary that is a subset of another, without hitting recursion limit so often?

Disclaimer: I have checked many questions with similar keywords, but I don't believe they address my situation. Please correct me if I'm wrong, but I can't find anything. I'm trying to get coverage ...
iamlc's user avatar
  • 75
0 votes
2 answers
345 views

How can i add subset to set in python [duplicate]

i can't add set to python you can add tuple to python set a={1,2,3,4,5} a.add((10,11,12)) when i try same with set a={1,2,3,4,5} a.add({10,11,12}) TypeError: unhashable type: 'set'
lasha tlasha's user avatar
1 vote
1 answer
86 views

How can I efficiently randomly select items from a dictionary that meet my requirements?

So at the moment, I have a large dictionary of items. Might be a little confusing, but each of these keys have different values, and the values themselves correspond to another dictionary. I need to ...
iamlc's user avatar
  • 75
-1 votes
1 answer
157 views

issubset method different than subSet in superSet - Error in Python3.x

Why issubset method of sets in python3.x don't return the same than subSet in superSet ? logically is correctly but the console return me unexpected result works fine with shorts sets but large sets ...
Alberto Licea's user avatar
1 vote
2 answers
795 views

How to find all subsets of a specified length?

I asked about this in my previous question. I want to find all subsets of a specified length. Damien wrote me a nice answer in C++, and I'm trying to convert that, but with no luck. Here is my attempt:...
klutt's user avatar
  • 31.2k
3 votes
5 answers
3k views

Finding all subsets of specified size

I've been scratching my head about this for two days now and I cannot come up with a solution. What I'm looking for is a function f(s, n) such that it returns a set containing all subsets of s where ...
klutt's user avatar
  • 31.2k
1 vote
1 answer
127 views

Problem with using sets and issubset in Python

I'm not clear about how my sets needs to be written. The answer I'm getting is False, which means I'm using the issubset type wrong or my sets are not written correctly. some_cords = {(1, 2), (2, 2), (...
cpsharp's user avatar
  • 45
0 votes
1 answer
20 views

RegExp set contains one or multiple words

Is there a way in regular expressions to match a subset of words against a set of words separated by a separator that does not involve creating a new pattern for every new word added to the set. Right ...
Gijs's user avatar
  • 175
1 vote
5 answers
907 views

Check if a Dictionary is a Subset of another Dictionary with Key Value pairs

I have two Dictionaries resources, and available_resources: resources = {'B': 1, 's': 2, 't': 3, 'e': 3, '!': 1, 'h': 1, 'i': 1, ' ': 3, 'o': 1, 'g': 1, 'E': 1, 'A': 1, 'x': 2, 'p': 1, 'l': 1, 'r': 1} ...
Suleyman Kiani's user avatar
5 votes
3 answers
503 views

Fastest way to split a list into a minimum amount of sets, enumerating all possible solutions

Say I have a list of numbers with duplicants. import random lst = [0, 0, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 6, 7, 7, 8, 8, 8, 9] random.shuffle(lst) I want to split the list into a minimum amount of ...
Shaun Han's user avatar
  • 2,785
0 votes
1 answer
445 views

Is there any alternative for issubset() for list in python. all I want is to return a bool True if list1 is subset of list2 else False [closed]

Is there any alternative for issubset() for list in python. all I want is to return a bool True if list1 is subset of list2 else False. So that { if list1.ABC(list2) } will return True if all the ...
Darshil Shah's user avatar
-1 votes
1 answer
196 views

How do you print all non-empty subsets of an array ordered in Java?

Basically, I already generated all possible non-empty subsets. However, the approach I have taken to find this doesn't print it in the order I want it to. For example, if I input 1 2 3, I want the ...
Enbao Cao's user avatar
1 vote
1 answer
43 views

Algorithm: Find out which objects hold the subset of input array

We have some objets (about 100,000 objects), each object has a property with some integers (range from 1 to 20,000, at most 20 elements, no duplicated elements.): For example: object_1: [1, 4] ...
Kxrr's user avatar
  • 520
0 votes
1 answer
154 views

Generating Maximal Subsets of a Set Under Some Constraints in Python

I have a set of attributes A= {a1, a2, ...an} and a set of clusters C = {c1, c2, ... ck} and I have a set of correspondences COR which is a subset of A x C and |COR|<< A x C. Here is a sample ...
Muhammad Adeel Zahid's user avatar
0 votes
1 answer
480 views

how to declare a subset from a set in cplex?

i am a new in Cplex , so i want to know how to declare a subset included in a set . i have a S_i : the set of flight i's Feasible start time tuples. and i declare this et like this : int F=....
Siw Mni's user avatar
  • 21
0 votes
1 answer
1k views

Pandas - check if set values in column are a subset of set values in another column

I have a dataframe df, with columns that contain sets. Here is a sample: df=pd.DataFrame([[{1,2,3,'a'},{5,'b','d',1,4}], [{'z',9,'a','b',3},{'a',3,'z','b','d',9,4}]],columns=['...
clg4's user avatar
  • 2,943
1 vote
2 answers
1k views

How to find sets containing sets in Racket

So I have this program that has several definitions. Three of interest here are (set-equal? L1 L2), (union S1 S2) and (intersect S1 S2). For set-equal? it should test if L1 and L2 are equal, where Two ...
terrylt1's user avatar
-1 votes
5 answers
64 views

how to find subsets from given sets like below

How to make program for getting subset if given list is [1,2,3] and output should be [[1], [2], [3], [1,2], [2,3], [1,3], [1,2,3]]. That is how to get all possible combinations?
dhananjay wadhavane's user avatar
0 votes
1 answer
741 views

finding all subsets of a given set in java and in this order

actually I want to write all subsets of a given set in this way : for example if my set is A:{1,2} I want to have {} , {1} , {2} , {1,2} this is what I tried : static void printSubsets(java.util....
mas's user avatar
  • 85
1 vote
1 answer
71 views

How to find all subsets of a set using java with custom format for output

I am trying to write a code to find all the possible subsets of a set using java and here is my code : public static void printSubSets(Set set){ int n = set.size(); ArrayList<String> ...
Mohammad Eskini's user avatar
7 votes
3 answers
5k views

Kotlin: Iterate through every pair (or generally fixed-sized subsets) in collection

Is there a short/idiomatic way to iterate through every pair of elements in a collection? Even better would be a method that iterates through all fixed-cardinality subsets of a collection. The classic ...
Moritz Groß's user avatar
  • 1,450
0 votes
1 answer
444 views

A fast and efficient way to test if a set is subset of any other n sets?

I have the following problem: I have a list of items [O_0,..., O_n] , where each item is represented by a binary power (o_0 represented by 2^0, ..., o_n by 2^n). I have constructed a list of ...
abdul rahman taleb's user avatar
0 votes
0 answers
133 views

Fastest way to exclude numbers from an array in each loop iteration

I am not a python expert. I am trying to implement a solution for a K-Coloring interval problem. Only using the python standard library, so no numpy,. What i want to achieve : So i have a sorted ...
kollegah's user avatar
0 votes
1 answer
136 views

How to add the items in subset in c & store them in some array or some datatype so I can access each sum for further comparison?

I have generated subset of a set I want to calculate the sum of that set like the output is: Enter the elements of main set :3 1 2 There are 8 subsets Subset 7 = 3 1 2 Subset 6 = 1 2 Subset 5 = 3 2 ...
ROCKY's user avatar
  • 7
0 votes
1 answer
42 views

Displaying sets and subsets of a string

I am trying to find the subsets and output them with binary representation. EXAMPLE: 000:EMPTY 001:C 010:B 011:B C 100:A 101:A C 110:A B 111:A B C I have the following code that finds all subsets ...
Clueless's user avatar
-1 votes
3 answers
74 views

to find a set (having copies of elements) is a subset of a bigger set in python

i have 2 sets a=[3,4,5,5] b=[3,4,5,6,7,8,9] we have to find whether a is a subset of b? a=[3,4,5,5] b=[3,4,5,6,7,8,9] if(set(a).issubset(set(b))): print('yes') else: print('no') this code ...
anadi's user avatar
  • 63
1 vote
2 answers
105 views

How to remove all duplicate lists and lists that are subset of other lists from an array of lists?

I am given a list of lists. I have to remove from that list of lists, lists that are full subsets of any other list in that list of lists and lists that are equal to any other list in that list of ...
Hamsa's user avatar
  • 483
1 vote
3 answers
816 views

How to iterate through all partitions of a list with a condition on the subsets lenghts

For certain purposes, I need to generate an iterable that lists all the partitions of a list, but with a condition on the subsets lenghts. That is, I want to partition my list in subsets of equal ...
Thierry's user avatar
  • 11
0 votes
0 answers
81 views

Calculating the smallest sum of a list where certain subsets have different values

I am trying to recreate the card game "Five Crowns" in python and I ran into a tricky algorithmic problem I can't figure out for trying to calculate the score of a hand. Basically, scoring works like ...
evs21's user avatar
  • 45
3 votes
2 answers
175 views

Find frequency of subsets amongst multiple sets

I have a list of skills as follows: skills = ['Listening', 'Written_Expression','Clerical', 'Night_Vision', 'Accounting'] I have a separate list of sets, each of which contains the skills ...
Lonewoolf's user avatar
1 vote
1 answer
796 views

How to constraint a variable in Minizinc to be part of a set

I am looking for a constraint that will force an array of variables to take the values from a specific set or Array My constants are: An array of arrays (or array of sets) that are known (calculated ...
Ganor Tamir's user avatar
0 votes
0 answers
83 views

Given a set of arrays, find out which arrays are subset of another

I am working on a project, where we have a set of arrays with same (and fixed) length, and their entries could be Null or a number. Some arrays are "somehow" subsets of other arrays. In this problem, ...
EdenHazard's user avatar
-1 votes
1 answer
1k views

Partitioning the array into k non-empty non-intersecting subsegments such that each subsegment has odd sum

I am new in competitive programming. The other day I was solving this problem You are given an array a consisting of n integers a1,a2,…,an. You want to split it into exactly k non-empty non-...
Hamsa's user avatar
  • 483
1 vote
0 answers
84 views

Subtracting a sub set from a set in alloy

I am playing around with alloy and I am using a pretty simple example. What I am trying to do is return the set of a specifics person's aunts. I am trying to accomplish with the following code, but it ...
Kyle's user avatar
  • 441
0 votes
1 answer
1k views

Algorithm to find the best combination of a list if given sets

I'm looking for an algorithm to find the best combination (the highest weight) of a list of sets. For example, let's say we have items 'A', 'B' and 'C' and we got 4 A's, 2 B's and 3 C's. Some possible ...
Algeel's user avatar
  • 11
11 votes
2 answers
9k views

Python: How to obtain a random subset

How would I get a random subset of a set s in python? I tried doing from random import sample, randint def random_subset(s): length = randint(0, len(s)) return set(sample(s, length)) But I ...
Enrico Borba's user avatar
  • 2,117
0 votes
1 answer
232 views

How to find sum of each subset in php?

I want to compute the sum of all possible sub-set form array. $array= Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 6 ); //changing function powerSet($array) { // add the empty ...
Andrew's user avatar
  • 846
1 vote
3 answers
117 views

Determine subset using recursion

I am trying to write a function subset which takes two lists and determines whether the elements of the first appear in the second. The code compiles to the GHCi but does not run (i.e. becomes stuck)...
David Ciocoiu's user avatar
3 votes
1 answer
487 views

Creating all multisets of subsets of NON DISTINCT values, in Java

Given an array of objects, i need to find, as efficiently as possible, all different sets of subsets of the given array, that include all values, when the values in the array may repeat. for example: ...
Eytan Rath's user avatar
1 vote
0 answers
79 views

Algorithm for all combinations to divide set into equally sized subsets [duplicate]

I need a little bit of algorithmic help to improve the performance of an analysis. The Problem: given a set of N many elements X[0], ..., X[N-1]: I need all possible ways of dividing those N ...
DudeDoesThings's user avatar
-1 votes
1 answer
88 views

How to find a family in a group of individuals

Say I have a group S of potential family members. I define a family as a set of individuals, which contains one or two adults (over 18 years old) and at most 9 children (under 24 years old), but with ...
Ipsider's user avatar
  • 571
2 votes
1 answer
93 views

How do I find number of subsets satisfying two constraints?

Suppose I have a set: A = {1, 2, 3, 4}. I have to find the number of subsets of size K, which must have an element p. For example K = 3, p = 2 - then the subsets must be of size 3 and must have an ...
Chandresh Phirke's user avatar
0 votes
1 answer
198 views

Sum of OR of smallest and largest elements of each subset of a set

Given a set S, for its each non-empty subset, find smallest and largest elements and take their logical OR. Find sum of these ORs across all such subsets. For example: S = {1, 2, 3}, then subsets {1}...
Sushil Verma's user avatar
2 votes
1 answer
56 views

Debugging number of possible sums - JavaScript

I'm writing an algorithm that finds the number of possible sums from an array that contains unique values, and a second array that contains the quantity of each corresponding value in the first array. ...
Snkendall's user avatar
  • 110
0 votes
1 answer
21 views

Data structure for subset-reduced growing list

I'm working on a problem which involves going through a lot of data. To reduce the work (because current calculations take about two weeks of compute time, and I'd like to reduce that dramatically) I ...
Charles's user avatar
  • 11.4k
1 vote
1 answer
44 views

Define overlap elements or elements not contained in subsets

I would like to check which strategy would be the most efficient to compute the problem described below I have one set Q and two subsets L and R. I have three cases. 1) L ∩ R != 0. In this case, I ...
WillEnsaba's user avatar
0 votes
1 answer
898 views

Subsets of size "k" using Guava

I have around 1 million sets each with around 30 elements. For each set, I want to generate all subsets up to size "k" where k is going to be something like 3 or 4 or 5. I am new to Guava and decided ...
Andrew's user avatar
  • 1,157