Programming Contest: Efficient Editor Usage 33
Fred (a.k.a. The POTM-MASTER) writes "Anyone can write editors, but it's surprisingly hard to write a program to USE an editor. This latest Programming challenge asks you to write a program that will change one block of text into another using a simple set of 'vim-like' editor commands." (Find the details here.) "Deadline is May 31, 2005 so you've got plenty of time. The POTM is the 'Programmer Of The Month' contest - newly revived and active with about 1000 folks registered for the forums. It is completely for fun - unsponsored and prize-less except for the fame!"
vim-like? (Score:5, Interesting)
But then, I guess "using a few simple manipulation commands" doesn't sound as sexy, eh?
Re:vim-like? (Score:3, Interesting)
In that regard, I think the problem is quite cleverly designed, as the choice of commands is small yet sufficient to invite complex solutions (beyond just finding the smallest diff between the inputs).
Re:vim-like? (Score:1)
Contest to find most effienct keystrokes (Score:4, Interesting)
And my method is capable of learning.
Re:Contest to find most effienct keystrokes (Score:2)
Re:Contest to find most effienct keystrokes (Score:2)
Submit it, then. I'll look for Mycroft in the live standings.
Doug
IP (Score:1)
pff... (Score:3, Funny)
Just use sed, like a RealMan.
Re:pff... (Score:2)
Re:pff... (Score:1)
Re:pff... (Score:2, Funny)
The winning entry will probably have a nice, eye-candy laden window with animated spinning skulls, crappy MIDI music (just like a geocities page) with an Expect backend. Naturally the name will be called "Kreplace" or "GNU/Instead" or something equally stupid.
Re:pff... (Score:4, Interesting)
Its also a non-trivial algorithm. Basicly a bunch of partial line diffs and trying to find as much commonality as you can. RCS systems use this type of functionality. The better you make them, the better they can do. ALthough a real RCS system would need to be able to analyze over y as well as x, this seems to have a very limited y.
Brute Force solution (Score:2)
I'm thinking this may be the most efficient for really different sets of files.
Re:Brute Force solution (Score:3)
That solution fails, by the way, to reproduce the target. I'm using:
>aFIRSTLINEd<>aNEXTLINE
That should reproduce any target, without regard to the input. And I submitted it, we'll see just how well it does. :)
Doug
Re:Brute Force solution (Score:2)
Hope your solution wins!
Re:Brute Force solution (Score:3, Interesting)
Tied for 6th place [dinsights.com]!
Doug
Watch out (Score:2, Funny)
Oh no. Don't tell the emacs people about this...
Re:Watch out (Score:2)
There is already a M-x vi-mode.
Re:Watch out (Score:1)
Re:Watch out (Score:2)
We're talking text-editor passion here, baby.
Genetic Algorithm anybody? (Score:2, Insightful)
I think an obvious approach here is to use a genetic algorithm - literally breed the best collection of editting commands to generate the output.
Reading the rules says that there is a time limit of 60 seconds per program, so it might not be the best approach in reality - but it might be a fun way to attack the problem.
Re:Genetic Algorithm anybody? (Score:2)
The obvious would be a simple linear combination: a1 * Len(P) + a2 * Lev(Src, P(Src))
Where P is the editing sequence, P(Src) is the result of running P on the source string, and Lev is the distance between the source and target.
a1, a2 could be manually tuned, or superselected by some appropriate method.
Re:Genetic Algorithm anybody? (Score:2)
Edit distance with traces (Score:4, Informative)
So what's the deal with this?
Use the edit distance algorithm and find all traces transforming the source string into the target string. Then go through all traces and try to chunk them into as big "editing chunks" as possible, which depends on whatever the editing operations they permit.
Re:Edit distance with traces (Score:4, Interesting)
For example, change a couple of characters on the first line (which moves the cursor left or right); go down a line; change a couple of characters (again moving the cursor left or right); return to the first line and perform some more edits...
So, there are two problems -- solving the problem in the minimum number of moves (which should be doable with a small amount of thought), and solving the problem in the minimum amount of time (which will be more difficult, because the standard diff algorithms aren't sufficient).
Re:Edit distance with traces (Score:2, Informative)
Re:Edit distance with traces (Score:1, Interesting)
a) work out which part of the ton does actually half solve the problem, and
b) work out how to extend it to do the other half of the work.
The fact the scoring is based upon all commands including cursor movements means that it isn't the case of just finding the smallest number of changes for each line.
Mole125
Triviality (Score:1)
Perhaps I'm being thick here, but I can't really see how to do this. For example, consider trying to reduce the problem using maximal length shared substrings (sort of like doing greedy regex searches). Consider transforming this:
into this
Even though the shared substring takes up most of the example, trying to preserve it make