Questions About Set2

Subset calculation of list of integers

I'm currently implementing an algorithm where one particular step requires me to calculate subsets in the following way.

Imagine I have sets (possibly millions of them) of integers. Where each set could potentially contain around a 1000 elements:

Set1: [1, 3, 7]
Set2: [1, 5, 8, 10]
Set3: [1, 3, 11, 14, 15]
...,
Set1000000: [1, 7, 10, 19]

Imagine a particular input set:

InputSet: [1, 7]

I now want to quickly calculate to which this InputSet is a subset. In this particular case, it should return Set1 and Set1000000.

Now, brute-forcing it takes too much time. I could also parallelise via Map/Reduce, but I'm looking for a more intelligent solution. Also, to a certain extend, it should be memory-efficient. I already optimised the calculation by making use of BloomFilters to quickly eliminate sets to which the input set could never be a subset.

Any smart technique I'm missing out on?

Thanks

http://www.stackoverflow.com/questions/14123595/subset-calculation-of-list-of-integers

Algorithm to match pairs from two sets

I have two sets, each set is a listing of a pair of numbers

Set1 =[(x1, y1), (x2, y2), ..., (xN, yN)]
Set2 =[(a1, b1), (a2, b2), ..., (aN, bN)]

If plotted on an XY plane, Set1 and Set2 have the same basic shape, however the data points of set2 are a rotated/translated/scaled/noisy/skewed version of set1. The ordering of the pairs within each set is random. Is there an efficient way to determine which points in set1 correspond to their counterparts in set2?

http://www.stackoverflow.com/questions/14266649/algorithm-to-match-pairs-from-two-sets

Pool numbers in a set of numbers to match the size of another set

I need to reduce the size of a set by combining the numbers in it. I need all possible combinations. Here are two examples that might illustrate my situation.

1) Set1 has 4 entries and Set2 has 2. So we need to combine two numbers in each case.

Set1 = {70, 100, 50, 200}; Set2 = {"part1", "part2"}
All combinations I want to retrive should look like following:
"part1"        |"part2"
  70 + 100       |  50 + 200
  70 + 50        | 100 + 200
  70 + 200       |  50 + 100
 100 + 50       |  70 + 200
 100 + 200      |  50 +  70
  50 + 200       | 100 +  70
 50             |  70 + 100 + 200
 70             |  50 + 100 + 200
 100            |  50 +  70 + 200
 200            |  50 +  70 + 100  
 70 + 100 + 200 |  50
 50 + 100 + 200 |  70
 50 +  70 + 200 |  100
 50 +  70 + 100 |  200 

2) Set1 has 4 entries and Set2 has 3. So we need to combine two numbers just once.

Set1 = {70, 100, 50, 200}; Set2 = {"part1", "part2", "part3"}
All c
    
http://www.stackoverflow.com/questions/14438404/pool-numbers-in-a-set-of-numbers-to-match-the-size-of-another-set

Building a URL with ActionLinks from within a Controller in MVC

I'm building a basic flashcard application - a Set contains Cards and other Sets. When navigating to something like Set1 > Set2 > Set3, I want each of the parent "Sets" to link to their respective details page. I'm passing the Details viewModel a string called "breadcrumbs", which contains something like this:

var stringBuilder = "";
            var parent = model.ParentSet;

            while (parent != null)
            {
                stringBuilder += "<li><a href="@Url.Action('Detail'
    
http://www.stackoverflow.com/questions/14841583/building-a-url-with-actionlinks-from-within-a-controller-in-mvc

How to find intersection of sets

I have N number of sets of let us say integers. Now I want a function, which finds me the intersection of those sets. For example, for the following

Set1 = { A, D, E, F, G, L }
Set2 = { N, K, E, G, B, C }
Set3 = { K, P, Q, E, F, G }
Set4 = { Z, Y, C, G, F, E }

Since E and G is in every set, I should get { E, G } as output. What is the easiest way to do this. I know it is not very difficult to write your own code to do this, but perhaps there is already an STL or any other library function to this, in which I'm interested.

http://www.stackoverflow.com/questions/15087197/how-to-find-intersection-of-sets

(Javascript/RaphaelJS) How would I append a variable to a new object in a new array?

Sorry If this seems short/ un-researched (I've probably been looking in all the wrong places with the wrong logic in mind) but I feel like the answer is going to be simple/straight forward.

Say I have some variables set up, for example:

var path1 = paper.path("M 95, 259 L 110, 250... etc. etc.. ");

var path2 = paper.path("M 96 138 L 55, 100,... etc... etc..");

Insert them into a set...

var set1 = paper.set();
    set1.push(icon1, path1);

EDIT: These two steps x2 ^^^^^^^^^

Then want to go ahead and insert that new set into a new array with new objects with their own ids, So I can later reference that array when I set up a click handler function.

Basically is there any way I should/can go about attaching each set to this new array of new objects?

EDIT:

Here's more specifically what I'm working with.. I created a for loop to run through that array... which works but it only dis

http://www.stackoverflow.com/questions/14087521/javascript-raphaeljs-how-would-i-append-a-variable-to-a-new-object-in-a-new-array

How to receive difference of maps in java?

I have two maps:

Map<String, Object> map1;
Map<String, Object> map2;

I need to receive difference between these maps. Does exist may be apache utils how to receive this difference? For now seems need take entry set of each map and found diff1 = set1 - set2 and diff2 = set2- set1. After create summary map =diff1 + diff2 It looks very awkwardly. Does exist another way? Thanks.

http://www.stackoverflow.com/questions/12721735/how-to-receive-difference-of-maps-in-java

How to implement a Set with a user-defined equality

This question is related to this one: is it possible to create a Set-like class (meaning that it's extending the Set trait) in Scala where the equality used to define the containment relationship is defined by the user instead of being ==?

One way to test if this really works is to check whether filter returns the same collection type.

// typeclass for equality
trait Equals[T] {
  def isEqual(t1: T, t2: T): Boolean
}

// an object representing plane coordinates
case class Coordinate(i: Int, j: Int)

// an equality saying that 2 coordinates are equal if they are on 
// the same horizontal line
implicit def horizontalEquality: Equals[Coordinate] = new Equals[Coordinate] {
   def isEqual(t1: Coordinate, t2: Coordinate) = t1.i == t2.i
}

// we create an EqualitySet[T] where T must verify [T : Equals]     
val set = EqualitySet[Coordinate]()

    
http://www.stackoverflow.com/questions/12739432/how-to-implement-a-set-with-a-user-defined-equality

union of 2 sets; return simple object - C++

What is the best way to implement the following? I am trying to find the union of 2 sets. I am creating 2 objects (one called set1 and one called set2). I aim to create a 3rd object that is a UNION of the two without having to use a copy constructor. Using dynmanic memory allocation and pointers and/or references is a must. Thanks to anyone to solves this dilemma and any pointers (no pun intended) would help.

Thanks coders.

THE HEADER file

                #ifndef INTEGERSET_H_
                #define INTEGERSET_H_

                class IntegerSet
                {
                private:
                    int * set;
                    int set_size;
                public:
                    IntegerSet(int size);    //default constructor
                    ~IntegerSet();           //destructor
                    IntegerSet * unionOfSets(const IntegerSet & set2);      
                    void insertElement(int k) const;
                
    
http://www.stackoverflow.com/questions/12739565/union-of-2-sets-return-simple-object-c

Array Issue in Objective C Xcode

I have a problem with my algorithm for calculating a sore. The user enters a word into the UITextField, and if the word matches a string in the array (@"The Word") the int 'score' will be added by 1.

Then the int score is set as a label as the user gets a word right. (DISPLAYING THE SCORE)

THE PROBLEM, a user can just keep on entering the same word over and over again and the score will keep going up by one. IS there a command for knowing if a word has already been entered, so you can only use the word once.

The Code

 NSArray *scoreArray1 = [NSArray arrayWithObjects:
@"Word 1", @"Word 2", @"Word 3", nil];

NSString *inputtwo =_EnterNameText.text;
BOOL isItright = NO;
for(NSString *possible in scoreArray1) {
    if([inputtwo isEqual:possible] ) {
        isItright = YES;
        break;
    }
}

if(isItright) {

    static int myInt = 0;
    myInt++;
    NSString *score = [NSString stringWithFormat:@"%d", myInt];
    [_scorelabel setText:
    
http://www.stackoverflow.com/questions/12902079/array-issue-in-objective-c-xcode

set union operation in Prolog : explanation

union([H|T],[],[H|T]).     
union([],[H|T],[H|T]).    
union([H|T], SET2, RESULT) :- member(H,SET2), union(T,SET2,RESULT).    
union([H|T], SET2, [H|RESULT]) :- not(member(H,SET2)), union(T,SET2,RESULT).

I am able to understand that it is traversing the first list and adding based on whether the element is a member of 2nd list or not. I got the logic. However, the workflow is mysterious to me where it adds the elements of "second list" to the result once the first list is exhausted.

Please could someone take a simple example like union([1,2], [2,3], Result), and explain the workflow.

http://www.stackoverflow.com/questions/12905839/set-union-operation-in-prolog-explanation

vbscript text file search a line with multiple strings

Need small modification in the below vbscript...

Const ForReading = 1

Dim strSearchFor, set1, set2
strSearchFor = "10/17/2012"
set1= app1

set2 =app2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("mylogfile.log", ForReading)

do until objTextFile.AtEndOfStream
    strLine = objTextFile.ReadLine()

    If InStr(strLine, strSearchFor and set1 or set2) <> 0 then

Wscript.Echo "we found current date with app1 or current date with app2"
    Else
        Wscript.Echo "We did not found current date"
    End If
loop
objTextFile.Close

My actual mylogfile.log sample file has below in the text file.

working on 10/17/2012 starting something ending
closing on  started app1
working on 10/17/2012 starting something app1
working on 10/17/2012 starting something app2
closing on 10/17/2012 starting something ending

Thanks.. in advance for your valuable time ..

http://www.stackoverflow.com/questions/12930384/vbscript-text-file-search-a-line-with-multiple-strings

Does Set Of Sets on contain method checks the order?

My concern is if the Set of Sets (HashSet s) checks the order of items as well. I wrote the app that checks if the given Set of Integers exists in the Set of Sets of Integers

Somehow on one computer yesterday I noticed what Set of Integers is unordered (what is OK about HashSets) but I worried and wrote some simple main for check it :

public static void main(String[] args) {

    Set<Set<Integer>> set1 = new HashSet<Set<Integer>>();
    Set<Integer> set2 = new HashSet<Integer>();
    Set<Integer> set3 = new HashSet<Integer>();

    set3.add(14); set3.add(2); set3.add(9); set3.add(3); set3.add(5);

    set1.add(set3);

    set3 = new HashSet<Integer>();
    set3.add(6); set3.add(7); set3.add(8); set3.add(9); set3.add(10);   
    set1.add(set3);

    set2.add(9); set2.add(14); set2.add(5); set2.add(2); set2.add(3);

    System.out.println(set1);
    System.out.println(set2);
    if(set1.contains(set2)){
    
    
http://www.stackoverflow.com/questions/12939701/does-set-of-sets-on-contain-method-checks-the-order

Adding and removing multiple elements in javascript

I am trying to populate a list of images dynamically using javascript. I have the following code, but it is not working. If you see any errors, or know of a better way of doing this, any help will be appreciated.

code is as follows:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<script type="text/javascript">
function generateCarousel(baseval, num_images)
{
    var list_node = document.getElementById("carousel");
    list_node.innerHtml(''); // clear the previous contents

    for (var i = 0; i < num_images; i++)
    {
        var img = document.createElement("img");
        img.src = baseval + ((i<9)?0+i:i) + ".jpg"; 
        list_node.appendChild(img);
    }
}
</script>
<style type="text/css">
#carousel {
    width: 700px;
    height: 450px;
    overflow-x: scroll;
    overflow-y: hidden;
    white-space: nowrap;
}
</style>

</head>


<body>

<div id="Container">



<div id="Content">

    
http://stackoverflow.com/questions/2214619/adding-and-removing-multiple-elements-in-javascript

Why does this C++ code fail?

I have the following code

#include <iostream>
#include <vector>

using namespace std;

int distance(vector<int>& set1, vector<int>& set2) {
    int distance = 0;

    unsigned int i1 = 0;
    unsigned int i2 = 0;
    while(i1 < set1.size() && i2 < set2.size()) {
        if(set1[i1] == set2[i2]) {
            ++i1; ++i2;
        } else {
            ++distance;
            set1[i1] < set2[i2] ? ++i1 : ++i2;
        }
    }

    unsigned int zero = 0;
    distance += std::max(set1.size() - i1, zero) + std::max(set2.size() - i2, zero);
}

int main() {
    vector<vector<int> > frequent_sets;
    vector<int> vector3;
    vector3.push_back(1);vector3.push_back(2);vector3.push_back(3);
    vector<int> vector2;
    vector2.push_back(1);vector2.push_back(2);

    frequent_sets.push_back(vector3);
    frequent_sets.push_back(vector3);
    frequent_sets.push_back(vector2);
    frequent_sets.push_back(vecto
    
http://stackoverflow.com/questions/2295297/why-does-this-c-code-fail

Multi-part question about multi-threading, locks and multi-core processors (multi ^ 3)

I have a program with two methods. The first method takes two arrays as parameters, and performs an operation in which values from one array are conditionally written into the other, like so:

void Blend(int[] dest, int[] src, int offset)
{
    for (int i = 0; i < src.Length; i++)
    {
        int rdr = dest[i + offset];
        dest[i + offset] = src[i] > rdr? src[i] : rdr; 
    }
}

The second method creates two separate sets of int arrays and iterates through them such that each array of one set is Blended with each array from the other set, like so:

void CrossBlend()
{
    int[][] set1 = new int[150][75000]; // we'll pretend this actually compiles
    int[][] set2 = new int[25][10000]; // we'll pretend this actually compiles
    for (int i1 = 0; i1 < set1.Length; i1++)
    {
        for (int i2 = 0; i2 < set2.Length; i2++)
        {
            Blend(set1[i1], set2[i2], 0); // or any offset, 
    
http://stackoverflow.com/questions/2941371/multi-part-question-about-multi-threading-locks-and-multi-core-processors-multi-3

Fast way to compute the minimal distance of two sets of k-dimensional vectors

I two sets of k-dimensional vectors, where k is around 500 and the number of vectors is usually smaller. I want to compute the (arbitrarily defined) minimal distance between the two sets. A naive approach would be this:

(loop for a in set1
      for b in set2
      minimizing (distance a b))

However, this requires O(n * distance) computations. Is there a faster way of doing this?

http://stackoverflow.com/questions/2984325/fast-way-to-compute-the-minimal-distance-of-two-sets-of-k-dimensional-vectors

Accessing Variables in Javascript using .length

I'm pretty new to Javascript, so forgive me if this is a simple question.

I'm trying to access the length of a set of checkboxes in a form using Javascript. However, I need to be able to change the "name" field of the checkboxes to check several different sets of them. Right now, my sample code looks like:

var set = "set" + x;
totalLength = optionBoxes.set.length;

The variable x is being incremented by a for loop that wraps the whole thing and the name of the checkbox sets that I'm trying to access are set0, set1, set2, etc.

Thanks.

Edit: small typo fixes

http://stackoverflow.com/questions/3019021/accessing-variables-in-javascript-using-length