Now, one of the first puzzles is called the MU puzzle. It's rather simple:
Now, the puzzle that is in the book is to try to transform MI to MU. Much of the book shows that this is impossible. This golf isn't going to go that far.
Given the above rules for the MU-puzzle, and two strings, the starting and target strings (only made up of M, I, or U), and a number that is the maximum number of steps.
Find the perl golf solution that either returns the shortest number of steps it takes to get from the starting string to the target string, or zero if no such transformation is possible within the maximum number of steps. Zero should also be returned if the target string equals the starting string.
Note that each step is *1* application of any rule above; that is, "MUUUU" to "M" requires 2 steps. (MUUUU->MUU->M).
Example usages is as below:
And as a hint, double maps are possibly your friends.# call as mu ( $start, $targer, $max ); mu( "MUUUU", "M", 20 ); # returns 2 UPDATED!!!!!! (thanks japhy) mu( "MI", "MU", 20 ); # returns 0 mu( "MI", "MI", 20 ); # returns 0 mu( "MI", "MUIUI", 20); # returns 4 mu( "MI", "MUIUI", 3 ); # returns 0
Update : fixed the problem in the example above. And as another hint (based on japhys first go), be aware that MUIIIIU can go to both MUIUU and MUUIU.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Golf) Gödel, Escher, and Bach, Oh My!
by japhy (Canon) on Jul 03, 2001 at 18:37 UTC | |
by Masem (Monsignor) on Jul 03, 2001 at 18:56 UTC | |
|
Re: (Golf) Gödel, Escher, and Bach, Oh My!
by VSarkiss (Monsignor) on Jul 03, 2001 at 18:51 UTC | |
by busunsl (Vicar) on Jul 04, 2001 at 01:19 UTC | |
by VSarkiss (Monsignor) on Jul 04, 2001 at 02:47 UTC | |
|
Re: (Golf) Gödel, Escher, and Bach, Oh My!
by blakem (Monsignor) on Jul 03, 2001 at 23:56 UTC | |
|
Re: (Golf) Gödel, Escher, and Bach, Oh My!
by chipmunk (Parson) on Jul 06, 2001 at 00:13 UTC |