Institute of Computer Science
  1. Courses
  2. 2019/20 fall
  3. Programming Languages (MTAT.03.006)
ET
Log in

Programming Languages 2019/20 fall

  • Info
  • Õppekava
  • Moodle
  • Loengud & Praksid
  • Lisamaterjalid
  • Küsi abi! (Fleep)

Teine kodutöö

NB! Kodutöö ülesande rekursiivne osa tuleb lahendada lihtrekursiooniga, mitte standardfunktsioone kasutades.

1. Ülesanne (2/5 punkti)

Tagastab paaride listide esimesed elemendid (samas järjekorras).

Näiteks:

esimesed [] ==> []
esimesed [(2,3),(6,4),(9,9)] ==> [2,6,9]
esimesed :: [(Int,Int)] -> [Int]
esimesed xs = undefined

2. Ülesanne (2/5 punkti)

Tagastab True, kui arv leidub listis, muidu False.

otsi 3 [1,2,3,4,5,6] ==> True
otsi 8 [1,2,3,4,5,6] ==> False
otsi :: Integer -> [Integer] -> Bool
otsi n xs = undefined

3. Ülesanne (2/5 punkti)

dropLast eemaldab viimase elemendi

Näiteks:

dropLast []        ==> []
dropLast [1,2,3]   ==> [1,2]
dropLast [3,2,1,0] ==> [3,2,1]
dropLast :: [Integer] -> [Integer]
dropLast xs = undefined

4. Ülesanne (2/5 punkti)

Tähe lisamine sõnesse. Kusjuures nulli või negatiivse indeksiga pannakse täht algusse, suurema indeksiga, kui sõne pikkus, lõppu. Näiteks

lisa (-1) 'a' "xyz" ==> "axyz"
lisa 1    'a' "xyz" ==> "xayz"
lisa 3    'a' "xyz" ==> "xyza"
lisa 2    'a' "xyz" ==> "xyaz"
lisa 400  'a' "xyz" ==> "xyza"
lisa :: Int -> Char -> [Char] -> [Char]
lisa n x ys = undefined

5. Ülesanne (2/5 punkti)

Polünoomi arvutamine kohal x. Iga listi element (a,n) tähistab polynoomi liidetavat a*x^n. Näiteks: [(4.0,2),(1.0,1),(30.0,0)] tähendab 4*x^2 + x + 30

arvuta [(4.0,2),(1.0,1),(30.0,0)] 5 ==> 135.0
arvuta [(4.0,2),(1.0,1),(30.0,0)] 2 ==> 48.0
arvuta []                         5 ==> 0
arvuta :: [(Double,Int)] -> Double -> Double
arvuta p x = undefined
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment