So sayeth the Shepherd
MATL, 60 56 53 bytes
:"@qXJx[HKCbO]"7Z"' |-| 'v'o'@('--|-|-- ' JVhXxXD
The animation with the above code runs very fast. The following version includes a pause to make the animation slower and thus easier to see (not required by the challenge), at the cost of 4 more bytes:
:"@qXJx[HKCbO]"7Z"' |-| 'v'o'@('--|-|-- ' JVhXxXD.2Y.
Try it at MATL Online! The interpreter is a beta; refresh the page if it doesn't work.
Or see a recording from the offline compiler:
Explanation
:" % Input N implicitly. Repeat N times
@q % Push iteration index minus 1, that is, from 0 to N-1. This
% are the numbers of sheep
XJx % Copy into clipboard J and delete
[HKCbO] % Push array [2 4 7 -2 0]
" % For each value in that array. This loops generates the 5
% frames for each number of sheep
7Z" % Push string of 7 spaces
' |-| ' % Push this string
v % Concatenate vertically. This gives a 2x7 char array
% with the upper part of the frame, except the 'o',
% which will be now placed in a varying position
'o' % Push string 'o'
@ % Push loop variable, that is, 2, 4, 7, -2 or 0
( % Write 'o' into that position of the 2x7 char array.
% The position is interpreated linearly, that is, a single
% number is used as index into the 2D array in column-major
% order (down, then across). So index 2 is lower-left corner,
% index 4 is to the right of that etc. Indexing is
% semi-modular (modular for non-positive values). So 0 is
% the lower-right corner, and -2 is to the left of that
'--|-|-- ' % Push this string
JV % Push current number of sheep converted to string
h % Concatenate horizontally
Xx % Clear screen
XD % Display all stack contents
.2Y. % Pause for 0.2 seconds (optional)
% End implicitly
% End implicitly
JavaScript (ES6), 120 124 bytes
f=(n,m=` 2
43|-|10
──|-|── `,s=0)=>n?alert(m.replace(s%5,'o').replace(/\d/g,' ')+' '+(n-1),(++s%5?f(n,m,s):f(n-1,m,0))):''
The last frame computed is showing first.
Thanks to this the jump number is n-1
In alert
, charaters have different width so it looks like it's broken.
f=(n,m=` 2
43|-|10
──|-|── `,s=0)=>n?alert(m.replace(s%5,'o').replace(/\d/g,' ')+' '+(n-1),(++s%5?f(n,m,s):f(n-1,m,0))):''
;
f(2);//You'll get 10 alert popup
Previous answer:
120 bytes, the jump number is wrong because it starts at 1 instead of 0
f=(n,m=` 2
43|-|10
──|-|── `,s=0)=>n?alert(m.replace(s%5,'o').replace(/\d/g,' ')+' '+n,(++s%5?f(n,m,s):f(n-1,m,0))):''
JavaScript (ES6), 144 142 bytes
Clears the output and waits 300ms between each frame:
n=>(F=j=>((c=console).clear(),c.log(` 2
01|-|34
──|-|── `.replace(/\d/g,i=>(j-i)%5?' ':'o')+(j/5|0)),++j<n*5&&setTimeout(`F(${j})`,300)))(0)
You can test it here (make sure to open the console).