15
2
Intro
The information panels are everywhere. When the technology became cheaper, the paper posters were transformed into luminous signs that show words that appear on one side and come out on the other, like the one on the figure:
When one of these signs starts up, it usually starts empty and the text leaves from the right side to the left, moving until it disappears.
Its functionality is to go on and off the small light bulbs (LEDs) to give the sensation of movement.
If instead of text we only need to show numbers, the poster can be much less sophisticated using the so-called seven-segment markers like the following:
In this case each number is represented by the combination on / off of only 7 light segments that allow to represent all the numbers:
The question we ask ourselves is how many changes of lights (how many on and off) should be made to pass through one of these posters a certain number?
For example, to show the 123 in a 3-digit sign that starts with all the LEDs off we will have:
This makes a total of 42 changes of lights.
Challenge
Given a non-negative number and a positive sign length calculate the number of lights changes.
Rules
- Assume input consist in a non-negative number (N >= 0) and a positive sign length (M > 0)
- Assume Sign length >= Number length (M >= digits(N))
Test cases
123, 3 => 42
45, 5 => 60
111, 3 => 12
98765, 10 => 220
0, 3 => 36
https://en.wikipedia.org/wiki/Seven-segment_display#Displaying_letters useful link – qwr – 2018-08-22T18:20:13.590
1
What's the goal of the question? In reality, a part like MAX7219 will control the 8 digits, to have them displayed you would just send the 8 digits to the MAX7219 via SPI commands. The decimal point 8th bit from 1 or 2 digits would be used to for the -/+ light. For instance, 4 could be daisychained to make an 8 x 32 dot display to scroll text across, like this one I made: https://www.youtube.com/watch?v=hwYqgyMc5S4
– CrossRoads – 2018-08-22T18:18:14.3773@CrossRoads Actually this is not intended for a real hardware answer or anything like this. It is a challenge to create an algorithm which can output the number of lights changes of a given number in multiples 7-segment displays – Luis felipe De jesus Munoz – 2018-08-22T19:18:03.837
1Suggested test case:
0,3 => 36
– Chas Brown – 2018-08-22T22:21:52.4801May we take the first integer as a string, or list of digits? – Οurous – 2018-08-22T23:38:39.800
1@Οurous no, you must take both inputs as integer – Luis felipe De jesus Munoz – 2018-08-23T00:40:52.993
I'm with @CrossRoads - it's a pointless challenge as no hardware would ever work this way. – Alnitak – 2018-08-23T07:13:01.823
1@Alnitak This is not intented to work in real world. It is just a programming challenge. Nothing to do with how real hardware works..... – Luis felipe De jesus Munoz – 2018-08-23T11:50:14.927