Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
it is regular expression as it is used in math, not programming, the og definition
-
@iiii [01]*0 could work i guess.
Then again this is the first solution don't expect it to be the best. We find something working and optimize it later. -
@iiii too much coffee or just learning a new concept - like regex - could do that.
Fuck around, find out, optimize to fuck around faster and better. -
@iiii sorry for my dum dum but give me an example what would be missed by the OG regex
-
@iiii
1. this is regular expression (algebra), not regex. the notation is straight out of math
2. we're only considering numbers that don't have 0s on the left -
@lbfalvy it really doesn't, * includes any combination plus an empty word, so it can be 0
-
@darksideofyay It can be either just 0 or any number ending in 10, because any occurence of the outermost * group will end in 1.
-
@iiii The outermost * group contains
1(0+1)*
This can be rewritten as
1 | 1(0+1)+
Both of which end with 1, therefore if the outermost * matches 0 occurrences then the output is exactly 0, if it matches >=1 occurrences then the output ends with 10. -
@iiii My solution contains only one * so it's easier to reason about. Don't be like the Haskell community. Don't pretend like character count = complexity.
-
@iiii But the original regex doesn't match even numbers, that's my point. It needs to end in 0 and before that there needs to be a group which is either just 1 or ends with a subgroup that ends with 1.
-
@lbfalvy @iiii i literally took this from a college class example lol it's not the same notation, you guys are confused
-
@darksideofyay I know mathematical regex notation and I gave a reasoning for my claim. If my reasoning is unsound I'm open to criticism, otherwise your teacher made a mistake. I'm in the third year of my bachelor's and believe me they tend to do that a lot more than their students.
-
L:={⟨2n⟩2:n∈Z≥0}
(0+1)* = {e, 0,1,01,10,11,...}
1(0+1)* ={1,10,11,101,110,111,...}
(1(0+1)*)*0 => all end in 0 and begin in 1 -
@darksideofyay Okay, so it's some sort of ascii-mapping into +. Mapping logical OR would be dumb, so it's probably the union operation. Weird, it doesn't feel intuitive and I've never seen it written that way.
-
I guess if there's one thing all mathematicians agree on is that the notation is always correct as long as someone uses it to prove useful statements so standardization and readability aren't objectives.
-
@lbfalvy we're getting into Chomsky, but the professor said that's formal linguistics, not algebraic notation. we also did representation in automatons.
i only did this post to prove to myself this knowledge is useless in our field -
@darksideofyay It's not useless, state machines are directly used in sequence processing which was initially just signal processing and text parsing but with Redux even mouse clicks form an input sequence.
-
@darksideofyay I may overvalue them because I'm neck deep in langdev but I have seen them used everywhere because they have very nice limitations that lend themselves to static analysis.
-
@lbfalvy yeah but it's very specific knowledge, no one in my class will go into academic research or anything
-
@darksideofyay Most devs don't know how much faster they could think if they had the right models. It's not strictly necessary for most things but it has more uses than you'd expect.
-
@darksideofyay It's not just academic research, as I said, even button clicks form a sequence that can often be most easily processed with a FSM.
-
Regex as a tool is definitely overvalued because it's among the worst possible descriptions of a FSM, but other, better models of them exist.
-
-
Oh also, sorry if I misunderstood but
1(0+1)*0 should only match "begins with 1, ends with 0"
(1(0+1)*)*0 looks like it could match 01001 and 11001 where as the one I suggested would only match 11001
out of curiosity, how many of you know how to read this:
(1(0+1)*)*0
question