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:
Anonymous2011-06-26 15:12
I don't do Java nor Lisp, fagstorm.
Also, lisp is fucking gay and so are you.
Name:
Anonymous2011-06-26 19:36
forget it, it's np hard
Name:
Anonymous2011-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.
>>7
It's a fucking source code. How much more precise do you want it to be written? Fuck you.
Name:
Anonymous2011-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.
Geehrte Damen und Herren wären sie bereit für einen Augenblick die Augen zu schließen und sich vorzustellen wie ich langsam meinen Penis in ihren Mund führe, halten sie kurz inne, riechen sie diesen Würzigen strengen Duft ein ungewaschenen Glieds? Nähmen sie sich zeit und lassen sie es auf sich wirken während ich langsam weiter ihren Rachen runter gleite merken sie die plötzlich Luftknappheit? Erschrecken sie sich nicht sie werden sich schnell dran gewöhnen weinen sie ruhig wen ihn danach zumute spüren sie dem Rhythmus des pochenden Gliedes konzentrieren sie einzig und allein auf die würzige Zwiebelwurst die ihren brechreiz wieder und abermals auf die probe stellt. Und dann werden sie eins, eins mit dem Moment der Vollkommenen Entleerung genießen sie jeden einzigen klebrigen tropfen der ihr Kehle herunter tropft und werden sie sich dem Leben in seiner vollen Wonne bewusst.
Name:
Anonymous2011-06-28 19:44
What's the answer? This is killing me
Name:
Anonymous2011-06-29 9:40
Ive read sicp
Name:
Anonymous2011-06-29 10:40
>>15
It would be a challenge if I told you the answer.
>>18
No, I wanted the fast way. I should probably just dl SICP.
One idea I had, you could look at the sting as a CFG, so that if your original string is xyxzx, then you add a symbol S, and the following two production rules:
S -> SxSySxSzSx
S -> ""
So basically, you iterate through the original string, and try each character as the starting character, construct a grammer using the two rules above, convert it to chomsky form and use the CYK algorithm to see if the long string parses. I think this works, and I think it goes in O(m*n^2) time, like the brute force solution, but you don't need to tell it how many repetitions there are.
Sadly that wasn't the question. Maybe I'm just retarded but this puzzle is good.