discrete-mathematics

PHP take all combinations

不羁的心 提交于 2019-12-17 09:51:15
问题 I saw this algorithm that will take numbers or words and find all possible combinations And I'm using it, but it does NOT return all "real" combinations. PHP: <?php require_once 'Math/Combinatorics.php'; $words = array('cat', 'dog', 'fish'); $combinatorics = new Math_Combinatorics; foreach($combinatorics->permutations($words, 2) as $p) { echo join(' ', $p), "\n"; } ?> And it returns: cat dog dog cat cat fish fish cat dog fish fish dog But these are not all real combinations, all real

How do I return an integer array the sum of which equals to a given number in php? [closed]

♀尐吖头ヾ 提交于 2019-12-13 23:24:06
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . Input: any number in 1-15 or 64-79 range which is a sum of either (1, 2, 4, 8, 64) in any combination Output: an array of integers from this list: ( 1, 2, 4, 8, 64 ) the sum of which equals the input number. e.g. input 72 , output array(8, 64) input 13 , output array(1, 4, 8) 回答1:

For binomial function nCr=k, given r and k find n

本秂侑毒 提交于 2019-12-13 10:00:30
问题 I need a function that can solve the following: for a binomial function nCr=k, given r and k find n. in mathematics nCr=n!/r!(n-r)! I tried following but it doesn't solve it. for example 8C6=28, for my function the inputs are 6 and 28 and i want to find 8. This may not have exact integer number so I want to find an x>=n. """I am approaching it this way, i.e. find the solution of a polynomial function iteratively, hope there is a better way""" def find_n(r,k): #solve_for_n_in(n*(n-1)...(n-r)

Algorithm to compute set of bins bounded by a discrete contour

北战南征 提交于 2019-12-13 05:24:50
问题 On a discrete grid-based plane (think: pixels of an image), I have a closed contour that can be expressed either by: a set of 2D points (x1,y1);(x2,y2);(x3,y3);... or a 4-connected Freeman code, with a starting point: (x1,y1) + 00001112... I know how to switch from one to the other of these representations. This will be the input data. I want to get the set of grid coordinates that are bounded by the contour. Consider this example, where the red coordinates are the contour, and the gray one

Choose r outcomes from n possibilities efficiently in Pandas

狂风中的少年 提交于 2019-12-13 00:30:29
问题 I have a 50 years data. I need to choose the combination of 30 years out of it such that the values corresponding to them reach a particular threshold value but the possible number of combination for 50C30 is coming out to be 47129212243960 . How to calculate it efficiently? Prs_100 Yrs 2012 425.189729 2013 256.382494 2014 363.309507 2015 578.728535 2016 309.311562 2017 476.388839 2018 441.479570 2019 342.267756 2020 388.133403 2021 405.007245 2022 316.108551 2023 392.193322 2024 296.545395

P versus NP Clarification

倖福魔咒の 提交于 2019-12-12 10:42:10
问题 Quoted from wikipedia, the P vs NP problem, regarding the time complexity of algorithms "... asks whether every problem whose solution can be quickly verified by a computer can also be quickly solved by a computer." I am hoping that somebody can clarify what the difference between "verifying the problem" and "solving the problem" is here. 回答1: I am hoping that somebody can clarify what the difference between "verifying the problem" and "solving the problem" is here. It's not "verifying the

Uses of Ackermann function?

和自甴很熟 提交于 2019-12-12 07:52:23
问题 In our discrete mathematics course in my university, the teacher shows his students the Ackermann function and assign the student to develop the function on paper. Beside being a benchmark for recursion optimisation, does the Ackermann function has any real uses ? 回答1: Yes. The (inverse) Ackermann function appears in complexity analysis of algorithms. When it does, it means you can almost ignore that term since it grows so slowly (a lot like log(log ... log(n)...)) i.e. lg*(n). For example:

How do I write a recursive function for a combination

不羁的心 提交于 2019-12-12 07:38:44
问题 I am going over recursive functions and i understand how to write basic ones, but I have a question on my study guide that I dont understand. . Write code for a recursive function named Combinations that computes nCr. Assume that nCr can be computed as follows: nCr = 1 if r = 0 or if r = n and nCr = (n-1)C(r-1) + (n-1)Cr Can someone please help me through this or explain in layman's terms? Thank you! 回答1: The question really has all the information. It tells you how to compute nCr - and that

Combinatorics in excel: Find every possible sum of every possible combination

情到浓时终转凉″ 提交于 2019-12-12 06:59:46
问题 Ok, I´ve found similar questions but none of them solve this problem so here I go: I´ve a list of individuals (col. "A"), and each of them has a value assigned for a determined parameter (col. "B"). I´ve some target parameter values and I want to know which combinations of individuals sum up "x" for that parameter value. Let´s take an example: Col. A Col. B M 10 N -5 O -8 P 0.87 Q 9 - Target for Parameter("X"): 9-10 - Solution: S1= Q+P -> 9.87 S2= Q -> 9 As you can see just by inspection, the

Generate all permutations of several lists in Java

▼魔方 西西 提交于 2019-12-12 01:49:06
问题 I have n lists, for example: L_1 = [a_11, a_12, ...] L_2 = [a_21, a_22, ...] ... L_n = [a_n1, a_n2, ...] where i th list has k_i elements. And now, I want to generate all n -elements list, where i th element is from L_i , I mean: [a_11, a_21, ..., a_n1] [a_11, a_21, ..., a_n2] ... [a_11, a_22, ..., a_n1] [a_11, a_22, ..., a_n2] ... [a_12, a_21, ..., a_n1] [a_12, a_21, ..., a_n2] ... [a_12, a_22, ..., a_n1] [a_12, a_22, ..., a_n2] ... The total number of lists shoulbe be equal to k_1*k_2*...k