[Problem] Weather on consecutive holidays (Ruby edition)

[Problem] Solve the weather for consecutive holidays (Ruby edition)

Q

You had seven consecutive holidays, but decided to go out if the probability of precipitation was less than 30%.

Since the probability of precipitation (%) for 7 days is entered separated by line breaks, please output the total number of days to go out.

Example

13 0 15 31 89 100 30 If given 4 Please create a program that outputs.

Value to be entered

The input is given in the following format.

t_1 t_2 t_3 t_4 t_5 t_6 t_7

Expected output

Since the probability of precipitation for 7 days is entered separated by line breaks, please output the total number of days to go out.

My answer

python


t_1 = gets.chomp.to_i
t_2 = gets.chomp.to_i
t_3 = gets.chomp.to_i
t_4 = gets.chomp.to_i
t_5 = gets.chomp.to_i
t_6 = gets.chomp.to_i
t_7 = gets.chomp.to_i
int = t_1, t_2, t_3, t_4, t_5, t_6, t_7 
str = int.select do |i|
    i <= 30
end
print str.size

Commentary

This time, the numbers from t_1 to t_7 are stored in the array with int =. By doing this, you can use the select method </ font> that can retrieve a specific value from the array. So if you print str with print, you will get [13,0,15,30] </ font>. This time it is a problem to output the number, so I output the number of values with the size method.

that's all!

Recommended Posts