6

out of curiosity, how many of you know how to read this:

(1(0+1)*)*0

Comments
  • 10
    Weird regex but okay~
  • 2
    @ElectroArchiver I'd rather be studying regex tbh, more useful
  • 7
    At first I was like (゜-゜)
  • 1
  • 8
    @darksideofyay ¯\(◉‿◉)/¯
  • 0
    @zlice it's the regex for the language that codifies even numbers in binary
  • 0
    it is regular expression as it is used in math, not programming, the og definition
  • 4
    Glad there is something JavaScript cannot evaluate
  • 1
    @darksideofyay is it correct? You are excluding many even numbers with it. You only need the lowest bit to be 0

    [01]*0 is all you need
  • 1
    @iiii and the last character is 0 :)
  • 1
    @FuckJava ohohoho... it is being evaluated
  • 0
    @melezorus34 yes, but the expression preceding it is unnecessary complex
  • 1
    @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.
  • 1
    @melezorus34 eh? How could one come to such a complex solution for such a simple task?
  • 0
    @melezorus34 if you want to be unnecessary fancy by excluding leading zeros then

    (1[10]*)?0

    But the original expression is just wrong. It excludes a lot of numbers
  • 0
    @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.
  • 0
    @iiii sorry for my dum dum but give me an example what would be missed by the OG regex
  • 1
    @melezorus34 100000000 or any other combination of 1 and many zeros following it except 10.
  • 1
    the answer is 0. anything multiply 0 becomes 0. duh.
  • 1
    It's a pointlessly complicated version of

    (1([01]*1)?)?0

    Edit: fixed regex
  • 0
    @iiii not quite. it's either zero or a number that begins in 1 and ends in 0
  • 0
    @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
  • 0
    @darksideofyay It needs to end in 10
  • 0
    @lbfalvy it really doesn't, * includes any combination plus an empty word, so it can be 0
  • 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.
  • 0
    \(_/o.O\_)/
  • 0
    @lbfalvy your is pointlessly complicated as well 😂
  • 1
    @lbfalvy it does not need to end with 10. It just needs to have the lowest bit as 0. This lowest bit is the only odd component in any binary number.
  • 0
    If using basic regular expressions without additional features then it should be like this:

    (1(1|0)*)?0
  • 0
    @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.
  • 0
    @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.
  • 1
    @lbfalvy mine has only one as well and is simpler to reason about
  • 0
    @lbfalvy and your expression excludes quite a few even numbers which do not end in 10.
  • 0
    @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.
  • 1
    @lbfalvy yes, exactly. i was saying that as well: it does not match even numbers, despite OPs claim that it does
  • 0
    @iiii I missed the comment where she said that, sorry.
  • 1
    @lbfalvy the seventh one
  • 0
    it's zero. Don't even have to read it
  • 0
    oh wait
  • 0
    @lbfalvy @iiii i literally took this from a college class example lol it's not the same notation, you guys are confused
  • 0
    @darksideofyay so what is it then?
  • 1
    @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.
  • 2
    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
  • 2
    @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.
  • 1
    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.
  • 1
    @lbfalvy yeah it's

    L(0+1) = L(0) U L(1)

    L(01) = L(0)L(1)
  • 1
    I only ever read Chomsky and he and my lecturers both used | for OR.
  • 0
    @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
  • 1
    @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.
  • 1
    @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.
  • 0
    @lbfalvy most devs don't know this, and they're fine
  • 0
    @lbfalvy yeah but it's very specific knowledge, no one in my class will go into academic research or anything
  • 0
    @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.
  • 0
    @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.
  • 2
    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.
  • 0
    @darksideofyay I could not find such a notation
  • 0
    I learn something new everyday.

    @darksideofyay does the e stand for empty in that syntax?
  • 0
    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
  • 0
    @melezorus34 the first one doesn't include 0
  • 0
    @melezorus34 Really? My Firefox didn't eval it.
  • 0
    @melezorus34 i was too lazy to find the character ε, but yeah it's empty
  • 0
    @FuckJava put a slash to the start and another one at the end.
  • 0
    @darksideofyay "all end in 0 and begin in 1"

    0 doesn't begin with 1 :)
Add Comment