Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
fp2023:lab02 [2023/03/10 13:20]
pdmatei
fp2023:lab02 [2024/03/15 10:48] (current)
pdmatei
Line 18: Line 18:
 } }
 </​code>​ </​code>​
 +
  
 **2.2.** Implement a tail-recursive function that computes the greatest common divisor of a natural number: **2.2.** Implement a tail-recursive function that computes the greatest common divisor of a natural number:
Line 24: Line 25:
 def gcd(a: Int, b: Int): Int = ??? def gcd(a: Int, b: Int): Int = ???
 </​code>​ </​code>​
 +
  
 **2.3.** Write a tail-recursive function takes an integer $math[n] and computes the value $math[1 + 2^2 + 3^2 + ... + (n-1)^2 + n^2]. (Hint: use inner functions). **2.3.** Write a tail-recursive function takes an integer $math[n] and computes the value $math[1 + 2^2 + 3^2 + ... + (n-1)^2 + n^2]. (Hint: use inner functions).