Get the mode of a matrix [closed] - algorithm

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a matrix that is 300x50 big filled with integers. I want to find what number appears the most in that 300x50 matrix and have it returned as an integer.

Just use mode on the linearized matrix:
mode(matrix(:))
Example:
>> matrix = [3 2 3; 2 2 1]
matrix =
3 2 3
2 2 1
>> mode(matrix(:))
ans =
2

Related

How to print random numbers from 2 given arrays without repeating if already printed on ruby [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
lets suppose
al=['Al','2l','3l','4l','5l','6l','7l','8l','9l','jl','ql','kl']
af=['Af','2f','3f','4f','5f','6f','7f','8f','9f','jf','qf','kf']
ak=['Ak','2k','3k','4k','5k','6k','7k','8k','9k','jk','qk','kk']
an=['An','2n','3n','4n','5n','6n','7n','8n','9n','jn','qn','kn']
are array
let's suppose
there a two-person wait for random numbers to get
but they should not get the same word ( 3 outputs should be to 2 people from 4 arrays without repeating
)
Use Array#sample and then Enumerable#each_slice:
persons, cards = 2, 3
(al + af + ak + an).sample(persons * cards).each_slice(cards).to_a
#⇒  [["qk", "4l", "Ak"], ["6l", "8l", "5l"]]

Best way to solve a first degree equation with multiple variables [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
I would like to solve a first degree equation with multiple variables (not a system of equations) like :
10x + 5y + 7z = 630
Is there any way to solve it without using bruteforce?
Solutions must be integers.
Regroup the first two terms as 10x+5y = 5(2x+y) = 5t.
Then t/7 + z/5 = 18.
As 5 and 7 are relative primes, t = 7k and z = 5(18-k), where k is abritrary.
Finally, y = t - 2x = 7k - 2x, where x is arbitrary.
As we can check,
10 x + 5 (7k - 2x) + 7 5 (18-k) = 630.
No you can't, you have an infinity of solutions in this case.
To solve such problem you shoud have a system with at least the same number of equations as the number of variables.
Another trick, in some cases you could solve it as an underdetermined system.

Gamma distribution [closed]

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 5 years ago.
Improve this question
Let X~gamma(2,1).
Find:
P(X>=2)
(X<=10)
I'm struggling to determine how to solve this. I know you must integrate some function from 2 to infinity and 0 to 10 but don't know what to integrate.
There are actually two ways to define Gamma-distribution - one with scaling 'theta' and another with inverse scale 'beta', see https://en.wikipedia.org/wiki/Gamma_distribution
Fortunately, for parameter value of 1 there is no difference.
So you have to integrate PDF
f(x) = (1/G(2)) * x * exp(-x)
Gamma function at 2 is equal to 1. G(2)=1, so
P(x) = S x exp(-x) dx
where S is integration notation.
P(x) = -(x+1)*exp(-x)
So now you have to substitute limits

Calculating summations [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
Link to question
I am struggling so answer the following question. I think the reason I am not doing it correctly is because i starts at 0 rather than 1, but I am not sure how to do it.
The sum is equivalent to 3(n+1) + sum_{i=1}^n 2i, which is 3(n+1) + 2*n*(n+1)/2 = 3(n+1) + n(n+1) = (n+3)(n+1).
The result is thus (n+3)(n+1). The whole derivation is here.

The largest tile in the 2048, groups of 3 variant? [moved to SE.Math] [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
Question moved to: https://math.stackexchange.com/questions/1391780/the-largest-tile-with-2048-with-groups-of-3
A sentence to use up characters.
Dropping 3 and 6 doesn't create the same type of game. It would need to be 3 and 9 (3*3). Or you end up with two completely separate sets to merge, one with base 3 the other with base 6 (2*3).
In case you drop 3 and 9 then any 3^(2^min_moves) would be an acceptable objective just like 2048 = 2^16 = 2^(2^4)
EDIT:
Looks like I missed the part about merging 3 elements. That may need to have 3 and 27 (3^3) drop in. Also the objective would end up being 3^(3^min_moves) as merging 3 tiles is a move

Resources