Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Regular expressions help

  1. May 29, 2010 #1
    1. The problem statement, all variables and given/known data
    Σ = {a,b}
    find regular expression for

    1)all strings that havent got more than 3 a's
    2)all strings that have a number of a's that is divisible by 3
    3)all strings that have the substring aaa only one time

    3. The attempt at a solution
    1) b*Ub*ab*Ub*ab*ab*Ub*ab*ab*ab*

    2) (b*Ub*ab*ab*ab*)*

    3) b*(aUaaUe)b*aaab*(aUaaUe)b*

    can you please tell me if im correct? this is not homework actually but i didnt know where to post it, im just preparing myself for the upcoming exams and need to know if i have these correct

    thanks in advance
     
  2. jcsd
  3. May 29, 2010 #2
    i have one more

    Σ = {a,b,c}

    i want a regular expression for all strings that contain at least 1 a, 1 b and 1 c

    ok my solution is this

    (a(bUc)*Ub(aUc)*Uc(aUb)*)*

    but the book has this solution

    (aUbUc)*c(aUbUc)*b(aUbUc)*a(aUbUc)*

    which is right but is my solution wrong?
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook