+ 2

SL´s challenges with multiple inputs

How am I supposed to handle Sololearn´s Code Coach challenges that send you multiple inputs each one in a new line? I´m trying it on Ruby. I have tried to split and map it, but it only gets the first input str = gets.split("/n").map { |x| x } print str OUTPUT: ["1"] I used "print" instead of "puts" to see the whole content, but it is not helping me. More specifically, I am trying to solve "That´s odd" https://code.sololearn.com/cu7aF3iCg86g/?ref=app

17th Jan 2020, 7:29 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
4 Answers
+ 2
If the input spans, say, two lines, and "gets" reads in one line until it encounters a newline seperator, what prevents you from using "gets" twice and storing the result of each call in a different variable?
17th Jan 2020, 8:59 AM
Shadow
Shadow - avatar
+ 9
for this challenge you can also solve the input this way: arr = [] for n in (0..gets.to_i)      arr << gets.to_i end
17th Jan 2020, 12:13 PM
Danijel Ivanović
Danijel Ivanović - avatar
0
Yes, I had a typo. But it makes no difference. I posted the code. I have tried to chomp it, but still failing.
17th Jan 2020, 8:06 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
0
That idea is working! It's not the most automatic way to store and handle variables. I would love to be able to store them all in an array. However, for now, I will be using your method. I have modified the uploaded code to make the idea clear. However, if someone thinks it could be improved, I'm open to suggestions. Thank you very much!
17th Jan 2020, 10:01 AM
Fernando Pozzetti
Fernando Pozzetti - avatar