Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge

Name: Anonymous 2011-06-26 15:10

The Anus operation is defined as follows:


public static string Anus(string input, int repetitions)
{
    Random rand = new Random();
    string result = input;
    while(repetitions --> 0)
    {
        result = result.Insert(rand.Next(0, result.Length-1), input);
    }
    return result;
}


Little Ive was playing with his Anus and discovered that, when he knows the output string and the number of repetitions, he can determine the original string. Then The Suss joined Ive and told him that his method, written in LISP, was faster and that Ive was a faggot for using brute force. What method did Ive discover? What was The Suss's method?

Name: Anonymous 2011-06-26 20:43

Here's the brute-force way:
  - You know the last letter of result is the last letter of input.  Store this value in LL.  then (sorry, newfag, don't know how to do monospace/code):

orig := LL
while (orig.length < (result.length/(repetitions+1)):
    if (every occurrence of orig in result is preceded by LL):
        orig := (LL + orig)
    else:
        orig := (rightmost character that preceeds orig that isn't LL) + orig

return orig;

I bet there is a slick way to do this using a memoization table, like in the KMP algorithm, but I'd have to think about that and don't want to.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List