NOTE: If you're looking for issue 430's gist, go here: https://gist.github.com/ericnormand/fb8d0356a5ff7d898707012a97975ec7
Headline Scroller
A local news station needs you to program their LED scroller screen. It will scroll headlines from the right side to the left side all day. Write a function that takes a headline (string) and the number of characters in the LED screen (integer) and returns a list of the different refreshes of the screen.
The first refresh should be a string of all spaces to clear the screen:
(nth (scroller "HEADLINE" 10) 0) ;=> " "
It should be a number of spaces equal to the width of the screen (in this case, 10).
The second refresh should have the first letter after 9 spaces:
(nth (scroller "HEADLINE" 10) 1) ;=> " H"
Then:
(nth (scroller "HEADLINE" 10) 2) ;=> " HE"
The full output:
(scroller "HEADLINE" 10) => (" "
" H"
" HE"
" HEA"
" HEAD"
" HEADL"
" HEADLI"
" HEADLIN"
" HEADLINE"
" HEADLINE "
"HEADLINE "
"EADLINE "
"ADLINE "
"DLINE "
"LINE "
"INE "
"NE "
"E "
" ")
The scroller should end with a string of 10 spaces again.
Thanks to this site for the problem idea, where it is rated Very Hard in Ruby. The problem has been modified.
Please submit your solutions as comments on this gist.
To subscribe: https://purelyfunctional.tv/newsletter/