You are on page 1of 4

Ishu Dharmendra Garg (CS13B060)

Paradigms of Programming
Assignment

Programming In haskell Not So Hard


Code less get More

Abstract
The motive was to show that all what we have done in C or C++ can be done in haskell
too. So all of the programs I implemented were either taken from a programming contest
or were given to me during our programming lab sessions (which were in C or Java). Also
all the modules are user interactive to show that they are no different from the normal c
programs.

Problem 1 - Sieve Of Eratosthenes


Problem:

To find the all the primes between any two positive numbers.

Motive :

To show how compact coding can be in haskell. This also shows how easily

a numerical problem can be solved in Haskell.

Implementation and Learning:

The program takes two integers from the user and

prints the primes numbers between them. I implemented this using sieve of
eratosthenes. Here I used Infinite lists, recursion and guarded functions.

Problem 2 - Special Permutation of 1 to n


Problem:

Given a positive integer n, find a permutation of numbers from 1 to n such

that for any two numbers in the permutation there does not exist their mean between
them.

Motive :

To show how Divide and Conquer can be implemented in Haskell.

Implementation and Learning:

The program takes a integers from the user and prints

the permutation between from 1 to n with the property specified above. I implemented
this using recursion and divide and conquer programming methods. Here I used higher
order functions, recursion, guarded functions and lambda functions.

Problem 3 - Matrix Multiplication Problem


Problem:

Given a sequence of arrays the program finds the minimum cost of

multiplication of the arrays using dynamic programming. The cost is number of the
multiplications done during the multiplication of the matrices.

Motive :

To show how dynamic programming can be implemented in Haskell. Also

how arrays can be used in haskell is shown in the implementation.

Implementation and Learning:

The program takes a list of integers from the user.

These list represents the dimensions of the matrices and gives out the minimum cost of
multiplication. I implemented this using recursion and dynamic programming methods
using arrays. Here I used higher order functions, recursion, guarded functions and
Arrays.

Problem 4 - Binary Tree (types and its height)


Problem:

Given a list of integers, convert this list and make three types of trees left

skewed, right skewed and balanced. Also find the height of the each tree.

Motive :

To show how data types can be used in Haskell.

Implementation and Learning:

The program takes list and makes three types of

binary trees which are - totally left skewed, totally right skewed and balanced. It also
prints the height of the tree made. Here I used recursion, guarded functions and Data
types.

Problem 5 - Check for binary search Tree


Problem:

Given a binary tree find whether it is a binary search tree or not. Also find

the size of the maximum sized subtree that is a binary search tree.

Motive :

To show how a algorithms on trees can be implemented in haskell.

Implementation and Learning:

The program takes list and makes three types of

binary trees which are - totally left skewed, totally right skewed and balanced. It checks
whether the binary tree made is a binary search tree or not and then it prints the size of
the maximum sized subtree that is a binary search tree. Here I used recursion, guarded
functions and Data types.

Problem 6 - KeyBoard Words


Problem:

Given a word find whether it is a left hand, right hand or alternate hand

word.

Motive :

To show how input output intensive programs can be written in Haskell.

Implementation and Learning:

The program takes a word and a choice from the user .

According to the choice the program checks whether the word belongs to a specific type
or not. Word can be of types left - written by only left hand, right - written by right hand
only or is an alternate hand word. Here I used recursion, guarded functions and several
IO functions.

You might also like