Question: Need help step by step + will be used to denote both alternatives ( as in ( 1 + 2 ) ) and also to
Need help step by step
will be used to denote both alternatives as in
and also to denote one or more applications
of Kleene star as in a
meaning the language a
n
n You must take its application within
the context in which it is applied so you will need to use your brains!
Ranges such as all letters or all digits will be represented as a z meaning a b c d e f
g h i j k l m n o p q r s t u v w x y z Hopefully the reason
for using ranges is obvious!
Historians have long debated the role and significance of the ceremony known as Stagscratch, which
appears to have been practiced for many centuries, including at the legendary school Pigwarts.
Ceremonies took place at irregular intervals, although never on the th or st of any month, and
involved a combination of up to three of four possible instruments, being bagpipes, drums, horns,
and lutes. Records of all Stagscratch ceremonies at Pigwarts since the year have been kept in a
handwritten archive, although there appear to have been no such ceremonies since the last recorded
on on th December To save precious parchment and ink, the records of each ceremony
were kept as a string, using one character for each instrument b d h and l respectively used, and
including the date, and the instruments used in that particular ceremony. Such strings were written
as follows.
CYYMMDDSE
where
C is the century indicator
YY are the last two digits of the year of the date
MM are two digits of the month of the date
DD are two digits of the day of the date
S is the sequence of instruments used in the ceremony
E is either the character a or the character z indicating what caused the ceremony to end
Note that C is either a single character in or string of length with the first character
and the second in D is a single character in and M is a single character in
While no ceremony ever used more than three instruments, each instrument could be used any
number of times, and in any sequence, as long as at least one instrument was used. So the sequence
S can be any nonempty sequence of up to three instruments. For example, bdbdbdbh llllllllllldb
and hlhlhlhllll are all legal sequences of instruments, but lhdb and bbdhl are not because they both
contain four instruments
Scribes also had the habit of omitting the century, year, month and day from an entry if they were
the same as the previous entry. For example the entry bbbaddz indicates two ceremonies on
the nd of January in the year whereas the entry dlbdlbdlbabbbbbbbz indicates one
ceremony on th October and a second on th October
Ceremony records were written one after the other on the parchment as one enormous string. In order
to analyse the history of Stagscratch, it is necessary to write regular expressions to identify specific
matches of interest somewhere in this string. Scribes were attentive and diligent, but inevitably it
has been observed that there were occasionally errors made by scribes. This means that any regular
expressions for such purposes must be precise, and cannot assume that any given entry is errorfree.
Give a regular expression for the following cases. In each case explain your answer.
i Any ceremony taking place before the year in which neither drums nor bagpipes were
used.
ii Any ceremony in July or August after the year which began with bagpipes followed
by drums.
iii. Any syntactically correct record of a ceremony. This means the recorded entry must have
M being either or D being or include at most three instruments as above, a
correct end marker and take into account the potential omission of the dates. Anything
not syntactically correct must be an obvious error, such as the date or the
ceremony sequence bdlhnnnnq
iv Any ceremony of the th of some month in which exactly two instruments were used.
b Is it possible to give a regular expression for the following? Explain either why it is possible or
why it is not.
i Any two consecutive ceremonies which used exactly the same sequence of instruments.
ii The maximum number of times a given instrument is used in all of Pigwartss history
iii. Any year in which no ceremony ever used a bagpipe.
iv Determining when, if ever, the lute has been used more than times in history.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
