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

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"]]

Related

Ruby count of the most frequent number in big integer [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 1 year ago.
Improve this question
I have big number for example 123456782345673455676767878
And i need to find the amount of the most frequent number in this big integer
num = num.digits # turn num into an array of digits [1, 2, ...]
num.tally.max_by { |digit, count| count }[0]
Note: solution only works on ruby 2.7+ (when tally method was added)

how to determine if there are numbers can be add up to 10 in a 4x4 grid? [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 4 years ago.
Improve this question
At the beginning, generating a 4x4 grid like the first grid
Notice that all numbers are less than 6.
Player can add more than 2 numbers together to get number 10 (those numbers must be neighbours of each other)
if the number is greater than 10, it only can be add up with itself, like 10+10=20, 20+20=40...160+160=320
How can I determine that the adding all the numbers does not sum up to 10, shown as the 2nd grid (even the 6+4=10 but they are not neighbor)?

Get round number from rand [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 5 years ago.
Improve this question
How I can get always round number from Ruby rand method between the interval rand(1..99999999).
For Example I want to get as a result for example 1000 or 100000
Randomize the power of 10:
10 ** rand(1..9)
Why not this:
('1' + '0' * (0..10).sample).to_i

Ruby: Finding duplicate array elements in two dimentional array [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 8 years ago.
Improve this question
I have this array:
a= [[1,2],[3,4],[1,2],[2,3],[2,3]]
How can I make user to enter an array element ex:[1,2] and it should take that element and return the number of times it is found in the array.
You have your array a and the user input (i1 and i2), all you have to do is:
a.count([i1, i2])

Come up with an algorithm [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 8 years ago.
Improve this question
Using only five 3s and valid mathematical operations, how to get answer 31? Only digit 3 should be there and you can use 5 times (no more or less) to get the answer.
Would this work?
33 - 3 + 3/3
You can get to 31 with…
(3**3+(3/3))+3

Resources