A screen consists of some LED segments like such:
The screen can be split into several(maybe one) component. Each component is a segment like above, with varying lengths. These components can be used to display any amount, including 0, of digits, as long as the component is large enough.
Every digit except 1 needs two columns of the grid to be displayed. These columns are not allowed to overlap (even a number like 67 still needs 4 columns and does not fit into a n=2 component). The digit 1 is slim, so it only needs one column.
Therefore, a number fits into a component, iff 2 * Length - (Amount of 1's) <= n+1
.
For example, the number 14617 can be displayed in a screen with the component lengths [0, 1, 1, 2, 0]
:
Given the n's of each component and a positive integer, find the nearest positive integer that can be expressed in the screen. If multiple number are nearest, you can output either.
Shortest code wins.
Examples
[1],3 => 3
[1],16 => 11
[0,0],3 => 1
[0,0],6 => 1 or 11
[2],14 => 14
[2],24 => 21
[3],999999999 => 1111
[1,0,0,0,0,0,1],23 => 23
[0,3],100 => 100
88
be possible forn=2
? What about69
forn=2
? \$\endgroup\$[3]
as one of your examples but don't define it anywhere. What is it EEEI? Very unclear whatever it is. Also details on exactly what numbers EI can represent would be clearer. \$\endgroup\$1
interacts with other numbers, since it only occupies one column - can a single n=2 grid represent both18
and81
? It's not immediately clear. \$\endgroup\$n=3
, or do those not exist? \$\endgroup\$