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-27 7:58

>>8
Since Random rand = new Random(); is not seeded
It is implicitly seeded with current time, homosexual.

Anyway, the bruteforce approach is obvious:

def penis(s, repetitions):
    assert not (len(s) % repetitions)
    orig_len = len(s) / repetitions
    def rec_check(s, word):
        print 'rec', s, word
        if not s: return True
        start = 0
        while True:
            start = s.find(word, start)
            end = start + orig_len
            if start < 0:
                return False
            if rec_check(s[:start] + s[end:], word):
                return True
            start = end
    for start in xrange(0, len(s) - orig_len + 1):
        end = start + orig_len
        word = s[start:end]
        if rec_check(s[:start] + s[end:], word):
            return word
    return None

I wonder if the solution has to be unique, I guess it's directly related to any kind of search optimization.

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