RegExp challenge.

Started by
9 comments, last by rip-off 15 years, 9 months ago
If I challenged you to write a RegExp that somehow took this string:
Quote:Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
..and reduced it down to the word "Salsa".. 1. Could you? No, seriously. 2. How much would it cost for you to do something so headache-inducing? Just curious ;) Some people are obsessed with this.

Kult House - Fresh Production Media

Advertisement
Umm, are you just asking for a simple replace? As in something like s/Lorem ipsum blah blah blah/Salsa/? Or are you asking something more complex?
Far more complex. Like, as convoluted and ridiculous as possible.

Kult House - Fresh Production Media

A regexp doesn't reduce things, though. It just matches (or doesn't match) them. It has no output capabilities.
Maybe I'm misunderstanding you, but this seems like it'd be fairly simple if tedious task, for which is possible to prove both the existence of a solution, and easily provide an algorithm to generate it(if you dont want to just muck around with regexp syntax which also seems pretty straight forward). You want to build a regexp to recognize the given string. This is equivalent to wondering if you can build a DFA that can recognize the string, which clearly you can, as for example below

state0(on l go to state one, else computation fails)
State1(on o go to state 2, else computation fails)
etc..
StateLast (we recognized the string, output salsa)

Really since you are only trying to recognize the one string, theres not much to it.

Then you want to convert the DFA to a regular expression. For every DFA there is a regular expression and algorithms exist for converting one to the other..So really not too exciting, although tedious to apply to the long state machine that would result.

Perhaps I'm not understand what you mean by reduce, but imo any reasonable definition you can come up for that would just mean outputting salsa whenever you recognize that string(or outputting parts of salsa when you recognize parts of the string, but thats to be equivalent) .
like s/.*/salsa ?
A more interesting one IMO is to match all numbers divisible by 3.
I mean, why would you get your medical advice anywhere else?
Anything that would do what you are asking would be so hopelessly tied to your exact specific input that it could equivalently be reduced to s/Lorem ipsum blah blah blah/Salsa/, as Trapper said.
you are asking for a regexp that would match only one specific text?
(in formal words: a language of only one word)

that is not a challenge.
the regexp is ^text$

a challenge would be to identify any text that an average human would confuse for the lorem ipsum :)
This is the closest thing to "reducing" that text to "salsa" in Perl. (There is no uppercase "S" in the text, that's why not "Salsa".

 my $str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";my @arr = ($str =~ /.*(s).*(a).*(l).*(s).*(a).*/);print @arr;



But this problem is not challenging nor interesting at all.
Quote:Original post by misi
But this problem is not challenging nor interesting at all.


Ya, its stupid and I hate it.

This topic is closed to new replies.

Advertisement