# S.O.S. Mathematics CyberBoard

Your Resource for mathematics help on the web!
 It is currently Thu, 23 May 2013 09:35:50 UTC

 All times are UTC [ DST ]

 Page 1 of 1 [ 9 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: regular expressionPosted: Wed, 1 Feb 2006 12:00:25 UTC
 Senior Member

Joined: Mon, 21 Jun 2004 15:56:08 UTC
Posts: 69
Let and the set of all string in that start with an even number of a's and no more than two b's.

I only got the first part which is (aa)+(aa)* -> even numbers of a's, however, I don't know how to get the second part for b's.. Can anyone help?

Last edited by simple on Wed, 9 Feb 2011 05:16:42 UTC, edited 2 times in total.

Top

 Post subject: Posted: Wed, 1 Feb 2006 19:28:44 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Sat, 14 Jan 2006 22:40:49 UTC
Posts: 694
Location: Yountville, California
I'm interpreting the description as "starting with an even number of a's followed by no more than two b's." So after the optional b's, the next letter if any must be an a. Also zero is an even number.

The result is: (aa)*b?b?(a[ab]*)?

BTW, in (aa)+(aa)*, the (aa)* is redundant since the + means 1 or more.

Last edited by Bilbo on Sat, 26 Feb 2011 22:16:13 UTC, edited 1 time in total.

Top

 Post subject: Posted: Wed, 1 Feb 2006 22:35:25 UTC
If Bilbos interpretation is correct you could write (haven't tested it)

(aa)*b{,2}

Top

 Post subject: Posted: Thu, 2 Feb 2006 00:23:06 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Wed, 1 Oct 2003 04:45:43 UTC
Posts: 9633

Last edited by Matt on Thu, 2 Feb 2006 09:18:42 UTC, edited 1 time in total.

Top

 Post subject: Posted: Thu, 2 Feb 2006 02:15:02 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Sat, 14 Jan 2006 22:40:49 UTC
Posts: 694
Location: Yountville, California
This is a tricky problem! Here is a regular expression testing program. Using it, I found all of our solutions do not work. But a combination of the three solutions does with the addition of using the start ^ and end $metacharacters. Code: #!/usr/bin/perl (print "$ARGV[1] matches $ARGV[0]\n"), exit(0) if$ARGV[1] =~ /$ARGV[0]/; print "$ARGV[1] does not match $ARGV[0]\n"; Here are some results. ~ % re "(aa)*b{0,2}" aaabb aaabb matches (aa)*b{0,2} ~ % re "(aa)*|(aa)*ba*|(aa)*ba*ba*" aaabb aaabb matches (aa)*|(aa)*ba*|(aa)*ba*ba* After trial and error, I found that excluding the odd beginning a and the 3rd b are the tough parts. Here's what I ended up with. It's pretty ugly, so I'd like to see it simplified. ~ % re "^((aa)*|(aa)*b{1,2}(a[ab]*)?)$" aabb
aabb matches ^((aa)*|(aa)*b{1,2}(a[ab]*)?)$~ % re "^((aa)*|(aa)*b{1,2}(a[ab]*)?)$" aabbb
aabbb does not match ^((aa)*|(aa)*b{1,2}(a[ab]*)?)$~ % re "^((aa)*|(aa)*b{1,2}(a[ab]*)?)$" aaab
aaab does not match ^((aa)*|(aa)*b{1,2}(a[ab]*)?)$Last edited by Bilbo on Sat, 26 Feb 2011 22:16:35 UTC, edited 1 time in total. Top  Post subject: Posted: Thu, 2 Feb 2006 05:15:03 UTC  Senior Member Joined: Mon, 21 Jun 2004 15:56:08 UTC Posts: 69 Sorry about the misinterpretation part. It should be start with an even number of a's, and contain no more than 2 b's. So I believe all strings include aa,aab,aabb aabaa,aabaab,aaaa aaaabb,aaaabaaaab, aaaaaa, etc... Last edited by simple on Wed, 9 Feb 2011 05:16:56 UTC, edited 2 times in total. Top  Post subject: Posted: Thu, 2 Feb 2006 08:11:01 UTC  Member of the 'S.O.S. Math' Hall of Fame Joined: Sat, 14 Jan 2006 22:40:49 UTC Posts: 694 Location: Yountville, California That's much better: ^(aa)*(ba*){0,2}$ seems to work.

The strings starting with b and containing at most two b's are included.

Last edited by Bilbo on Sat, 26 Feb 2011 22:17:04 UTC, edited 1 time in total.

Top

 Post subject: Posted: Thu, 2 Feb 2006 09:07:00 UTC
 Senior Member

Joined: Mon, 21 Jun 2004 15:56:08 UTC
Posts: 69
Hi Bilbo,

The string need to be begin with even number of a's and contains at most 2 b's...

Last edited by simple on Wed, 9 Feb 2011 05:17:04 UTC, edited 2 times in total.

Top

 Post subject: Posted: Thu, 2 Feb 2006 09:46:47 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Sat, 14 Jan 2006 22:40:49 UTC
Posts: 694
Location: Yountville, California
Hi Simple,

As I said before, 0 is an even number, so I think even the empty string fits the description (0 = even # of a's and 0 <= 2 b's). But you can change 1 character to get the result you want. I'll leave that to you.

Thanks for the posting the question. I got something out of it.

Bilbo

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 9 posts ]

 All times are UTC [ DST ]

#### Who is online

Users browsing this forum: No registered users

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ High School and College Mathematics    Algebra    Geometry and Trigonometry    Calculus    Matrix Algebra    Differential Equations    Probability and Statistics    Proposed Problems Applications    Physics, Chemistry, Engineering, etc.    Computer Science    Math for Business and Economics Advanced Mathematics    Foundations    Algebra and Number Theory    Analysis and Topology    Applied Mathematics    Other Topics in Advanced Mathematics Other Topics    Administrator Announcements    Comments and Suggestions for S.O.S. Math    Posting Math Formulas with LaTeX    Miscellaneous
Contact Us | S.O.S. Mathematics Homepage
Privacy Statement | Search the "old" CyberBoard

users online during the last hour
Powered by phpBB © 2001, 2005-2011 phpBB Group.
Copyright © 1999-2013 MathMedics, LLC. All rights reserved.
Math Medics, LLC. - P.O. Box 12395 - El Paso TX 79913 - USA