Professional Documents
Culture Documents
Week 4-7 Nptel Haskell HRST
Week 4-7 Nptel Haskell HRST
Week 4-7 Nptel Haskell HRST
(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)
hs16052003@outlook.com
https://onlinecourses.nptel.ac.in/noc23_cs94/progassignment?name=98 1/3
9/19/23, 5:24 PM Introduction To Haskell Programming - Course
Test Case
Week 8 () f1 [1, 3, 9, 27, 81] [3,9,27,81,243] [3,9,27,81,243]\n
7
Test Case
DOWNLOAD VIDEOS f2 [] [] []\n
8
()
Test Case
f2 [1] [] []\n
Text Transcripts () 9
Test Case
f2 [1, 2, 3, 2, 1] [2,3] [2,3]\n
Books () 10
Test Case
f2 [1, 2, 3, 4, 5, 6] [] []\n
Problem Solving 11
Session - July 2023 () Test Case
f2 [6, 5, 4, 3, 2, 1] [0,1,2,3,4] [0,1,2,3,4]\n
12
Test Case f3
[1,2,3,4,5,6,7,8,9,10] [1,2,3,4,5,6,7,8,9,10]\n
20 [1,2,3,4,5,6,7,8,9,10]
f3 [1, 1, 1, 2, 2, 3,
Test Case
3, 3, 3, 4, 4, 5, 5, [1,2,3,4,5] [1,2,3,4,5]\n
21
5, 5, 5]
Test Case
f3 [1, 2, 3, 2, 1] [1,2,3,2,1] [1,2,3,2,1]\n
23
Test Case
f4 [] [] []\n
24
Test Case
f4 [5] [[5]] [[5]]\n
25
Test Case
f4 [1,2,3,4,5] [[1,2,3,4,5]] [[1,2,3,4,5]]\n
26
Test Case
f4 [5,4,3,2,1] [[5],[4],[3],[2],[1]] [[5],[4],[3],[2],[1]]\n
27
f4 [1, 1, 1, 2, 2, 3,
Test Case
3, 3, 3, 4, 4, 5, 5, [[1,1,1,2,2,3,3,3,3,4,4,5,5,5,5,5]]\n
29 [[1,1,1,2,2,3,3,3,3,4,4,5,5,5,5,5]]
5, 5, 5]
https://onlinecourses.nptel.ac.in/noc23_cs94/progassignment?name=98 2/3
9/19/23, 5:24 PM Introduction To Haskell Programming - Course
https://onlinecourses.nptel.ac.in/noc23_cs94/progassignment?name=98 3/3
WEEK 5
types, search trees () 1. Define a function subSeq :: String -> String -> Bool which checks whether
the first argument is a subsequence of the second. A subsequence is obtained by
Week 7: arrays, IO () deleting some letters in a string and retaining the other characters in the same
order as in the original string.
Week 8 ()
Test cases:
DOWNLOAD VIDEOS () subSeq "ab" "abc" = True
subSeq "ab" "acb" = True
Text Transcripts () subSeq "ab" "bca" = False
subSeq "" "bea" = True
Books () subSeq "ba" "ba" = True
Problem Solving 2. Define a function subWord :: String -> String -> Bool which checks whether
Session - July 2023 () the first argument is a subword of the second. A subword is obtained by deleting
some number (possibly 0) of letters at the left end and right end in a string
and retaining the other characters in the same order.
Test cases:
subWord "ab" "abc" = True
subWord "ab" "acb" = False
subWord "ca" "bca" = True
subWord "" "bea" = True
subWord "ba" "ba" = True
(a) Define a function isMatrix :: [[a]] -> Bool that checks if a list of lists
is a valid matrix (nonzero number of rows, each of the same nonzero length).
Test cases:
isMatrix [] = False
isMatrix [[],[],[]] = False
isMatrix [[2,3], [4,5], [6,7]] = True
isMatrix [[2,3,4,5,6,7]] = True
(b) A square matrix is one where the number of rows is equal to the number of
columns. Define a function isSquareMatrix :: [[a]] -> Bool that checks if a
list of lists is a square matrix.
Test cases:
isSquareMatrix [] = False
isSquareMatrix [[]] = False
isSquareMatrix [[1]] = True
isSquareMatrix [[1,2,3],[4,5,6],[7,8,9]] = True
isSquareMatrix [[1,2,3,4],[5,6,7,8],[9,10,11,12]] = False
(c) Two matrices are addable if they have the same number of rows and same
number of columns. Define a function addable :: [[a]] -> [[a]] -> Bool that
checks if two matrices are addable.
Test cases:
addable [[1,2],[3,4]] [[1,2],[3,4]] = True
addable [[1,2],[3,4]] [[5,6,7],[8,9,10]] = False
addable [[1,2],[3,4]] [[1,2],[3,4],[3,4]] = False
(d) Define a function addMatrices :: [[Int]] -> [[Int]] -> [[Int]] that computes
the sum of the input matrices.
Test cases:
addMatrices [[1,2]] [[3,4]] = [[4,6]]
addMatrices [[1,2],[3,4]] [[1,2],[3,4]] = [[2,4],[6,8]]
Test cases:
multiplyable [[1,2,3],[4,5,6]] [[1,2],[3,4]] = False
multiplyable [[1,2,3],[4,5,6],[1,2,3],[4,5,6]] [[1,2],[3,4],[5,6]] = True
(f) Define a function multiplyMatrices :: [[Int]] -> [[Int]] -> [[Int]] that
computes the product of the input matrices.
Test cases:
multiplyMatrices [[1,2],[3,4]] [[1,2,3],[4,5,6]] = [[9,12,15],[19,26,33]]
multiplyMatrices [[1,2,3],[4,5,6]] [[1,2],[3,4],[5,6]] = [[22,28],[49,64]]
isSquareMatrix [[1,2,3,4],[5,6,7,8],
Test Case 19 False False\n Passed
[9,10,11,12]]
multiplyable [[1,2,3],[4,5,6],[1,2,3],
Test Case 26 True True\n Passed
[4,5,6]] [[1,2],[3,4],[5,6]]
(/noc23_cs94/progassig 1. Define a function dropOdds :: Int -> Int with the following behaviour.
nment?name=100) For any positive number m, dropOdds m is got by dropping all the odd digits
in m. (If all the digits in the number are odd, the answer should be 0.)
Week 7: arrays, IO ()
Test cases:
Week 8 ()
dropOdds 0 =0
dropOdds 8 =8
DOWNLOAD VIDEOS ()
dropOdds 1357 =0
Text Transcripts ()
2. Define a function moreZeros :: Int -> Bool such that moreZeros n returns
True exactly when the binary representation of n has strictly more 0s than 1s.
Books ()
Test cases:
Problem Solving
moreZeros 0 = True
Session - July 2023 ()
moreZeros 1 = False
moreZeros 2 = False
moreZeros 4 = True
3. Define a function binToTer :: Int -> Int which takes as input the binary
representation of a number n and outputs the ternary representation of n.
(You can assume that the input consists only of the digits 0 and 1, and the
output should only consist the digits 0, 1 and 2.)
Test cases:
binToTer 0 =0
binToTer 1 =1
binToTer 11 = 10
binToTer 100 = 11
4. Define a function palindrome :: Int -> Bool which outputs True exactly when
the number is a palindrome (digits read from left to right is the same as
digits read from right to left).
Test cases:
palindrome 0 = True
palindrome 121 = True
Private Test cases used for evaluation Input Expected Output Actual Output Status
Input
Week 5: User-defined
datatypes, abstract
-----
datatypes, modules ()
abba
Level
Week 6: recursive data
Hi
types, search trees () Malayalam
Week 7 Feedback Form: Private Test cases used for evaluation Input Expected Output Actual Output Status
Introduction To Haskell
Programming (unit?
unit=55&lesson=58)
Week 7: Programming
Assignment
(/noc23_cs94/progassig
nment?name=101) Y\n
Madam Y\n
Y\n
Malayalam Y\n
Week 8 () N\n
ebba N\n
Y\n
Test Case 1 abba Y\n Passed
DOWNLOAD VIDEOS () Y\n
aBbA Y\n
N\n
Habibi N\n
Text Transcripts () Y\n
maDAm Y
\n
Books ()