KleveR_

Untitled

Oct 25th, 2020
112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. object Zad1 extends App {
  2.  
  3.   @annotation.tailrec
  4.   def jestPierwsza(n : Int, i : Int = 2) : Boolean = {
  5.     if (n == i) true
  6.     else if (n % i == 0) false
  7.     else jestPierwsza(n, i + 1)
  8.   }
  9.  
  10.   val result = jestPierwsza(4)
  11.   println(s" => $result")
  12.  
  13. }
  14. // ===============================
  15. object Zad2 extends App {
  16.  
  17.   def ciąg(n: Int): Int = {
  18.   if (n < 0) -1
  19.   else {
  20.     @annotation.tailrec
  21.     def rekOgon(n: Int, arg1: Int, arg2: Int): Int = {
  22.       if (n == 0) arg2
  23.       else rekOgon(n - 1, arg1 = arg1 + arg2, arg2 = arg1)
  24.     }
  25.     rekOgon(n, arg1 = 1, arg2 = 0)
  26.   }
  27. }
  28.  
  29.   val result = ciąg(7)
  30.   println(s" => $result")
  31.  
  32. }
  33.  
  34. // ===============================
  35. object Zad3 extends App {
  36.  
  37.  def uporządkowana(tab: Array[Int], mlr: (Int, Int) => Boolean) : Boolean = {
  38.     if (tab.length <= 1) true
  39.     else if (!mlr(tab.head, tab.tail(0))) false
  40.     else uporządkowana(tab.tail, mlr)
  41.   }
  42.  
  43.   def desc = (a: Int, b:Int) => a >= b
  44.   def asc = (a: Int, b:Int) => a <= b
  45.  
  46.   val tab1 = Array(1, 2, 3, 4, 5)
  47.   val tab2 = Array(3, 2, 2, -1, -2)
  48.  
  49.   println(s"#[tab1 | asc]: ${uporządkowana(tab1, asc)}")
  50.   println(s"#[tab1 | desc]: ${uporządkowana(tab1, desc)}")
  51.   println(s"#[tab2 | asc]: ${uporządkowana(tab2, asc)}")
  52.   println(s"#[tab2 | desc]: ${uporządkowana(tab2, desc)}")
  53.  
  54. }
  55.  
  56.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×