COL100 Assignment 5: 1 Play With Grid
COL100 Assignment 5: 1 Play With Grid
Example:
8 1 6
3 5 7
4 9 2
1
1. write a python program which takes a grid(list of lists) MxN as an
input and returns a single integer representing the minimum penalty
Rishabh has to face so he can complete the game. [Hint: use Dynamic
Programming]
2. Give a worst case polynomial time complexity.
3. Prove all your assertions and invariants.
2 String Problem
Given two string A and B consisting of lower case letters, find if A can be
converted to B with minimum number of edits as follows:
1. Insert a character in A.
2. Delete a character from A.
3. Replace a character in A subject to restriction: (a) a vowel can be
replaced with only a vowel, (b) a consonant may be replaced with
either vowel or consonant.
Let us explain with the help of an example. Let Input:A= “bplpcd” and
B= “apple” then edits performed are:
1. A[0] is a consonant & B[0] is a vowel. A[0] is changed to vowel i.e
“bplpcd” → “aplpcd”.
2. A[2] & B[2] are both consonants. A[2] is changed to B[2] i.e “aplpcd”
→ “apppcd”.
3. A[3] & B[3] are both consonants. A[3] is changed to B[3] i.e. “apppcd”
→ “applcd”.
4. A[4] is a consonant & B[4] is a vowel. A[4] is changed to vowel i.e.
“applcd” → “appled”. Changes made = 4
5. A[5] is a consonant & B has ended. Remove A[5] i.e “appled” →
“apple”. Changes made = 5
Even though there are multiple answers to the same inputs, your output
must be the smallest number of changes that will change A into B.
2
1. Write a program in python which returns a number of changes that
have to be performed to convert string A into B
2. Give a worst case time complexity.
3. Prove all your assertions and invariants.
3 Calendar Problem
Let us print out a calendar. Given a year, our target is to print a calendar
to a text file in a formatted way. The calendar must print all 12 months
and days of the week in a single page in a nice formatted manner that one
can print for use. You do not need to mark holidays. See example calendar
below (Notice the text formatting, ignore fonts).
You need to correctly compute the day for 1st of January (use the wikipedia
entry of the Gregorian Calendar to figure this out.
https://en.wikipedia.org/wiki/Leap_year#Gregorian_calendar
You may assume that the input to the function is greater than 1582.
1. Write a function printCalendar(year), that takes in an integer as the
input year and creates a file calendar.txt on the system in the same
directory as your python code file.
3
The filenames of your submitted files should be exactly the same as
your entry number. For example, if your entry number is 2017CS10389,
you should name your Python file as 2017CS10389.py and your PDF file as
2017CS10389.pdf. Your submission should consist of only these two files,
uploaded individually. There should be no sub-folders or zip files in the
submission on Moodle.
Failure to comply with these submission instructions will lead to a penalty.
Please ask any queries related to the assignment on the COL100 Piazza
page (https://piazza.com/iit delhi/fall2020/col100).
4
Figure 1: Calendar