Homework_2-sol - Homework 2 Due on Monday April 7th before...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework 2 – Due on Monday April 7 th before class CSC122 Spring 08 1. Explain what the following Haskell function does in one clear sentence. mystery([],[]) = 0; mystery([],[h:t]) = 0; mystery([h:t],[]) = 0; mystery([h1:t1],[h2:t2]) = if (h1==h2) then 1+mystery(t1,t2) else mystery(t1,t2); counts the number of elements that are the same in the same spots in both lists. 2. Write a Haskell function CountThem(x,l) that counts the number of occurrences of the symbol x in the list l. e.g. CountThem( 'A ' ,[‘A’,’ B’,’ A’,’ B’] ) is 2 countThem(item,[]) = 0; countThem(item, [x:xs]) = if(x==item) then 1+countThem(item, xs) else countThem(item, xs); 3. Write a HasCl function called declist that takes one parameter (a list of numbers). The function should return a list of numbers with each number one less that the corresponding number in the original list. For example, declist( [1, 2, 3, 4] ) should return [0, 1, 2, 3]. declist([]) = [];
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/17/2008 for the course COMPUTER S 221 taught by Professor Kadija during the Spring '08 term at DePauw.

Page1 / 3

Homework_2-sol - Homework 2 Due on Monday April 7th before...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online