pairs

Generating random couples in C#

I have a table in my DB with a list of people. I need to create a list of random buddies every day. The idea is that every day every person is paired with a differenct random person for that day. Since the table may get very large I was wondering what would be the best way to do such a thing? I have thought of 2 ideas but I am not so ...

What is the C interface to Lua for accessing a table's key/value pairs?

In Lua, using the C interface, given a table, how do I iterate through the table's key/value pairs? Also, if some table table members are added using arrays, do I need a separate loop to iterate through those as well or is there a single way to iterate though those members at the same time as the key/value pairs? ...

Getting all combinations of pairs from a list in Ruby

I have a list of elements (e.g. numbers) and I want to retrieve a list of all possible pairs. How can I do that using Ruby? Example: l1 = [1,2,3,4,5] -> l2 = [[1,2][1,3][1,4][1,5][2,3][2,4][2,5][3,4][3,5][4,5]] ...

Display pairs in Random order

Hi everyone, How can I randomised the order of pairs? e.g. I have 3 elements stored in list e.g. A,B,C --> which makes pairs of A-B, A-C, B-C. How can I display the pair in Random order? e.g. A-B, A-C, B-C or B-C, A-B, A-C or A-C, A-B,B-C ArrayList<String> s = new ArrayList<String>(); s.add("A"); s.add("B"); s.add("C"); ListGen...

Iterating over pair elements in a container of pairs (C++)

If I have a container (vector, list, etc) where each element is a std::pair, is there an easy way to iterate over each element of each pair? i.e. std::vector<std::pair<int,int> > a; a.push_back(std::pair(1,3)); a.push_back(std::pair(2,3)); a.push_back(std::pair(4,2)); a.push_back(std::pair(5,2)); a.push_back(std::pair(1,5)); and the...

Are there any methods included in Scala to convert tuples to lists?

I have a Tuple2 of List[List[String]] and I'd like to be able to convert the tuple to a list so that I can then use List.transpose(). Is there any way to do this? Also, I know it's a Pair, though I'm always a fan of generic solutions. ...

Match the pairs search algorithm?

I found an interesting pairs matching game at http://xepthu.uhm.vn. The rule is simple, you have to find and connect two identical pokemon but the path between them is not blocked and the direction can't not be changed 3 times. Let's see an example: I've think alot about the algorithm to check if the path between any 2 selected pokemo...

Looking for "Domino combination" algorithm

Hello, I'm going to complete my apprenticeship as coder and i got a nice j2me project to work on. But i have to admit that i'm not that good with mathematical algorithms as i'd like to be. My problem is to create all possible "domino pairs" from a given set of values. For example: The possible values go from 0 to 6. Now imagine some ...

.NET - Efficient sorting of pairs<key, value> by value

So, I'm looking for the most efficient way to sort a bunch of pairs<string, float> by value, because I need to get the 3 highest entries of a high number of pairs. My natural reaction was to use a sortedList, but apparently it only sorts by key, and I cant use the reversed list solution because I know for a fact that the strings are uni...

In Haskell, how can I use the built in sortBy function to sort a list of pairs(tuple)?

I am a beginner in Haskell so please bear with me. (Just started learning yesterday!) How can I sort a list of tuples primarily by their first components (highest to smallest) and secondarily by their second components (smallest to highest)? A sample input/output would be: [(1, "b"), (1, "a"), (2, "b"), (2, "a")] (input) [(1, "a"), (2,...

How do I select every pair of 2 sequential elements in jquery?

Can anyone please help me to work out how to achieve the following? I have a set of divs of unknown size. Each div has a class of .feature. I need to run a jQuery script to find all divs with .feature and then find all children as a series of pairs. Each pair will then be submitted to a further jQuery function. For example: 1. <div.fe...

(Java) Find all possible pairs in an array

Its when I try to do stuff like this I realise I really need to go to university! Anyway I have an array of strings (275) I need to loop through them and create strings of all the possible pairs, in java. I've been learning about recursion but I cant find the answer for this. Thanks ...

How does make_pair know the types of its args?

The definition for make_pair in the MSVC++ "utility" header is: template<class _Ty1, class _Ty2> inline pair<_Ty1, _Ty2> make_pair(_Ty1 _Val1, _Ty2 _Val2) { // return pair composed from arguments return (pair<_Ty1, _Ty2>(_Val1, _Val2)); } I use make_pair all the time though without putting the argument types in angle brackets: ...

Multimap containing pairs?

Is it possible for a multimap to contain within it pairs? IE, rather then being defined as multimap<char,int> for instance, it would be defined as multimap<pair, pair>? How would this multimap then be sorted? Also, how would one access the individual contents of each pair? ...