[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
You have 30 seconds to type up a regular expression that will
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 48
Thread images: 5
File: 1429290316542.jpg (36 KB, 511x509) Image search: [Google]
1429290316542.jpg
36 KB, 511x509
You have 30 seconds to type up a regular expression that will take the second and fourth word that happen to be right behind a comma and contain at least one number and an asterix in a string and output the same string with those words switched around.

Well? I thought you were a programmer, anon.
>>
Simply epic.
>>
>>55200456
define "word".
>>
>>55200887
Since we need a number and a special character but to separate it from a comma, let's say it's a chain of any character except for whitespace and punctuation.
>>
>>55200456
:^)
>>
>>55201230
That's an invalid pattern.
>>
>>55200456
:^)
>>
>>55200456
that problem can't be described by an regular grammar
>>
>>55200456
not doing your gay homework for you, gayboi
>>
>>55200456
Why don't you try those web sites that you pay like 5 bucks and they do your homework question for you instead of asking us bub
>>
>>55201381
>>55201382
i doubt that that's a homework question, there's just too much wrong with it.
>>
>>55201402
nice try OP
>>
>>55201434
god damn, just take a look at that retarded question and think about it for a second.
>>
>>55201459
It's a pretty basic regex problem, it just sounds complicated.
>>
>>55201459
Yeah, except it sounds like Question 5 on some data structures/algorithm course homework.
>>
regexes dot't replace text they only match it
>>
>>55201532
>>55201553
OPs problem can't be described by an regular grammar. so the whole question doesn't make any sense.
>>
File: 1432692516955.png (108 KB, 194x192) Image search: [Google]
1432692516955.png
108 KB, 194x192
>>55200456
:^)
>>
>>55201668
>using the smiley with a carat nose
>>
>>55201612
I second this. Given that you need to reverse the words by switching them around, this implies that algorithmically you would require a stack-style data structure.

Such a language can't be described by regular expressions. You need at the very least a context-free grammar.
>>
>>55200456
I mean, i could do that... but I'm on my phone in bed.... nah fuck off m8.
>>
>>55201532
No, it's not. It's a trick question. See above >>55201755
>>
>>55200456
:^)
>>
>>55201612
Yes it can. It's something like...
^.*[ .,:;!?](.*\*.*[0-9].*|.*[0-9].*\*.*),

... I give up.
>>
>>55201755
>>55201766
A lot of homework assignments don't make sense grammatically holy crap OP is desperately trying to get an answer lol
>>
>>55201779
>using the smiley with a carat nose
>>
>>55201755
ffs most programming environments have a regex function that will allow you to isolate matches in parentheses and output a new string where they're referred to by %0 for the first match, %1 for the second, etc. Read a book you nigger.
>>
>>55201825
just because grep or perl support capture groups doesn't mean those are regular expressions.
regular expressions can't keep a track of the state.
>>
>>55201825
No fucking shit, you troglodyte. That's just a syntactical sugar equivalent to the regex concept of character groupings.

It doesn't magically give regular expressions any more computational power, and certainly doesn't let you solve the general problem for a sentence composed of an arbitrary amount of strings.

I'm sorry your first year introductory CS course wasn't advanced enough to teach you about the complexity classes of formal languages, but SHUT YOUR FUCKING GODDAMN STUPID FUCKING FACE WHEN YOU AREN'T EDUCATED ENOUGH TO KNOW WHAT YOU'RE TALKING ABOUT.
>>
File: 1464978346223.png (169 KB, 459x475) Image search: [Google]
1464978346223.png
169 KB, 459x475
>>55201749
>carat
>>
>>55200456
>that will take the second and fourth word that happen to be right behind a comma and contain at least one number and an asterix in a string and output the same string with those words switched around.

s/([^ ],)([A-z0-9*])(,[^ ]+,)([A-z0-9*]+)(,[^ ]+)/\1\4\3\2/
>>
File: autism-1.jpg (935 KB, 2530x759) Image search: [Google]
autism-1.jpg
935 KB, 2530x759
>>55201879
>>55201906
So you knew what I meant, you were just ignoring it on purpose because I didn't phrase it in a way that left absolutely no ambiguity.
>>
>>55201946
>because I didn't phrase it in a way that left absolutely no ambiguity.
no, you phrased it completely wrong. you don't seem to have any idea what a regular expression is.
>>
>>55201930
corrections

>s/\([^ ]+,\)\([A-z0-9]*(\*+|[0-9]+)(\*+|[0-9]+)[A-z0-9]*(\*+|[0-9]+)(\*+|[0-9]+)[A-z0-9]*\)\(,[^ ]+,\)\(([A-z0-9]*(\*+|[0-9]+)(\*+|[0-9]+)[A-z0-9]*(\*+|[0-9]+)(\*+|[0-9]+)[A-z0-9]*\)\(,[^ ]+\)/\1\4\3\2/
>>
>>55201946
No, we're ignoring it because you're mathematically, provably wrong, you fucking dolt.

Regexes are 1-to-1 interchangeable with finite automata.

This question is asking you to store arbitrary state, because you need to reprint the entire original sentence albeit with two words swapped.

This is literally a classic example of a problem which requires an arbitrarily large automaton, and therefore can't be expressed with a regular expression.

You need a more powerful expressive tool such as a CFG to express it. Silly per-language shit isn't enough to give you the ability to solve this problem in general.

Please, stay the fuck away from computer science, you clearly have no business being there.
>>
>>55201997
He's a retard who thinks he knows more than he does. Just ignore him and hopefully he'll shrivel up and die.
>>
>>55201796
;^)
>>
>>55201906
character groups are not part of regular expressions, are they?

They are more like metainformation that require extra memory and processing from the program running the expression

even replacements is not part of regular expressions, regular expressions is just YES/NO-matching of input strings

the case in the OP does not look general enough to give regular expressions problems

arbitrary long-distance matching (like parenthesis-balancing) would not work even with groups, however.

I do not immediately see why OPs thing is impossible

12345

where 1 a blob up to the first word
2 is a blob constituting a word
3 is a blob after the word and up to the 4th word
4 is the 4th word
5 is the rest

then you just use the memory of the programming environment that ran the regex to output them

you are right that it is syntactic sugar for storing the shit in 5 variables and generating a string from those 5 variables

that is all replacements in regex are, right?

replacement-regex is really just a bastardization of the concept and misleading
>>
>>55202057
around the third or 4th sentence I started pretending those SED expressions that let you do replacements were equivalent with regular expression finite automata,

if you grant that then it should be possible as far as I can tell


With only finite automata? You can not even do replacements, you can only tell whether an input string matches some pattern.
>>
>>55202057
Actually, that's a fair argument.

Regardless, if we assume that we only have access to the mathematically defined operators of true regular expressions, then it isn't solvable, correct?

You need to rely on the bastardized programming-environment versions, which are not actually regular expressions, correct?
>>
>>55202023
>Swapping two words in a sentence requires to store arbitrary state

No, it just requires you to split the string in five words, and return them in a different order. You determine where each word is using the pattern. This is simple problem solving.

I can't imagine how much of a headache it must be for you to write a shell script that prints "Hello world". Drawing and rendering all the vectors for those characters in plain text is just step one of this fractally complex task.

I hope your salary is subsidized by the government you stupid fucking ape.


>>55201930
>>55202010
>>
>>55202057
i thought its
word*, word* match1 word* match2 word* match3 word* match4
where match2 and match4 are the words you were looking for
>>
>>55200456
//If player lands on spikes, play death sound, subtract 1 life, and restart the room.
if place_meeting(x,y,obj_spikefloor)
{
audio_play_sound(sfx_death, 1, false);
global.player_life -= 1;
room_restart();
}
>>
>>55200456
Not doing your homework.
You can go now
>>
what is a word?
in any case, get a list of words, check if there's a comma, test your regex on each word then swap. pretty simple. if you're trying to do all of that in a regex you're an idiot.
>>
>>55202261
>global.player_life -= 1;
nice try pajeet
>>
>>55200456
retard
>>
>>55200456
>regular expression that outputs
You should work through this book, it's really accessible but still educational
Thread replies: 48
Thread images: 5

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.