[RAILS] Minimum value (ruby edition)

Find the smallest value in Ruby

Value to be entered

n_1 n_2 n_3 n_4 n_5

Expected output

Outputs the smallest number among n_1, n_2, n_3, n_4, n_5


The following conditions are met in all test cases. ・ 1 ≤ n_1, n_2, n_3, n_4, n_5 ≤ 100

Input example 1

10 12 4 8 46

Output example 1




n_1 = gets.to_i
n_2 = gets.to_i
n_3 = gets.to_i
n_4 = gets.to_i
n_5 = gets.to_i

result = [n_1, n_2, n_3, n_4, n_5 ]
puts result.min

Output result



Substitute input examples 10 to 46 into variables n_1 to n_5 using gets.to_i

Next, put the numerical values from n_1 to n_5 into the array and assign it to the variable called result.

Finally, puts outputs the result, but since we want to find only the minimum number, we output it using min.

The maximum value can be output by setting min to max.

If you want to output only n_3, you can output the value of n_3 by setting puts result [2].

that's all

Recommended Posts

Minimum value (ruby edition)
Pedometer (Ruby edition)
Safe numbers (ruby edition)
Q. Elevator (Ruby edition)
ruby memorandum (basic edition)
Offline environment construction Ruby edition
Ruby memorandum (acquisition of key value)
Dharma doll drop of characters (ruby edition)
Ruby on Rails installation method [Mac edition]
Ruby methods return the last evaluated value
[Problem] Weather on consecutive holidays (Ruby edition)