Search Results

Search found 1081 results on 44 pages for 'combinations'.

Page 1/44 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Statistics: combinations in Python

    - by Morlock
    I need to compute combinatorials (nCr) in Python but cannot find the function to do that in 'math', 'numyp' or 'stat' libraries. Something like a function of the type: comb = calculate_combinations(n, r) I need the number of possible combinations, not the actual combinations, so itertools.combinations does not interest me. Finally, I want to avoid using factorials, as the numbers I'll be calculating the combinations for can get to big and the factorials are going to be monstruous. This seems like a REALLY easy to answer question, however I am being drowned in questions about generating all the actual combinations, which is not what I want. :) Many thanks

    Read the article

  • Python combinations no repeat by constraint

    - by user2758113
    I have a tuple of tuples (Name, val 1, val 2, Class) tuple = (("Jackson",10,12,"A"), ("Ryan",10,20,"A"), ("Michael",10,12,"B"), ("Andrew",10,20,"B"), ("McKensie",10,12,"C"), ("Alex",10,20,"D")) I need to return all combinations using itertools combinations that do not repeat classes. How can I return combinations that dont repeat classes. For example, the first returned statement would be: tuple0, tuple2, tuple4, tuple5 and so on.

    Read the article

  • combinations of sizes for shipping

    - by Eadz
    Hi there, I've got a bunch of products with sizes to ship and I need to find out the cheapest rate. Given a shipment made out of sizes, say [1,3,3,5] I need to decide how to ship - all together or separate. However it's not as simple as [1,3,3,5] or 1 & 3 & 3 & 5, i need all of the possible combinations something like: [ [[1,3,3,5]], ( 1 shipment ) [[1],[3,3,5]], ( 2 shipments ) [[1,3],[3,5]], ( 2 shipments ) [[1,3,3],[5]], ( 2 shipments ) [[1,5],[3,3]], ( 2 shipments ) [[1,3],[3],[5]], ( 3 shipments ) [[1],[3],[3],[5]] ( 4 shipments ) ] ( etc - many more i assume ) I've tried combinations from the facets gem but it's not quite what i'm after, and I'm not sure how else to approach this problem. I understand it probably has a name and a solution if only I knew the name :) I understand there could be a lot of combinations, but the initial array of sizes won't be larger than 7 or so. Thanks in advance!

    Read the article

  • Algorithm to determine coin combinations

    - by A.J.
    I was recently faced with a prompt for a programming algorithm that I had no idea what to do for. I've never really written an algorithm before, so I'm kind of a newb at this. The problem said to write a program to determine all of the possible coin combinations for a cashier to give back as change based on coin values and number of coins. For example, there could be a currency with 4 coins: a 2 cent, 6 cent, 10 cent and 15 cent coins. How many combinations of this that equal 50 cents are there? The language I'm using is C++, although that doesn't really matter too much. edit: This is a more specific programming question, but how would I analyze a string in C++ to get the coin values? They were given in a text document like 4 2 6 10 15 50 (where the numbers in this case correspond to the example I gave)

    Read the article

  • Combinations and Permutations in F#

    - by Noldorin
    I've recently written the following combinations and permutations functions for an F# project, but I'm quite aware they're far from optimised. /// Rotates a list by one place forward. let rotate lst = List.tail lst @ [List.head lst] /// Gets all rotations of a list. let getRotations lst = let rec getAll lst i = if i = 0 then [] else lst :: (getAll (rotate lst) (i - 1)) getAll lst (List.length lst) /// Gets all permutations (without repetition) of specified length from a list. let rec getPerms n lst = match n, lst with | 0, _ -> seq [[]] | _, [] -> seq [] | k, _ -> lst |> getRotations |> Seq.collect (fun r -> Seq.map ((@) [List.head r]) (getPerms (k - 1) (List.tail r))) /// Gets all permutations (with repetition) of specified length from a list. let rec getPermsWithRep n lst = match n, lst with | 0, _ -> seq [[]] | _, [] -> seq [] | k, _ -> lst |> Seq.collect (fun x -> Seq.map ((@) [x]) (getPermsWithRep (k - 1) lst)) // equivalent: | k, _ -> lst |> getRotations |> Seq.collect (fun r -> List.map ((@) [List.head r]) (getPermsWithRep (k - 1) r)) /// Gets all combinations (without repetition) of specified length from a list. let rec getCombs n lst = match n, lst with | 0, _ -> seq [[]] | _, [] -> seq [] | k, (x :: xs) -> Seq.append (Seq.map ((@) [x]) (getCombs (k - 1) xs)) (getCombs k xs) /// Gets all combinations (with repetition) of specified length from a list. let rec getCombsWithRep n lst = match n, lst with | 0, _ -> seq [[]] | _, [] -> seq [] | k, (x :: xs) -> Seq.append (Seq.map ((@) [x]) (getCombsWithRep (k - 1) lst)) (getCombsWithRep k xs) Does anyone have any suggestions for how these functions (algorithms) can be sped up? I'm particularly interested in how the permutation (with and without repetition) ones can be improved. The business involving rotations of lists doesn't look too efficient to me in retrospect. Update Here's my new implementation for the getPerms function, inspired by Tomas's answer. Unfortunately, it's not really any fast than the existing one. Suggestions? let getPerms n lst = let rec getPermsImpl acc n lst = seq { match n, lst with | k, x :: xs -> if k > 0 then for r in getRotations lst do yield! getPermsImpl (List.head r :: acc) (k - 1) (List.tail r) if k >= 0 then yield! getPermsImpl acc k [] | 0, [] -> yield acc | _, [] -> () } getPermsImpl List.empty n lst

    Read the article

  • All possible combinations of length 8 in a 2d array

    - by CodeJunki
    Hi, I've been trying to solve a problem in combinations. I have a matrix 6X6 i'm trying to find all combinations of length 8 in the matrix. I have to move from neighbor to neighbor form each row,column position and i wrote a recursive program which generates the combination but the problem is it generates a lot of duplicates as well and hence is inefficient. I would like to know how could i eliminate calculating duplicates and save time. int a={{1,2,3,4,5,6}, {8,9,1,2,3,4}, {5,6,7,8,9,1}, {2,3,4,5,6,7}, {8,9,1,2,3,4}, {5,6,7,8,9,1}, } void genSeq(int row,int col,int length,int combi) { if(length==8) { printf("%d\n",combi); return; } combi = (combi * 10) + a[row][col]; if((row-1)>=0) genSeq(row-1,col,length+1,combi); if((col-1)>=0) genSeq(row,col-1,length+1,combi); if((row+1)<6) genSeq(row+1,col,length+1,combi); if((col+1)<6) genSeq(row,col+1,length+1,combi); if((row+1)<6&&(col+1)<6) genSeq(row+1,col+1,length+1,combi); if((row-1)>=0&&(col+1)<6) genSeq(row-1,col+1,length+1,combi); if((row+1)<6&&(row-1)>=0) genSeq(row+1,col-1,length+1,combi); if((row-1)>=0&&(col-1)>=0) genSeq(row-1,col-1,length+1,combi); } I was also thinking of writing a dynamic program basically recursion with memorization. Is it a better choice?? if yes than I'm not clear how to implement it in recursion. Have i really hit a dead end with approach??? Thankyou Edit Eg result 12121212,12121218,12121219,12121211,12121213. the restrictions are that you have to move to your neighbor from any point, you have to start for each position in the matrix i.e each row,col. you can move one step at a time, i.e right, left, up, down and the both diagonal positions. Check the if conditions. i.e if your in (0,0) you can move to either (1,0) or (1,1) or (0,1) i.e three neighbors. if your in (2,2) you can move to eight neighbors. so on...

    Read the article

  • Getting the excluded elements for each of the combn(n,k) combinations

    - by gd047
    Suppose we have generated a matrix A where each column contains one of the combinations of n elements in groups of k. So, its dimensions will be k,choose(n,k). Such a matrix is produced giving the command combn(n,k). What I would like to get is another matrix B with dimensions (n-k),choose(n,k), where each column B[,j] will contain the excluded n-k elements of A[,j]. Here is an example of the way I use tho get table B. Do you think it is a safe method to use? Is there another way? n <- 5 ; k <- 3 (A <- combn(n,k)) (B <- combn(n,n-k)[,choose(n,k):1]) That previous question of mine is part of this problem. Thank you.

    Read the article

  • Enumerating all combinations of lists of different types

    - by jball
    Given two IEnumberables of different types, what is the best practice (considering readability and maintainability) for iterating over both lists to perform an action on all possible combinations? My initial solution was to use nested foreach loops, iterating over the first IEnumerable, and then within that loop, iterating over the second IEnumerable and passing the value from the outer and the current loop into the target method. Eg.: enum ParamOne { First, Second, Etc } List<int> paramTwo = new List<int>() { 1, 2, 3 }; void LoopExample() { foreach (ParamOne alpha in Enum.GetValues(typeof(ParamOne))) { foreach (int beta in paramTwo) { DoSomething(alpha, beta); } } } I tried to restructure it with LINQ, but ended up with something that had no obvious advantages and seemed less intuitive. A search here shows lots of questions about nesting foreachs to iterate over child properties, but I couldn't find anything about iterating over two distinct lists.

    Read the article

  • Algorithm for condensing/consolidating number combinations

    - by user1404383
    Using a horse race betting scenario, say I have a number of separate bets for predicting the first 4 finishers of the race (superfecta). The bets are as follows... 1/2/3/4 1/2/3/5 1/2/4/3 1/2/4/5 1/2/5/3 1/2/5/4 What I want to do is combine or condense these separate combinations as much as possible. For the bets above, they can be all condensed into 1 line... 1/2/3,4,5/3,4,5 What would algorithm look like for this?

    Read the article

  • enumerate all combinations in c++

    - by BCS
    My question is similar to this combinations question but in my case I have N (N 4) small sets (1-2 items per set for now might go to 3 maybe 4) and want to generate each combination of one item from each set. The current solution looks somethinging along the lines of this for(T:: iterator a = setA.begin(); a != setA.end(); ++a) for(T:: iterator b = setB.begin(); b != setB.end(); ++b) for(T:: iterator c = setC.begin(); c != setC.end(); ++c) for(T:: iterator d = setD.begin(); d != setD.end(); ++d) for(T:: iterator e = setE.begin(); e != setE.end(); ++e) something(*a,*b,*c,*d,*e); Simple, effective, probably reasonably efficient, but ugly and not very extensible. Does anyone know of a better/cleaner way to do this?

    Read the article

  • Algorithm for dynamic combinations

    - by sOltan
    My code has a list called INPUTS, that contains a dynamic number of lists, let's call them A, B, C, .. N. These lists contain a dynamic number of Events I would like to call a function with each combination of Events. To illustrate with an example: INPUTS: A(0,1,2), B(0,1), C(0,1,2,3) I need to call my function this many times for each combination (the input count is dynamic, in this example it is three parameter, but it can be more or less) function(A[0],B[0],C[0]) function(A[0],B[1],C[0]) function(A[0],B[0],C[1]) function(A[0],B[1],C[1]) function(A[0],B[0],C[2]) function(A[0],B[1],C[2]) function(A[0],B[0],C[3]) function(A[0],B[1],C[3]) function(A[1],B[0],C[0]) function(A[1],B[1],C[0]) function(A[1],B[0],C[1]) function(A[1],B[1],C[1]) function(A[1],B[0],C[2]) function(A[1],B[1],C[2]) function(A[1],B[0],C[3]) function(A[1],B[1],C[3]) function(A[2],B[0],C[0]) function(A[2],B[1],C[0]) function(A[2],B[0],C[1]) function(A[2],B[1],C[1]) function(A[2],B[0],C[2]) function(A[2],B[1],C[2]) function(A[2],B[0],C[3]) function(A[2],B[1],C[3]) This is what I have thought of so far: My approach so far is to build a list of combinations. The element combination is itself a list of "index" to the input arrays A, B and C. For our example: my list iCOMBINATIONS contains the following iCOMBO lists (0,0,0) (0,1,0) (0,0,1) (0,1,1) (0,0,2) (0,1,2) (0,0,3) (0,1,3) (1,0,0) (1,1,0) (1,0,1) (1,1,1) (1,0,2) (1,1,2) (1,0,3) (1,1,3) (2,0,0) (2,1,0) (2,0,1) (2,1,1) (2,0,2) (2,1,2) (2,0,3) (2,1,3) Then I would do this: foreach( iCOMBO in iCOMBINATIONS) { foreach ( P in INPUTS ) { COMBO.Clear() foreach ( i in iCOMBO ) { COMBO.Add( P[ iCOMBO[i] ] ) } function( COMBO ) --- (instead of passing the events separately) } } But I need to find a way to build the list iCOMBINATIONS for any given number of INPUTS and their events. Any ideas? Is there actually a better algorithm than this? any pseudo code to help me with will be great. C# (or VB) Thank You

    Read the article

  • Python script to calculate aded combinations from a dictionary

    - by dayde
    I am trying to write a script that will take a dictionary of items, each containing properties of values from 0 - 10, and add the various elements to select which combination of items achieve the desired totals. I also need the script to do this, using only items that have the same "slot" in common. For example: item_list = { 'item_1': {'slot': 'top', 'prop_a': 2, 'prop_b': 0, 'prop_c': 2, 'prop_d': 1 }, 'item_2': {'slot': 'top', 'prop_a': 5, 'prop_b': 0, 'prop_c': 1, 'prop_d':-1 }, 'item_3': {'slot': 'top', 'prop_a': 2, 'prop_b': 5, 'prop_c': 2, 'prop_d':-2 }, 'item_4': {'slot': 'mid', 'prop_a': 5, 'prop_b': 5, 'prop_c':-5, 'prop_d': 0 }, 'item_5': {'slot': 'mid', 'prop_a':10, 'prop_b': 0, 'prop_c':-5, 'prop_d': 0 }, 'item_6': {'slot': 'mid', 'prop_a':-5, 'prop_b': 2, 'prop_c': 3, 'prop_d': 5 }, 'item_7': {'slot': 'bot', 'prop_a': 1, 'prop_b': 3, 'prop_c':-4, 'prop_d': 4 }, 'item_8': {'slot': 'bot', 'prop_a': 2, 'prop_b': 2, 'prop_c': 0, 'prop_d': 0 }, 'item_9': {'slot': 'bot', 'prop_a': 3, 'prop_b': 1, 'prop_c': 4, 'prop_d':-4 }, } The script would then need to select which combinations from the "item_list" dict that using 1 item per "slot" that would achieve a desired result when added. For example, if the desired result was: 'prop_a': 3, 'prop_b': 3, 'prop_c': 8, 'prop_d': 0, the script would select 'item_2', 'item_6', and 'item_9', along with any other combination that worked. 'item_2': {'slot': 'top', 'prop_a': 5, 'prop_b': 0, 'prop_c': 1, 'prop_d':-1 } 'item_6': {'slot': 'mid', 'prop_a':-5, 'prop_b': 2, 'prop_c': 3, 'prop_d': 5 } 'item_9': {'slot': 'bot', 'prop_a': 3, 'prop_b': 1, 'prop_c': 4, 'prop_d':-4 } 'total': 'prop_a': 3, 'prop_b': 3, 'prop_c': 8, 'prop_d': 0 Any ideas how to accomplish this? It does not need to be in python, or even a thorough script, but just an explanation on how to do this in theory would be enough for me. I have tried working out looping through every combination, but that seems to very quickly get our of hand and unmanageable. The actual script will need to do this for about 1,000 items using 20 different "slots", each with 8 properties. Thanks for the help!

    Read the article

  • Combinations into pairs

    - by Will
    I'm working on a directed network problem and trying to compute all valid paths between two points. I need a way to look at paths up to 30 "trips" (represented by an [origin, destination] pair) in length. The full route is then composed of a series of these pairs: route = [[start, city2], [city2, city3], [city3, city4], [city4, city5], [city5, city6], [city6, city7], [city7, city8], [city8, stop]] So far my best solution is as follows: def numRoutes(graph, start, stop, minStops, maxStops): routes = [] route = [[start, stop]] if distance(graph, route) != "NO SUCH ROUTE" and len(route) >= minStops and len(route) <= maxStops: routes.append(route) if maxStops >= 2: for city2 in routesFromCity(graph, start): route = [[start, city2],[city2, stop]] if distance(graph, route) != "NO SUCH ROUTE" and len(route) >= minStops and len(route) <= maxStops: routes.append(route) if maxStops >= 3: for city2 in routesFromCity(graph, start): for city3 in routesFromCity(graph, city2): route = [[start, city2], [city2, city3], [city3, stop]] if distance(graph, route) != "NO SUCH ROUTE" and len(route) >= minStops and len(route) <= maxStops: routes.append(route) if maxStops >= 4: for city2 in routesFromCity(graph, start): for city3 in routesFromCity(graph, city2): for city4 in routesFromCity(graph, city3): route = [[start, city2], [city2, city3], [city3, city4], [city4, stop]] if distance(graph, route) != "NO SUCH ROUTE" and len(route) >= minStops and len(route) <= maxStops: routes.append(route) if maxStops >= 5: for city2 in routesFromCity(graph, start): for city3 in routesFromCity(graph, city2): for city4 in routesFromCity(graph, city3): for city5 in routesFromCity(graph, city4): route = [[start, city2], [city2, city3], [city3, city4], [city4, city5], [city5, stop]] if distance(graph, route) != "NO SUCH ROUTE" and len(route) >= minStops and len(route) <= maxStops: routes.append(route) return routes Where numRoutes is fed my network graph where numbers represent distances: [[0, 5, 0, 5, 7], [0, 0, 4, 0, 0], [0, 0, 0, 8, 2], [0, 0, 8, 0, 6], [0, 3, 0, 0, 0]] a start city, an end city and the parameters for the length of the routes. distance checks if a route is viable and routesFromCity returns the attached nodes to each fed in city. I have a feeling there's a far more efficient way to generate all of the routes especially as I move toward many more steps, but I can't seem to get anything else to work.

    Read the article

  • combinations algorithm

    - by mysterious jean
    I want to make simple sorting algorithm. given the input "abcde", I would like the output below. could you tell me the algorithm for that? arr[0] = "a" arr[1] = "ab" arr[2] = "ac" arr[3] = "ad" arr[4] = "ae" arr[5] = "abc" arr[6] = "abd" arr[7] = "abe" ... arr[n] = "abcde" arr[n+1] = "b" arr[n+2] = "bc" arr[n+3] = "bd" arr[n+4] = "be" arr[n+5] = "bcd" arr[n+5] = "bce" arr[n+5] = "bde" ... arr[n+m] = "bcde" ... ...

    Read the article

  • Demantra 7.3.1.3 Controlling MDP_MATRIX Combinations Assigned to Forecasting Tasks Using TargetTaskSize

    - by user702295
    New 7.3.1.3 parameter: TargetTaskSize Old parameter: BranchID  Multiple, deprecated  7.3.1.3 onwards Parameter Location: Parameters > System Parameters > Engine > Proport   Default: 0   Engine Mode: Both   Details: Specifies how many MDP_MATRIX combinations the analytical engine attempts to assign to each forecasting task.  Allocation will be affected by forecsat tree branch size.  TaskTargetSize is automcatically calculated.  It holds the perferred branch size, in number of combinations in the lowest level. This parameter is adjusted to a lower value for smaller schemas, depending on the number of available engines.   - As the forecast is generated the engine goes up the tree using max_fore_level and not top_level -1.  Max_fore_level has     to be less than or equal to top_level -1.  Due to this requirement, combinations falling under the same top level -1     member must be in the same task.  A member of the top level -1 of the forecast tree is known as a branch.  An engine     task is therefore comprised of one or more branches.     - Reveal current task size       go to Engine Administrator --> View --> Branch Information and run the application on your Demantra schema.  This will be deprecated in 7.3.1.3 since there is no longer a means of adjusting the brach size directly.  The focus is now on proper hierarchy / forecast design.     - Control of tasks       The number of tasks created is the lowest of number of branches, as defined by top level -1 members in forecast       tree, and engine sessions and the value of TargetTaskSize.  You are used to using the branch multiplier in this       calculation.  As of 7.3.1.3, the branch ID multiple is deprecated.     - Discovery of current branch size       To resolve this you must review the 2nd highest level in the forecast tree (below highest/highest) as this is the       level which determines the size of the branches.  If a few resulting tasks are too large it is recommended that       the forecast tree level driving branches be revised or at times completely removed from the forecast tree.     - Control of foreacast tree branch size         - Run the following sql to determine how even the branches are being split by the engine:             select count(*),branch_id from mdp_matrix where prediction_status = 1 and do_fore = 1 group by branch_id;             This will give you an understanding if some of the individual branches have an unusually large number of           rows and thus might indicate that the engine is not efficiently dividing up the parallel tasks.         - Based on the results of this sql, we may want to adjust the branch id multiplier and/or the number of engines           (both of these settings are found in the Engine Administrator)           select count(*), level_id from mdp_matrix where prediction_status = 1 and do_fore = 1 group by level_id;           This will give us an understanding at which level of the Forecast tree where the forecast is being generated.            Having a majority of combinations higher on the forecast tree might indicate either a poorly designed forecast           tree and/or engine parameters that are too strict           Based on the results of this we would adjust the Forecast Tree to see if choosing a different hierarchy might           produce a forecast, with more combinations, at a lower level.           For example:             - Review the 2nd highest level in the forecast tree, below highest/highest, as this is the level which               determines the size of the branches.             - If a few resulting tasks are too large it is recommended that the forecast tree level driving branches               be revised or at times completely removed from the forecast tree.               - For example, if the highest level of the forecast tree is set to Brand/All Locations.             - You have 10 brands but 2 of the brands account for 67% and 29% of all combinations.             - There is a distinct possibility that the tasks resulting from these 2 branches will be too large for               a single engine to process.  Some possible solutions could be to remove the Brand level and instead               use a different product grouping which has a more even distribution, possibly Product Group.               - It is also possible to add a location dimension to this forecast tree level, for example Customer.                This will also reduce forecast tree branch size and will deliver a balanced task allocation.             - A correctly configured Forecast Tree is something that is done by the Implementation team and is               not the responsibility of Oracle Support.  Allocation will be affected by forecast tree branch size.  When TargetTaskSize is set to 0, the default value, the system automatically calculates a value for 'TargetTaskSize' depending on the number of engines.   - QUESTION:  Does this mean that if TargetTaskSize is 1, we use tree branch size to allocate branches to tasks instead                of automatically calculating the size?     ANSWER: DEV Strongly recommends that the setting of TargetTaskSize remain at the DEFAULT of ZERO (0).   - How to control the number of engines?     Determine how many CPUs are on the machine(s) that is (are) running the engine.  As mentioned earlier, the general     rule is that you should designate 2 engines per each CPU that is available.  So for example, if you are running the     engine on a machine that has 4 CPU then you can have up to 8 engines designated in the Engine Administrator.  In this     type of architecture then instead of having one 'localhost' in your Engine Settings Screen, you would have 'localhost'     repeated eight times in this field.     Where do I set the number of engines?                 To add multiples computers where engine will run, please do a back-up of Settings.xml file under         Analytical Engines\bin\ folder, then edit it and add there the selected machines.                 Example, this will allow 3 engines to start:         - <Entry>           <Key argument="ComputerNames" />           <Value type="string" argument="localhost,localhost,localhost" />           </Entry Otherwise, if there are no additional engines defined, the calculated value of 'TargetTaskSize' is used. (Oracle does not recommend changing the default value.) The TargetTaskSize holds the engines prefered branch size, in number of level 1 combinations.   - Level 1 combinations, known as group size The engine manager will use this parameter to attempt creating branches with similar size.   * The engine manager will not create engines that do not have a branch. The engine divider algorithm uses the value of 'TargetTaskSize' as a system-preferred branch size to create branches that are more equal in size which improves engine performance.  The engine divider will try to add as many tasks as possible to an existing branch, up to the limit of 'TargetTaskSize' level 1 combinations, before adding new branches. Coming up next: - The engine divider - Group size - Level 1 combinations - MAX_FORE_LEVEL - Engine Parameters  

    Read the article

  • A Combinations of Items in Given List

    - by mecablaze
    Hello stackoverflow, I'm currently in Python land. This is what I need to do. I have already looked into the itertools library but it seems to only do permutations. I want to take an input list, like ['yahoo', 'wikipedia', 'freebase'] and generate every unique combination of one item with zero or more other items... ['yahoo', 'wikipedia', 'freebase'] ['yahoo', 'wikipedia'] ['yahoo', 'freebase'] ['wikipedia', 'freebase'] ['yahoo'] ['freebase'] ['wikipedia'] A few notes. Order does not matter and I am trying to design the method to take a list of any size. Also, is there a name for this kind of combination? Thanks for your help!

    Read the article

  • How to map combinations of things to a relational database?

    - by Space_C0wb0y
    I have a table whose records represent certain objects. For the sake of simplicity I am going to assume that the table only has one row, and that is the unique ObjectId. Now I need a way to store combinations of objects from that table. The combinations have to be unique, but can be of arbitrary length. For example, if I have the ObjectIds 1,2,3,4 I want to store the following combinations: {1,2}, {1,3,4}, {2,4}, {1,2,3,4} The ordering is not necessary. My current implementation is to have a table Combinations that maps ObjectIds to CombinationIds. So every combination receives a unique Id: ObjectId | CombinationId ------------------------ 1 | 1 2 | 1 1 | 2 3 | 2 4 | 2 This is the mapping for the first two combinations of the example above. The problem is, that the query for finding the CombinationId of a specific Combination seems to be very complex. The two main usage scenarios for this table will be to iterate over all combinations, and the retrieve a specific combination. The table will be created once and never be updated. I am using SQLite through JDBC. Is there any simpler way or a best practice to implement such a mapping?

    Read the article

  • Fair 2-combinations

    - by Tometzky
    I need to fairly assign 2 experts from x experts (x is rather small - less than 50) for every n applications, so that: each expert has the same number of applications (+-1); each pair of experts (2-combination of x) has the same number of applications (+-1); It is simple to generate all 2-combinations: for (i=0; i<n; i++) { for (j=i+1; j<n; j++) { combinations.append(tuple(i,j)); } } But to assign experts fairly I need to assign a combination to an application i correct order, for example: experts: 0 1 2 3 4 fair combinations: counts 01234 01 11000 23 11110 04 21111 12 22211 34 22222 02 32322 13 33332 14 34333 03 44343 24 44444 I'm unable to come up with a good algorithm for this (the best I came up with is rather complicated and with O(x4) complexity). Could you help me?

    Read the article

  • Character equipment combinations

    - by JimFing
    I'm developing a 2d isometric game (typical Tolkien RPG) and wondering how to handle character/equipment combinations. So for example, the player wears leather boots with chain-mail and a wooden shield and a sword - but then picks up plate-armour instead of chain-mail. I'm using Blender3D to create objects, environments and characters in 3D, then a script runs to render all 3D meshes into 2D orthographic tile maps. So I can use this script to create all the combinations of character equipment for me, but there would be an explosion in terms of the combinations required.

    Read the article

  • Enumerating combinations in a distributed manner

    - by Reyzooti
    I have a problem where I must analyse 500C5 combinations (255244687600) of something. Distributing it over a 10 node cluster where each cluster processes roughly 10^6 combinations per second means the job will be complete in about 7hours. The problem I have is distributing the 255244687600 combinations over the 10 nodes. I'd like to present each node with 25524468760, however the algorithms I'm using can only produce the combinations sequentially, I'd like to be able to pass the set of elements and a range of combination indicies eg: [0-10^7) or [10^7,2.0 10^7) etc and have the nodes themselves figure out the combinations. The algorithms I'm using at the moment are from the following: http://home.roadrunner.com/~hinnant/combinations.html A logical question I've considered using a master node, that enumerates each of the combinations and sends work to each of the nodes, however the overhead incurred in iterating the combinations from a single node and communicating back and forth work is enormous, and will subsequently lead to the master node becoming the bottleneck. Are there any good combination iterating algorithms geared up for efficient/optimal distributed enumeration?

    Read the article

  • Can't disable Alt + mouse buttons combinations

    - by Andrey
    I've already searched through the questions, and didn't find the same question as I want to ask. I'm working in blender and there are some combinations that I am used to and remapping them in blender would be the last resort, not the first. I have tried to disable Alt+LMB and Alt+RMB actions in ccsm, I've tried to do this in dconf or gconf editors as well, but nothing helped. As soon as I close the editors or get back to the main screen of ccsm, these combinations are enabled again. So, for example, instead of selecting an edge loop in blender with Alt+RMB, I get this goddamn menu offering me to move the window to another workspace, etc. I really don't need this function, so I'd rather switch it off instead of remapping the hotkeys I'm used to in blender.

    Read the article

  • What are the common Control combinations in a terminal setting

    - by Hamish Downer
    I would like to have a good guide to the common Control key combinations in use in bash (and similar) shells and the combinations used by common programs in use in those shells. My particular motivation is to be able to run GNU screen on one computer, ssh to a second computer and use screen and irssi on that computer. So I need to use something other than Ctrl-A to control one of the screen sessions. So I need to know what are Control key combinations are safe to use. But I imagine this list would be useful for others who want to bind custom actions to Control key combinations. I reckon we'd be best to group the Control key combinations by application (eg. bash itself, screen, vim, emacs), to make it easy to spot the applications you use or can ignore. So please one application per answer - hope that works.

    Read the article

  • Keybindings for individual letter keys (not modifier-combinations) on a GtkTextView widget (Gtk3 and PyGI)

    - by monotasker
    I've been able to set several keybord shortcuts for a GtkTextView and a GtkTextEntry using the new css provider system. I'm finding, though, that I only seem to be able to establish keybindings for combinations including a modifier key. The widget doesn't respond to any bindings I set up that use: the delete key the escape key individual letter or punctuation keys alone Here's the code where I set up the css provider for the keybindings: #set up style context keys = Gtk.CssProvider() keys.load_from_path(os.path.join(data_path, 'keybindings.css')) #set up style contexts and css providers widgets = {'window': self.window, 'vbox': self.vbox, 'toolbar': self.toolbar, 'search_entry': self.search_entry, 'paned': self.paned, 'notelist_treeview': self.notelist_treeview, 'notelist_window': self.notelist_window, 'notetext_window': self.notetext_window, 'editor': self.editor, 'statusbar': self.statusbar } for l, w in widgets.iteritems(): w.get_style_context().add_provider(keys, Gtk.STYLE_PROVIDER_PRIORITY_USER) Then in keybindings.css this is an example of what works: @binding-set gtk-vi-text-view { bind "<ctrl>b" { "move-cursor" (display-lines, -5, 0) }; /* 5 lines up */ bind "<ctrl>k" { "move-cursor" (display-lines, -1, 0) }; /* down */ bind "<ctrl>j" { "move-cursor" (display-lines, 1, 0) }; /* up */ } Part of what I'm trying to do is just add proper delete-key function to the text widgets (right now the delete key does nothing at all). So if I add a binding like one of these, nothing happens: bind "Delete" { "delete-selection" () }; bind "Delete" { "delete-from-cursor" (chars, 1) }; The other part of what I want to do is more elaborate. I want to set up something like Vim's command and visual modes. So at the moment I'm just playing around with (a) setting the widget to editable=false by hitting the esc key; and (b) using homerow letters to move the cursor (as a proof-of-concept exercise). So far there's no response from the escape key or from the letter keys, even though the bindings work when I apply them to modifier-key combinations. For example, I do this in the css for the text-widget: bind "j" { "move-cursor" (display-lines, 1, 0) }; /* down */ bind "k" { "move-cursor" (display-lines, -1, 0) }; /* up */ bind "l" { "move-cursor" (logical-positions, 1, 0) }; /* right */ bind "h" { "move-cursor" (logical-positions, -1, 0) }; /* left */ but none of these bindings does anything, even if other bindings in the same set are respected. What's especially odd is that the vim-like movement bindings above are respected when I attach them to a GtkTreeView widget for navigating the tree-view options: @binding-set gtk-vi-tree-view { bind "j" { "move-cursor" (display-lines, 1) }; /* selection down */ bind "k" { "move-cursor" (display-lines, -1) }; /* selection up */ } So it seems like there are limitations or overrides of some kind on keybindings for the TextView widget (and for the del key?), but I can't find documentation of anything like that. Are these just things that can't be done with the css providers? If so, what are my alternatives for non-modified keybindings? Thanks.

    Read the article

  • What are the Ruby equivalent of Python itertools, esp. combinations/permutations/groupby?

    - by Amadeus
    Python's itertools module provides a lots of goodies with respect to processing an iterable/iterator by use of generators. For example, permutations(range(3)) --> 012 021 102 120 201 210 combinations('ABCD', 2) --> AB AC AD BC BD CD [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D What are the equivalent in Ruby? By equivalent, I mean fast and memory efficient (Python's itertools module is written in C).

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >