added assignment 7 ex 5
This commit is contained in:
parent
95fdbf7abf
commit
e58c399bad
26
src/Assignment7/Ex5.sc
Normal file
26
src/Assignment7/Ex5.sc
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
1
|
||||
1 1
|
||||
2 1
|
||||
1 2 1 1
|
||||
1 1 1 2 2 1
|
||||
3 1 2 2 1 1
|
||||
Next :
|
||||
1 3 1 1 2 2 2 1
|
||||
*/
|
||||
|
||||
def nextLine(current: List[Int]) : List[Int] = {
|
||||
current.foldRight(List.empty[(Int, Int)])((x, acc) => {
|
||||
(x, acc) match {
|
||||
case (a, p :: rest) if a == p._2 => (p._1 + 1, p._2) :: rest
|
||||
case _ => (1, x) :: acc
|
||||
}
|
||||
}).flatten(p => List(p._1, p._2))
|
||||
}
|
||||
|
||||
def makeSequence(start: List[Int]): LazyList[List[Int]] = {
|
||||
start #:: makeSequence(nextLine(start))
|
||||
}
|
||||
|
||||
lazy val sequence: LazyList[List[Int]] = makeSequence(List(1))
|
||||
sequence.take(7).toList
|
Loading…
x
Reference in New Issue
Block a user