A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,14 @@
|
|||
object Generators {
|
||||
def main(args: Array[String]): Unit = {
|
||||
def squares(n:Int=0):Stream[Int]=(n*n) #:: squares(n+1)
|
||||
def cubes(n:Int=0):Stream[Int]=(n*n*n) #:: cubes(n+1)
|
||||
|
||||
def filtered(s:Stream[Int], c:Stream[Int]):Stream[Int]={
|
||||
if(s.head>c.head) filtered(s, c.tail)
|
||||
else if(s.head<c.head) Stream.cons(s.head, filtered(s.tail, c))
|
||||
else filtered(s.tail, c)
|
||||
}
|
||||
|
||||
filtered(squares(), cubes()) drop 20 take 10 print
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
def filtered2(s:Stream[Int], c:Stream[Int]):Stream[Int]=(s, c) match {
|
||||
case (sh#::_, ch#::ct) if (sh>ch) => filtered2(s, ct)
|
||||
case (sh#::st, ch#::_) if (sh<ch) => sh #:: filtered2(st, c)
|
||||
case (_#::st, _) => filtered2(st, c)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue