Strictly follow the following specification to address this question:
Program/Function name: q1.py
Arguments to your program/function: Two filenames, containing:
(a) the string corresponding to txt[1...n] (without any line breaks).
(b) the string corresponding to pat[1..m] (without any line breaks).Command line usage of your script:
python q1.py <text filename> <pattern filename>
Do not hard-code the filenames/input in your function. Ensure that we will be able to run your function from a
terminal (command line) supplying any pair of text and pattern filenames as arguments. Give sufficient details in
your inline comments for each logical block of your code. Uncommented code or code with vague/sparse/insufficient
comments will automatically be flagged for a face-to-face interview with the CE before your understanding can be
ascertained.
Output file name: output q1.txt
❼ Each position where pat matches the txt should appear in a separate line. For
example, when text = abcdabcdabcd, and pattern = abc, the output should be:
1
5
9
2. Matching a pattern containing unknown characters: In this exercise you will
attempt to implement pattern matching while allowing for unknown characters within
the pattern. Here, we will use ‘!’ to represent an unknown character. Importantly,
during pattern matching an unknown character in the pattern is always considered as a
match with any possible opposing character in the text.
Specifically, let pat[1 . . . m] represent a pattern containing ≥ 0 unknown (‘!’) characters.
Let txt[1 . . . n] denote some given text; it is safe to assume that txt[1 . . . n] does not
contain any unknown characters for this exercise. Your goal is to write an efficient
python program to detect all occurrences of pat in txt, while assuming that any unknown
character in pat[1 . . . m] always matches any possible character in txt[1 . . . n].
Strictly follow the following specification to address this question:
Program/Function name: q2.py
Arguments to your program/function: Two filenames, containing:
(a) the string corresponding to txt[1...n] (without any line breaks).
(b) the string corresponding to pat[1..m] (without any line breaks, and potentially
containing zero or more ‘!’ (i.e., unknown) characters).
Command line usage of your script:
python q2.py <text filename> <pattern filename>
Do not hard-code the filenames/input in your function. Ensure that we will be able to run your function from a
terminal (command line) supplying any pair of text and pattern filenames as arguments. Give sufficient details in
your inline comments for each logical block of your code. Uncommented code or code with vague/sparse/insufficient
comments will automatically be flagged for a face-to-face interview with the CE before your understanding can be
ascertained.
Output file name: output q2.txt
❼ Each position where pat matches the txt (while considering characters in text
opposing unknown characters in the pattern as matches) should be reported in
a separate line. For example, when pat[1 . . . 7] = de!!du! and txt[1 . . . 20] =
ddedadudadededududum, the output should be: