sets

Python, subclassing immutable types

I've the following class: class MySet(set): def __init__(self, arg=None): if isinstance(arg, basestring): arg = arg.split() set.__init__(self, arg) This works as expected (initialising the set with the words of the string rather than the letters). However when I want to do the same with the immutable ...

Minimum set cover [PHP]

Minimum Set Cover is a question where you must find the minimum number of sets needed to cover every element. For example, imagine that we have a set of X=array(1,2,3,4,5,6) and 5 another set S, where S[1]=array(1, 4) S[2] =array(2, 5) S[3] =array(3, 6) S[4] =array(1, 2, 3) S[5] =array(4, 5, 6) The problem is to find minimum numb...

Java set of byte arrays

I have a HashSet of byte[]s and I would like to test whether a new byte[] is in that set. The problem is that Java seems to be testing whether the byte[] instances are the same rather than testing whether the actual values in the byte arrays are the same. In other words, consider the following code: public class Test { public stat...

C# in VS2005: is there set style notation for integers?

For C# in VS2005, can you do something like this: if number in [1,2..10,12] { ... } which would check if number is contained in the set defined in the square brackets? ...

Finding continuous ranges in a set of numbers

I have a reasonably large set of phone numbers (approximately 2 million) in a database table. These numbers have been inserted in blocks, so there are many continuous ranges of numbers, anything from 10 numbers to 10 thousand in a range. Some of these numbers are in use and are therefore marked as unavailable, the rest are available. Giv...

Find set of numbers in one collection that adds up to a number in another.

For a game I'm making I have a situation where I have a list of numbers say [7, 4, 9, 1, 15, 2] (named A for this) and another list of numbers say [11, 18, 14, 8, 3] (named B) provided to me. The goal is to find all combinations of numbers in A that add up to a number in B. For example: 1 + 2 = 3 1 + 7 = 8 2 + 9 = 11 4 + 7 = 11 1...

How do I use clojure.set/difference? Why won't it work on a PersistentSet?

The following code: (require '[clojure.set]) (println (clojure.set/difference '("a" "b" "c" "d") '("c" "d" "e" "f"))) gives me the following error: java.lang.ClassCastException: clojure.lang.PersistentList (repl-1:47) I don't understand what I'm doing wrong. Shouldn't this print out ("a" "b")? ...

Challenge to calculate maximum quantity and split sets with PHP

I have two items, A and B. You can only have a maximum set of 2 items at any one time. This results in the following combinations: A B 1 0 2 0 0 1 0 2 1 1 If you want 3 or more items, the remainders spill over into a new set. Sets of 2 are preferred over single items in a set. Examples: 2 lots of A and 1 lot of B (total 3 items) wou...

Is it possible to share a set between two tables in MySQL?

I am currently in the process of designing a database. I have a table of 20,000+ records, which has a set in it (4 values). I also am making another table (100+ records) which will have an enum over the same set (1 value from the same set) Example of current: tbl1 tbl2 ID | Letters | Stuff ID | Le...

large set implementation in MongoDB

I have a data set in MongoDB that involves a large set of emails and I need to be able to add emails to the set and being able to check if certain emails are in the set. I thought of doing with document structure like this: {'key': 'foo', 'emails':['[email protected]','[email protected]', ...]} and use $addToSet and $in. But the problem is that ...

general problem- sets,python

I got a problem: keys here is a list. keys = [(6,4) , (6,8)] The entries in the keys can be 4,5...or watever Now, I have to pick up only 1 from it.So I used: root = keys[0] print root output: (6,4) Now I have to make a set which is empty, say,... closed = set() for u,v of root: if v not in closed: closed.add(v) ...

sets in python problem

can we remove a entry from the sets. what are the commands to use for it? like, my set conatins (6,5) , (6,7), (7,9)...I need to remove the second entry...what shud I do?? ...

error: list objects are unhashable

closed = set() -here closed is a set node is (5,5) The error occurse at execution time. Error is: list objects are unhashable the program is: closed.add(node) for val in closed: print val Node is the output of stack. node = stack.pop() - it gives me...(5,5) Traceback: File "/home/", line 99, in depthFirstSearch ...

How to safely remove objects from NSMutableSet (cocos2d-iphone)

Hello. I'm rather new to serious programming, so please forgive my dumbness, but I've failed to figure this out by myself. I am writing a game with cocos2d-iphone. I have a scene object with several NSMutableSets in its ivars - units, buildings, rockets, etc. I have a problem removing objects from these NSMutableSets. When a bullet obj...

How to create the union of many sets using a generator expression?

Suppose I have a list of sets and I want to get the union over all sets in that list. Is there any way to do this using a generator expression? In other words, how can I create the union over all sets in that list directly as a frozenset? ...

Algorithm: What is the fastest way to check for set inclusion?

Having an array of N sets, what is the fastest way to generate the inclusion graph of these sets? ...

Performing set operations on diffs?

Are there any tools which can perform set operations (union, intersection, difference, etc) on diffs? For example, if I've got two diffs that overlap (ie, contain hunks with identical changes), I'd like to be able to do things like "get all hunks which are only in one diff" or "get all hunks which are common to both diffs". For example...

Algorithm to check whether one set is a proper set from another set

Write an algorithm to check whether a set A is proper set from B or not. (Hint: proper set is that set A is subset from B but they should not be equal, the result should be either True or False, if true that means A is proper set else it is not proper set) ...

REXX / z/OS question

Hi, I'm wondering one thing with REXX-language, how it handles data set locks. The situation: - I have sequential data set open in my ISPF-editor - I start REXX-program what updates (makes changes) that data set - it works fine, but how it is possible? Normally if you have data set open in your editor and you try to use that from anothe...

Efficient algorithm to find additions and removals from 2 collections

Hi I would like to implement an efficient algorithm to handle the following case: Lets assume we have 2 lists with the following elements: Source: [a,b,c,d,e] New: [d,e,f,g] Now I have to update source with the new information. The algorithm should be able to find that 'f' and 'g' are new entries, that 'a', 'b' and 'c' has been remove...