0
Your task is to create a regular expression that matches most binary numbers with an even number of 0
s and an odd number of 1
s (e.g. "101100011"
).
The full criteria for the regex are:
- matches 90% or more of all binary numbers between
0
and11111111
with even number of0
s and an odd number of1
s, - doesn't match 90% or more of all binary numbers between
0
and11111111
with odd number of0
s or an even number of1
s, - works in most common programming languages.
Ideally, it should be short and creative.
The input string always has a length that is greater than 1, less than infinity, and only contains 1
s and 0
s.
I will upvote any answer that seriously attempts to match the above criteria. Once the activity around this question dies down, I'll accept the highest-voted answer that is at least only 1.333... times the length of the shortest answer.
http://stackoverflow.com/q/20485486/1223693 – Doorknob – 2013-12-23T14:13:37.993
@DoorknobofSnow shhhhh – The Guy with The Hat – 2013-12-23T14:14:03.773
3Maybe I don't understand the problem, but there are none which can match. All binaries you assume as input are exactly 8 bits long (your examples indicate that leading zeros are provided) and thus odd+even cannot be true at all. – Howard – 2013-12-23T15:55:06.280
1Moreover: short and creative doesn't sound very objective. If it is popularity-contest please tag it accordingly. (note: I don't think that this is a good example of a popularity-contest). – Howard – 2013-12-23T15:56:17.790
As @Howard points out, the 8-bit range specific criteria are impossible, but that would still appear to leave the initial statement of "most binary numbers with an even number of 0s and an odd number of 1s", later qualified with length "greater than 1, less than infinity." I take most to mean >50%. – Darren Stone – 2013-12-23T16:55:47.047
@Howard Thanks for noticing that. I feel stupid now. – The Guy with The Hat – 2013-12-23T20:45:47.693
1I think there is a missing specification of "without leading zeroes" here, which would allow for 8-bit binary numbers <1111101 to match the target pattern. – Iszi – 2013-12-23T21:20:08.367
Remaining thoughts... Opening sentence suggests 9-bit numbers are in scope, while the "full criteria" section limits itself to 8-bits, but then later I read that input strings can be binary strings of infinite length. These are not strictly conflicting, but it's a bit of a head-scratcher. I would also suggest removing the word "most" in the opening sentence (since it suggests a portion of more than 50%) of even 0-count and odd 1-count (of any length, apparently at least 9 bits in the example string) but that is not emphasized again. – Darren Stone – 2013-12-24T04:42:42.543