5
\$\begingroup\$

This question already has an answer here:

Write a program that generates a sequence of numbers starting with zero and then 100 random integers between -9 and 9.

That sequence will be displayed like a roller coaster.

Any increasing number in the sequence will go up and any decreasing number will go down

Sample sequence:

0 1 8 5 -1 -5 7 1 3 3 4 6 9 -2 ...

Sample output

                                                9
        8                                   6       -2...
    1       5                           4
0               -1      7       3   3
                    -5      1

This is code golf. Shortest code in bytes by November 5th wins.

\$\endgroup\$

marked as duplicate by Alex A. Nov 1 '15 at 7:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    \$\begingroup\$ Very similar. \$\endgroup\$ – Calvin's Hobbies Nov 1 '15 at 1:34
  • 3
    \$\begingroup\$ Can we use ANSI escape codes? \$\endgroup\$ – Dennis Nov 1 '15 at 2:33
  • \$\begingroup\$ This is essentially a special case of the challenge that Calvin's Hobbies linked to. \$\endgroup\$ – Alex A. Nov 1 '15 at 7:26
1
\$\begingroup\$

Ruby, 167 bytes

l={}
y=p=n=0
101.times{|i|
d/=d.abs if(d=n-p)!=0
l[y-=d]||=Array.new 101," "*4
l[y][i]=n.to_s.ljust 4
p,n=n,rand(18)-9}
puts l.sort_by(&:first).map(&:last).map(&:join)

First time golfing Ruby, so I'm sure I'm missing something.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.