Roller coaster of numbers

5

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.

Matías Cánepa

Posted 2015-11-01T01:10:46.447

Reputation: 161

Question was closed 2015-11-01T07:25:46.457

3Very similar. – Calvin's Hobbies – 2015-11-01T01:34:12.127

3

Can we use ANSI escape codes?

– Dennis – 2015-11-01T02:33:55.143

This is essentially a special case of the challenge that Calvin's Hobbies linked to. – Alex A. – 2015-11-01T07:26:22.973

Answers

1

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.

Flambino

Posted 2015-11-01T01:10:46.447

Reputation: 1 001