Download 02

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Location arithmetic wikipedia , lookup

History of the function concept wikipedia , lookup

Function (mathematics) wikipedia , lookup

Elementary arithmetic wikipedia , lookup

Approximations of π wikipedia , lookup

Positional notation wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Introduction to Programming – I
Assignment 1
1. Write a function oddDigits :: Int -> Int which returns the integer obtained by deleting
the digits in the even numbered positions starting from the left and assuming that the left
most position is numbered 1. For example:
oddDigits
oddDigits
oddDigits
oddDigits
3 = 3
25 = 2
2381 = 28
238 = 28
2. Write a function rotateDigits :: Int -> Int -> Int which takes two numbers m and
n as input and rotates the digits of m by n steps to the right. You may assume that none of
the digits of m is 0 and that n ≥ 0. For example:
rotateDigits
rotateDigits
rotateDigits
rotateDigits
3 7 = 3
345 1 = 534
345 4 = 534
7654 0 = 7654
3. Write a function nextab :: String -> Int which takes a string containing only charaters
’a’,’b’,’c’ and counts the number of occurances of "ab". For example:
nextab "accabccabbacb" = 2
nextab "abab" = 2
nextab "bbaaa" = 0
4. Write a function followsab :: String -> Int which takes a string containing only characters ’a’,’b’,’c’ and counts the number of occurances of patterns of the form "acc...cb".
That is count the number of occurances of ’a’ followed by 0 or more occurances of ’c’
followed by ’b’. For example:
followsab
followsab
followsab
followsab
"accabccabbacb" = 3
"acccb" = 1
"bbaaa" = 0
"acbaaccbbabaccccb" = 4
Deadline: 9.15 A.M., 5 September 2011
Submit your solution in a single file named loginid.hs via Moodle. For example if I were to submit
a solution, the file name would be kumar.hs.
Remarks: You are expected to work on these assignments individually and not in teams.
If you cheat on any assignment (and are gullible enough to be caught) you will get a fail grade in
this course. The Institute may also take other action. Clearly this will be painful for all
concerned and so please do not cheat.
1