17
1
On puzzling SE there are what are called "matchstick problems" in which math is written in match sticks and you are allowed to move a certain number of them to get a certain property.
In this question we will be considering only integers represented in a 7-segment display format. Here are all 10 digits in that format:
__ __ __ __ __ __ __ __
| | | __| __| |__| |__ |__ | |__| |__|
|__| | |__ __| | __| |__| | |__| __|
Each segment of the display is one "match-stick" which can be moved independently of the rest of the number. Matchsticks are indivisible and indestructible, the cannot be broken or removed by any means.
A common puzzle is to take a number given in base 10 and try to make the largest number possible in a given number of moves. A move is considered to be one movement of a matchstick from any occupied slot to any other unoccupied slot. You are perfectly permitted to make new digits on either side of the number, for example 0 can be made into 77 give 3 moves
__ __ __ __ __ __ __
| | | | | | | | |
|__| , __| , | , | |
However you may not make one slot into 2 or make new slots between existing ones, for example turning a 4 into an 11 in the middle of a number or inserting new digits in between existing ones. Each move need not make a proper number but the final result should be a proper number in the base 10 seven segment display. You need not use every move if you do not wish to. Unlike on puzzling this is a [tag:close ended question] you may not use any operators (multiplication, exponentiation, etc.) or mathematical constants (Pi, Graham's number, etc.) in your answers.
Task
Write a program or function that takes a number and a number of moves as input and returns the largest number that can be made with that many moves on the original number.
This is a code-golf question so answers will be scored in bytes, with less bytes being better.
Test Cases
n, moves -> max
0, 1 -> 9
0, 3 -> 77
0, 4 -> 111
8, 3 -> 74
220, 1 -> 320
220, 2 -> 520
220, 3 -> 7227
220, 4 -> 22111
220, 5 -> 32111
747, 1 -> 747
747, 2 -> 7171
747, 3 -> 7711
5I... actually stayed up late last night pondering the Levenshtein distance between various matchstick digits... What an odd coincidence :P – ETHproductions – 2017-07-25T17:03:53.097
1Can empty slots formed in the middle be ignored at the end? E.g.
919, 2 -> 991
– DanTheMan – 2017-07-26T00:20:49.317Related – geokavel – 2017-07-26T01:02:56.777
wheat wizard, which grid is being used? – tuskiomi – 2017-07-26T03:27:40.493
@tuskiomi "However you may not make one slot into 2 or make new slots between existing ones" – Post Rock Garf Hunter – 2017-07-26T03:28:42.990
So is the wheat wizard grid accurate to this? https://imgur.com/te38cF4
– tuskiomi – 2017-07-26T03:31:18.417@tuskiomi Yes the one on the bottom is accurate. I'm not sure how the one on the top would even work. – Post Rock Garf Hunter – 2017-07-26T03:32:12.023
@WheatWizard its the top one with bars between each digit. More of a shape recognition way of looking at it. – tuskiomi – 2017-07-26T03:33:45.977