KleveR_

Untitled

Nov 14th, 2020
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. object Zad1 extends App {
  2.  
  3.   def subSeq[A](seq: Seq[A], begIdx: Int, endIdx: Int): Seq[A] = seq.drop(begIdx).take(endIdx-begIdx+1)
  4.  
  5.   print(s"${subSeq(Seq(2, 3, 4, 5, 6, 7, 8, 9, 10), 1, 4)}")
  6. }
  7.  
  8.  
  9. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10.  
  11. object Zad2 extends App {
  12.  
  13.   def remElem[A](seq: Seq[A], k: Int): Seq[A] = {
  14.     seq.zipWithIndex.filter{ case (element, index) => index != k }.map(_._1)
  15.   }
  16.  
  17.   println(remElem(Seq(1, 2, 3, 4, 5), 2))
  18. }
  19.  
  20.  
  21. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22.  
  23. object Zad4 extends App {
  24.  
  25.   def freq[A](seq: Seq[A]): Seq[(A, Int)] = seq.groupBy(identity).view.mapValues(_.size).toSeq
  26.  
  27.   print(s"${freq(Seq('a','b','a','c','c','a'))}")
  28.  
  29. }
  30.  
  31. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32.  
  33. object Zad5 extends App {
  34.   def destutter[A](seq: Seq[A]): Seq[A] =
  35.     seq.foldLeft(Seq[A]()) {
  36.       case (s, e) if (s.isEmpty || s.last != e) => s :+ e
  37.       case (s, e)                               => s
  38.     }
  39.   println(destutter(Seq(1, 1, 2, 4, 4, 4, 1, 3)))
  40.  
  41. }
  42.  
  43.  
  44. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  45.  
  46. object Zad6 extends App {
  47.  
  48.   def diff[A](seq1: Seq[A], seq2: Seq[A]): Seq[A] = seq1.zip(seq2).filter{ case (s1, s2) => s1 != s2 }.map(_._1)
  49.  
  50.   println(diff(Seq(1, 2, 3),Seq(2, 2, 1, 3)))
  51. }
  52.  
  53.  
  54. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.

×