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)

1. kodutöö

NB! Moodle-s on selle kodutöö lahenduse mall

Implementeeri järgnevad funktsioonid:

{$i(x) = x$}

{$p(n,k) = \underbrace{n \cdot (n-1) \cdot \ldots \cdot (n-(k-1))}_{k \text{ tegurit}} $}

{$c(n,k) = \binom{n}{k} $}

Kus binoomkordaja leidmiseks kasutada reegleid

  • {$\binom{n}{0} = \binom{n}{n} = 1$}
  • {$\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}, \quad\text{kui $1\leq{}k\leq n-1$ } $}

{$\begin{align*} d(x,y) ={} &{} f(x,0)\\ &{} \text{kus} \quad f(n,z) = \begin{cases} z & \text{kui }n < y\\ f(n-y,z+1)& \text{muidu} \end{cases} \end{align*}$}

Järgnev ülesanne implemeteerib pikka täisarvulist jagamist. Korduvad arvutused on soovitatav teha leti või where-ga.

{$\begin{align*} \text{mydiv}(n,d) = &{} \begin{cases} \texttt{error("invalid argument")} & n<0 \lor d<0\\ \texttt{error("division by zero")} & d = 0\\ f(0, 0, \texttt{finiteBitSize n} - 1) & \text{muidu} \end{cases}\\ &\text{kus} \quad f(r, q, i) = \begin{cases} q & \text{kui } i = -1 \\ f(2*r + g(n, i)-d, q + 2^i, i-1) & \text{kui } 2*r + g(n, i) >= d\\ f(2*r + g(n, i), q, i-1) & \text{muidu} \end{cases}\\\\ &{}\text{ja}\quad g(i, n) = \texttt{shiftR i n .&. 1} \end{align*} $}

Trükimasina-kirjas avaldised kasutavad Haskelli funktsioone (error, shiftR, finiteBitSize, .&.) --- need kohad kirjutada täpselt nii, kuis ette antud. Lisada faili päisesse import Data.Bits .) Astendamine teha operaatoriga ^.

  • 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