Get round number from rand [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 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

Related

Calculate % of number in Scala programming [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 11 months ago.
Improve this question
How to do 50% of 120 in scala code..need proper syntax ,& runnable code for same.
Eg :
int k = (int)(120*(50.0f/100.0f));
This is in java need scala code for same.
The answer would be:
(120*(50.0f/100.0f)).toInt

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

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

How to use an upto method in ruby to count up by 100? [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 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)}

Resources