This problem is soberly difficult ... (Ruby)

Count from 0 to 9 (Ruby edition)

problem

Consider a counter that counts from 0 to 9.

0 → 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → 9

As an extension of this counter, we considered a counter that can start with any number.

2 → 3 → 4 → 5 → 6 → 7 → 8 → 9 → 0 → 1 (Example starting from 2, the counter returns to 0 when it reaches 9.)

Receive the number n from the input, start the counter from n,

Implement a program that outputs 10 counter values in order.

Value to be entered

The input is given in the following format

n

・ N is the first value of the counter

Expected output

Output the 10 counter values starting with n in order, separated by line breaks.

Input example 1

0

Output example 1

0 1 2 3 4 5 6 7 8 9

Input example 2

2

Output example 2

2 3 4 5 6 7 8 9 0 1

My answer (I couldn't solve it after all)

python


n = 2
#Reset to 0 when n reaches 10, pass otherwise and output 10
for i in n..9 do
if n == 9
   n = 0
   puts i
   n += 1
end
end

I played with it too much and probably did it for about 2 hours, so in the end it will be the code I gave up lol

Anyway, when I try to go to 10, I need a code that returns to 0 and restarts, but I struggled to write that code at n == 9. This is where the programming brain is lacking. .. .. And after all, verbalization when googled is quite difficult at such times.

that's all!

Recommended Posts

This problem is soberly difficult ... (Ruby)
Ruby problem ⑦
ruby search problem
[Ruby] FizzBuzz problem
ruby API problem
[Ruby] FizzBuzz problem
[Ruby] Ruby API problem
ruby API problem
[Ruby] What is true?
Maybe this is object oriented
What is a Ruby module?
Is Ruby all objects, true?
Ruby # {} is not variable expansion
This is the first post.
Rails is difficult and painful!
Rails is difficult and painful! Ⅱ
[Ruby] What is `!!` used for?
[Ruby] What is an instance?
[Ruby] problem with if statement
Ruby deposit system, algorithm problem
[Ruby] This is the solution. When should I use instance variables?