discrete-mathematics

PHP Possible combinations 3 arrays of 2 values [duplicate]

谁都会走 提交于 2021-02-19 07:41:40
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: PHP take all combinations I'm thinking of making something in PHP that will show me all combinations of license plates. For example: You have 3 boxes you can fill in max 2 values Like BOX1 BOX2 BOX3 75 PM M5 7S PH MS Z5 PN H5 ZS RM HS 25 RH N5 2S RN NS NOT BOX1+BOX1+BOX1 It needs to show me ex. 75-PM-M5 ex. 75-PH-MS ex. 75-PN-MS ex. 75-PM-H5 ex. 75-PH-H5 ex. 75-PN-H5 So, BOX1+BOX2+BOX3 The PHP script needs to

Find combinations of size r from a set with decreasing sum value

家住魔仙堡 提交于 2021-02-10 14:44:33
问题 I have a set of numbers eg. [100,90,80,70,60,50] and want to find all combinations of size r=3 but in order of decreasing sum. Arranging the numbers in decreasing order does not work eg. (100, 90, 80) 270 (100, 90, 70) 260 (100, 90, 60) 250 (100, 90, 50) **240** (100, 80, 70) **250** (100, 80, 60) 240 How can i go about finding such a combination set with decreasing sum value. 回答1: Here' the Code import itertools array = [100,90,80,70,60,50] size = 3 answer = [] # to store all combination

Arrays vs. lists in Lisp: Why are lists so much faster in the code below?

自古美人都是妖i 提交于 2021-01-27 05:50:50
问题 I got an unexpected result while solving Problem 75 in Project Euler. My code does find the correct solution, but it behaves strangely. My solution consists of traversing a Pythagorean tree (Barning's matrices) until the perimeter limit is reached, counting the numbers of times the perimeter assumed each value, and, lastly, counting the perimeter lengths that occurred only once. My admittedly untidy but functioning code is: (defparameter *barning-matrixes* '(#(1 -2 2) #(2 -1 2) #(2 -2 3) #(1

Arrays vs. lists in Lisp: Why are lists so much faster in the code below?

强颜欢笑 提交于 2021-01-27 05:49:46
问题 I got an unexpected result while solving Problem 75 in Project Euler. My code does find the correct solution, but it behaves strangely. My solution consists of traversing a Pythagorean tree (Barning's matrices) until the perimeter limit is reached, counting the numbers of times the perimeter assumed each value, and, lastly, counting the perimeter lengths that occurred only once. My admittedly untidy but functioning code is: (defparameter *barning-matrixes* '(#(1 -2 2) #(2 -1 2) #(2 -2 3) #(1

Is there a way to get “groups of combinations” of lists that don't overlap, and is exhaustive, using itertools on Python?

心不动则不痛 提交于 2020-08-26 08:27:24
问题 Here's what I mean: if you found all possible 2-element combinations of [1,2,3,4], you would get [1,2], [1,3],[1,4],[2,3],[2,4] and [3,4] What I want is groups of combinations that don't overlap and include all elements. So for example [[1,2],[3,4]] is an example of one "group", because the elements in both combinations do not overlap, and all possible elements are used. [[1,3],[2,4]] is an example of another "group" By the way, I'm aware that itertools will allow me to print combinations

Optimization problem - finding a maximum

别来无恙 提交于 2020-01-13 03:37:48
问题 I have a problem at hand which can be reduced to something like this : Assume a bunch of random points in a two-dimension plane X-Y where for each Y, there could be multiple points on X and for each X, there could be multiple points on Y. Whenever a point (Xi,Yi) is chosen, no other point with X = Xi OR Y = Yi can be chosen. We have to choose the maximum number of points. 回答1: This can be reduced to simple maximum flow problem. If you have a point (xi, yi), in graph it should be represented

Equations Equality test (in C++ or with Unix tools) (algebra functions isomorphism) [closed]

大憨熊 提交于 2020-01-02 03:34:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am looking for C++ open-source library (or just open-source Unix tool) to do: Equality test on Equations . Equations can be build during runtime as AST Trees, string or other format. Equations will mostly be simple algebra ones, with some assumptions about unknown functions. Domain, will be integer arithmetic

If g(n) = sqrt(n)^sqrt(n), does the complexity of g(n) = O(2^n)?

浪尽此生 提交于 2020-01-02 03:26:08
问题 If g(n) = sqrt(n) sqrt(n) , does the complexity of g(n) = O(2 n )? Any help is appreciated. 回答1: A useful technique when comparing two exponential functions is to get them to have the same base: √n √n = (2 lg √n ) √n = 2 √n lg √n Now you're comparing 2 √n lg √n against 2 n , and hopefully from that it's easy to see that the former function does not grow as rapidly as the latter, so √n √n = O(2 n ) is indeed true. 回答2: The other proofs are short and nice, but here is more detailed proof going