sets

Common elements between two lists not using sets in Python

I want count the same elements of two lists. Lists can have duplicate elements, so I can't convert this to sets and use & operator. a=[2,2,1,1] b=[1,1,3,3] set(a) & set(b) work a & b don't work It is possible to do it withoud set and dictonary? ...

Comparing lists of field-hashes with equivalent AR-objects.

I have a list of hashes, as such: incoming_links = [ {:title => 'blah1', :url => "http://blah.com/post/1"}, {:title => 'blah2', :url => "http://blah.com/post/2"}, {:title => 'blah3', :url => "http://blah.com/post/3"}] And an ActiveRecord model which has fields in the database with some matching rows, say: Link.all => [<Link#2 @ti...

java: how do I create an array of tuples

how can I create an array of tuples in jsp (java) like (a:1, b:2) (c:3, d:4) ... ... ...

SQL - Counting sets of Field-B values for each Field-A value

Hello, First of all sorry that I could not think of a more descriptive title. What I want to do is the following using only SQL: I have some lists of strings, list1, list2 and list3. I have a dataset that contains two interesting columns, A and B. Column A contains a TransactionID and column B contains an ItemID. Naturally, there ca...

Order awesome nested set array for combo box lookup

I'm using Awesome Nested Sets and Formtastic within Rails and am having trouble listing the nester set records in a structured order within a lookup (combo) box. I'd list to show the lookup box like so: -Parent1 --P1Child1 --P1Child2 -Parent2 --P2Child1 --P2Child2 --P2Child3 etc... Origionally the lookup box was displaying the resul...

Finding subsets that can be completed to tuples without duplicates

We have a collection of sets A_1,..,A_n. The goal is to find new sets for each of the old sets. newA_i = {a_i in A_i such that there exist (a_1,..,a_n) in (A1,..,An) with no a_k = a_j for all k and j} So in words this says that we remove all the elements from A_i that can't be used to form a tuple (a_1,..a_n) from the sets (A_1,..,A_n...

Implementing union of Set using basic java array

Note: This is an assignment. Hi, Continuing with my Set implementation using Java basic array, I'm now struggling with the 3 to last function namely the union. import java.io.*; class Set { private int numberOfElements = 0; private String[] setElements = new String[5]; private int maxNumberOfElements = 5; ...

joining two sets in LINQ

var setsA = new List<SetA> { new SetA { SsnA = "3450734507", name = "setA"}, new SetA { SsnA = "6833467788", name = "setA"}, new SetA { SsnA = "5452347787", name = "setA"}, new SetA { SsnA = "9345345345", name = "setA"}, }; var setsB = new List<SetB> { new SetB { SsnB = "5452347787" ,n...

Java constructor and modify the object properties at runtime

Note: This is an assignment Hi, I have the following class/constructor. import java.io.*; class Set { public int numberOfElements = 0; public String[] setElements = new String[5]; public int maxNumberOfElements = 5; // constructor for our Set class public Set(int numberOfE, int setE, int maxN...

What is the better approach to find if a given set is a perfect subset of a set - If given subset is not sorted?

Hi guys, What is the best approach to find if a given set(unsorted) is a perfect subset of a main set. I got to do some validation in my program where I got to compare the clients request set with the registered internal capability set. I thought of doing by having internal capability set sorted(will not change once registered) and do...

Algorithm to determine the minimal set of coins you should carry to always make exact change

US coin values: .01, .05, .10, .25 (*) What is an algorithm to determine what configuration(s) of US coins can be used to match every value from .01-.99 using the fewest coins possible? ...

What's wrong with this code to un-camel-case a string?

Here is my attempt to solve the About.com Delphi challenge to un-camel-case a string. unit challenge1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type check = 65..90; TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Send...

Use example of Scala ObservableSet Trait

Could anyone help me telling me how to use scala's ObservableSet trait? Thank you very much in advance ...

Determine the relative complement of two IEnumerable<T> sets in .NET

Is there an easy way to get the relative complement of two sets? Perhaps using LINQ? I have to find the relative compliment of a set A relative to B. Both A and B are of type HashSet<T> but I think the algorithm could be made more general (IEnumerable<T> or even ISet<T>)? I could use a solution in either VB.NET or C#. ...

Java HashSet is allowing dupes; problem with comparable?

Hi, all. I've got a class, "Accumulator", that implements the Comparable compareTo method, and I'm trying to put these objects into a HashSet. When I add() to the HashSet, I don't see any activity in my compareTo method in the debugger, regardless of where I set my breakpoints. Additionally, when I'm done with the add()s, I see severa...

Haskell Qualified Imports (Creating an Empty Set)

I am attempting to pass back a Node type from this function, but I get the error that empty is out of scope: import Data.Set (Set) import qualified Data.Set as Set data Node = Vertex String (Set Node) deriving Show toNode :: String -> Node toNode x = Vertex x empty What am I doing wrong? ...

Haskell Ord instance with a Set

I have some code that I would like to use to append an edge to a Node data structure: import Data.Set (Set) import qualified Data.Set as Set data Node = Vertex String (Set Node) deriving Show addEdge :: Node -> Node -> Node addEdge (Vertex name neighbors) destination | Set.null neighbors = Vertex name (Set.singleton destina...

looking for a set union find algorithm

I have thousands of lines of 1 to 100 numbers, every line define a group of numbers and a relationship among them. I need to get the sets of related numbers. Little Example: If I have this 7 lines of data T1 T2 T3 T4 T5 T6 T1 T5 T4 T3 T4 T7 I need a not so slow algorithm to know that the sets here are: T1 T2 T6 (because T1 is relat...

How to achieve better efficiency re-inserting into sets in C++

I need to modify an object that has already been inserted into a set. This isn't trivial because the iterator in the pair returned from an insertion of a single object is a const iterator and does not allow modifications. So, my plan was that if an insert failed I could copy that object into a temporary variable, erase it from the set, m...

Flex XMLList Intersections, Unions, Differences

I don't think Flex supports anything like this, but I'm new to it and thought it couldn't hurt to ask anyway before I go off and implement it myself. I'm basically wondering if Flex can give me the union or difference or intersection of two XMLLists, as in Python's sets: >>> a = set([1, 2, 3]) >>> b = set([3, 4, 5]) >>> b.difference(a) ...