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)
Related
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"]]
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
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])
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 9 years ago.
Improve this question
Say, for example, Σ={x,y}.
And you carried out the operation Σ*-x. What would be the resulting language? Would it essentially be y* or would it just minus one occurrence of x in all strings generated in Σ*?
i.e xxyyxx to xyyxx.
It would be the language of all strings generated by Σ* minus the string x. (so: xx, epsilon, xyx, y, etc... but not x)
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 9 years ago.
Improve this question
I need to make a program that counts down from 10, displays a message, and then immediately after starts counting from 100 metres to 200 metres, and so on up to 100,000 metres. I can't figure out how to do the last part. This is the code I have so far.
10.downto(1) do|counter|
puts counter
sleep 1
end
puts "Blast off!"
If you mean in increments of 100, try this:
100.step(100_000, 100) {|c| puts c; sleep(0.5)}