100% found this document useful (1 vote)
123 views

COL100 Assignment 5: 1 Play With Grid

This document provides instructions for Assignment 5 in COL100, which is due on January 29th, 2021. It includes four programming problems - a grid path finding problem, a string editing problem, a calendar generation problem, and submission instructions. Students are required to submit solutions to the three coding problems in a Python file along with written work in a PDF file.

Uploaded by

ManikyaMayank
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
123 views

COL100 Assignment 5: 1 Play With Grid

This document provides instructions for Assignment 5 in COL100, which is due on January 29th, 2021. It includes four programming problems - a grid path finding problem, a string editing problem, a calendar generation problem, and submission instructions. Students are required to submit solutions to the three coding problems in a Python file along with written work in a PDF file.

Uploaded by

ManikyaMayank
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

COL100 Assignment 5

Due date: 29th Jan, 2021

You are required to follow general assignment guidelines as specified pre-


viously. There are three questions all of which need to be submitted.

1 Play with Grid


Rishabh is playing a board game where a M × N grid G is given with non-
negative penalty values at each point G(i, j). Rishabh starts at the top left
corner (0, 0). To complete this game, he needs to reach the opposite corner
(M − 1, N − 1). At each step he can go either vertically, horizontally or
diagonally one step in the direction of the destination (i.e. from a given cell
(i, j) Rishabh can traverse only to cells (i + 1, j) or (i, j + 1) or (i + 1, j + 1)).
Every time Rishab steps into a cell, he will face penalty of the cell he has
entered.
Rishabh objective is to pick a route with least total penalty. (Total
penalty is Sum of all the penalties in traversing cells along route)

Example:

• Input : grid =[[8,1,6],[3,5,7],[4,9,2]]


Output: 15

8 1 6
3 5 7
4 9 2

Explanation: The path 8→5→2 minimizes the total penalty.

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.

4 Submission and other logistics


As usual, you should submit two files to the Moodle assignment page.
1. One file should be a PDF file containing all your written work, i.e.
correctness and efficiency analysis, etc. This can be handwritten with
pen and paper and then scanned with your mobile, or it can be typed
on your device using MS Word or LaTeX or any other software. The
only requirement is that it should be clearly legible.
2. The other file should be a Python file containing all your code. Put
your solutions to all four programming problems into a single file, along
with any helper functions they require. We should be able to run any
of the required functions by running your code in a Python console and
then typing in a function call.

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

You might also like