combinations

Just in time computation of combinations [duplicate]

泪湿孤枕 提交于 2019-12-11 12:19:18
问题 This question already has answers here : System.OutOfMemoryException when generating permutations (4 answers) Closed 3 years ago . I want to do something with every combination of ternaries for N variables: example with 1: T F U example with 2: TT FT UT TF FF UF UU Is there a way to compute this but only as needed: For example: var combinator = new Combinator<string>(2, {"T","F","U"}); List<String> tt = combinator.Next(); //tt contains {"T","T"} 回答1: You can implement it in an iterator method

Redshift create all the combinations of any length for the values in one column

好久不见. 提交于 2019-12-11 12:06:04
问题 How can we create all the combinations of any length for the values in one column and return the distinct count of another column for that combination? Table: +------+--------+ | Type | Name | +------+--------+ | A | Tom | | A | Ben | | B | Ben | | B | Justin | | C | Ben | +------+--------+ Output Table: +-------------+-------+ | Combination | Count | +-------------+-------+ | A | 2 | | B | 2 | | C | 1 | | AB | 3 | | BC | 2 | | AC | 2 | | ABC | 3 | +-------------+-------+ When the combination

List all combination possible in a php array of boolean value in PHP

為{幸葍}努か 提交于 2019-12-11 11:59:49
问题 I will try to better explain my needs. I need to generate from scrach, a multidirectional array who contain many array. The inner array must be array containing 7 boolean value. I need to have all the combinaisons possible of 7 boolean values. With 7 cases, it make 128 inner arrays. Here an example of output I need, for making it easy to understand : $sequence = array( array(true, true, true, true, true, true, true), array(true, true, true, true, true, true, false), array(true, true, true,

Create different combination / patterns between the data of two columns of a csv file by python

南楼画角 提交于 2019-12-11 11:47:09
问题 I have a .csv file that contain 5 columns, a_id, b_id, var, lo, up. I would like to create different combinations / patterns between two variables based on a_id, b_id, and var. In addition, at first I would like to delete the records that have no duplicate based on a_id, b_id, because if there is no duplicate, so combination or matching would not be created. As a result, in the dataFile.csv, first record is deleted, because it has no duplicate. For the combination / pattern between two

Generate a truth table of arbitrary length haskell

懵懂的女人 提交于 2019-12-11 11:29:11
问题 for an assignment I have to generate a truth table like this: combinations :: Int -> [[Bool]] combinations 3 should output: [[False, False, False],[False, False, True],[False, True, False],[False, True, True][True, False, False][True, False, True],[True, True, False],[True, True, True]] I can do a list comprehension: combinations n = [[a,b] | a<-[True, False], b <-[True, False]] but that doesn't scale for arbitrary numbers. Could you please give me a hint? 回答1: Adding to @chi 's answer, here

Generating k-combinations lexicographically

随声附和 提交于 2019-12-11 10:46:23
问题 I'm not aware nor could I find an algorithm to generate combinations of k items (i.e. k-subsets) lexicographically. I do know algorithms to generate combinations of n choose k, but they don't generate the k-subsets lexicographically. Can somebody help me out with this or point me in the right direction? 回答1: The following algorithm will generate all combinations of elements of a set: procedure all_combinations(S) if length(S) == 0 return {} else all_comb = {} x = first element of S Sx = S-{x}

Combinations using memoization in java

好久不见. 提交于 2019-12-11 10:15:24
问题 I'm making a program that calculates a combination given two numbers, ex: java Combination 5 3 would give an answer of 10. I have a method that looks like this: public static int choose(int n, int k) { // chooses k elements out of n total if (n == 0 && k > 0) return 0; else if (k == 0 && n >= 0) return 1; else return choose(n - 1, k - 1) + choose(n - 1, k); How would I be able to use memoization for this in order to make it calculate faster with larger numbers? 回答1: You might be better off

How to grep query all files for two strings

萝らか妹 提交于 2019-12-11 10:10:05
问题 Here we go: I need to query php files which both have a TODO statement as well as my name . Both strings could be anywhere in the document (ie. line) and be positioned anywhere on 0-infinite lines (position 0-n). How to grep query for my name: find -name '*.php' -exec grep -in "fincken" {} + output: ./some/file.php:51: ramon fincken ./somefile.php:2: rfincken How to grep query for the TODOs find -name '*.php' -exec grep -n "TODO" {} + output: ./some/file.php:53: // TODO: foobar! ./some

How To Find All Possible Permutations From A Bag under apache pig

三世轮回 提交于 2019-12-11 09:59:52
问题 i'm trying to find all combinations possible using apache pig, i was able to generate permutation but i want to eliminate the replication of values i write this code : A = LOAD 'data' AS f1:chararray; DUMP A; ('A') ('B') ('C') B = FOREACH A GENERATE $0 AS v1; C = FOREACH A GENERATE $0 AS v2; D = CROSS B, C; And the result i obtained is like : DUMP D; ('A', 'A') ('A', 'B') ('A', 'C') ('B', 'A') ('B', 'B') ('B', 'C') ('C', 'A') ('C', 'B') ('C', 'C') but what i'm trying to obtain the result is

Creating all combinations of a set and running out of memory

元气小坏坏 提交于 2019-12-11 09:43:06
问题 I need to generate every combination of 6 numbers from a set of 55. I believe there are 28,989,675 indexes in that set of combinations. I guess I'm running out of memory, because I can generate combinations with 4 numbers but nothing larger than that. How can I fix this problem? I'm using a modification of some code I borrowed from a tutorial here: https://www.youtube.com/watch?v=VyXDQxuIwPU import itertools text_file = open("comb3.txt", "w") harmonics = [28, 33, 36, 38, 40, 43, 45, 47, 48,