Du befindest dich hier: FSI Informatik » Prüfungsfragen und Altklausuren » Prüfungen im Bachelor-Studium (1. - 5. Semester) » pfp » Lösungsversuch (Übersicht)
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige ÜberarbeitungVorherige ÜberarbeitungNächste Überarbeitung | Vorherige Überarbeitung | ||
pruefungen:bachelor:pfp:loesungws14 [21.07.2018 18:35] – evren | pruefungen:bachelor:pfp:loesungws14 [21.07.2018 19:41] (aktuell) – evren | ||
---|---|---|---|
Zeile 115: | Zeile 115: | ||
</ | </ | ||
\\ | \\ | ||
- | Alternativ | + | (ich glaube im oberen Code ist ein barrier.await() zu viel) \\ |
+ | Alternativlösung: \\ | ||
1: | 1: | ||
<code java> | <code java> | ||
Zeile 151: | Zeile 152: | ||
==== Aufgabe 5 (Scala - Listenoperationen) ==== | ==== Aufgabe 5 (Scala - Listenoperationen) ==== | ||
**a)** | **a)** | ||
- | < | + | < |
def flatten : List[(Char, Char)] => List[Char] = { | def flatten : List[(Char, Char)] => List[Char] = { | ||
case Nil => List() | case Nil => List() | ||
case t :: ts => List(t._1, t._2) ::: flatten(ts) | case t :: ts => List(t._1, t._2) ::: flatten(ts) | ||
} | } | ||
+ | </ | ||
+ | |||
+ | Alternativlösung: | ||
+ | <code scala> | ||
+ | def flatten : List[(Char, Char)] => List[Char] = { | ||
+ | case Nil => Nil | ||
+ | case (a, b) :: tailList => a :: List(b) ::: flatten(tailList) | ||
+ | } | ||
</ | </ | ||
**b)** | **b)** | ||
- | < | + | < |
def countPar : List[Char] => List[(Char, Int)] = cs => { | def countPar : List[Char] => List[(Char, Int)] = cs => { | ||
for (c <- cs) yield (c, cs.par.filter(_ == c).size) | for (c <- cs) yield (c, cs.par.filter(_ == c).size) | ||
Zeile 166: | Zeile 175: | ||
**c)** | **c)** | ||
- | < | + | < |
def distinct : List[(Char, Int)] => List[(Char, Int)] = cs => { | def distinct : List[(Char, Int)] => List[(Char, Int)] = cs => { | ||
cs.foldLeft(List[(Char, | cs.foldLeft(List[(Char, | ||
Zeile 174: | Zeile 183: | ||
==== Aufgabe 6 (Scala - Lauflängenkodierung) ==== | ==== Aufgabe 6 (Scala - Lauflängenkodierung) ==== | ||
**a)** | **a)** | ||
- | < | + | < |
def decodeTuple: | def decodeTuple: | ||
case (c, 1) => Stream(c) | case (c, 1) => Stream(c) | ||
Zeile 183: | Zeile 192: | ||
**b)** | **b)** | ||
Geht für '' | Geht für '' | ||
- | < | + | < |
def decode: Stream[(Char, | def decode: Stream[(Char, | ||
case null => Stream() | case null => Stream() | ||
Zeile 189: | Zeile 198: | ||
} | } | ||
</ | </ | ||
- | Alternativlösung: | + | Alternativlösungen: |
- | < | + | < |
def decode: Stream[(Char, | def decode: Stream[(Char, | ||
case Stream.Empty => Stream.Empty | case Stream.Empty => Stream.Empty | ||
case ts => decodeTuple(ts.head) #::: decode(ts.tail) | case ts => decodeTuple(ts.head) #::: decode(ts.tail) | ||
+ | } | ||
+ | </ | ||
+ | <code scala> | ||
+ | def decode: Stream[(Char, | ||
+ | case Stream.Empty => Stream.Empty | ||
+ | case first #:: tailList => decodeTuple(first) #::: decode(tailList) | ||
} | } | ||
</ | </ |