# HG changeset patch # User Christian Urban # Date 1478523315 0 # Node ID 0ce25f8164143ba01a55e3d3767cadf93e9817e6 # Parent 4703aebadd236f35df38bc074a666cbc0d4c8d59 updated diff -r 4703aebadd23 -r 0ce25f816414 progs/lecture1.scala --- a/progs/lecture1.scala Mon Nov 07 12:11:54 2016 +0000 +++ b/progs/lecture1.scala Mon Nov 07 12:55:15 2016 +0000 @@ -4,107 +4,6 @@ // maps // recursion // webpages - - -//**Assignment (values)** -//======================= -val x = 42 -val y = 3 + 4 - - -//**Collections** -//=============== -List(1,2,3,1) -Set(1,2,3,1) - -1 to 10 -(1 to 10).toList - -(1 until 10).toList - - -//**Printing/Strings** -//==================== - -println("test") -val tst = "This is a " + "test" -println(tst) - -val lst = List(1,2,3,1) - -println(lst.toString) -println(lst.mkString("\n")) - -// some methods take more than one argument -println(lst.mkString("[",",","]")) - -//**Conversion methods** -//====================== - -List(1,2,3,1).toString -List(1,2,3,1).toSet -"hello".toList -1.toDouble - -//**Types** -//========= - -// Int, Long, BigInt -// String, Char -// List[Int], Set[Double] -// Pairs: (Int, String) -// List[(BigInt, String)] +// string interpolations -//**Smart Strings** -//================= - - -//**Pairs/Tuples** -//================ - -val p = (1, "one") -p._1 -p._2 - -val t = (4,1,2,3) -t._4 - -//**Function Definitions** -//======================== - -def square(x: Int): Int = x * x - -//**Ifs control structures** -//========================== - -def fact(n: Int): Int = - if (n == 0) 1 else n * fact(n - 1) - - -def fact2(n: BigInt): BigInt = - if (n == 0) 1 else n * fact2(n - 1) - -def fib(n: Int): Int = - if (n == 0) 1 else - if (n == 1) 1 else fib(n - 1) + f(n - 2) - - -//a recursive function -def gcd(x: Int, y: Int): Int = 2 //??? - - - -//**Assert/Testing** -==================== - -//**For-Maps (not For-Loops)** -//============================ - -for (n <- (1 to 10).toList) yield square(n) - -for (n <- (1 to 10).toList; m <- (1 to 10).toList) yield m * n - -val mtable = for (n <- (1 to 10).toList; m <- (1 to 10).toList) yield m * n - -mtable.sliding(10,10).toList.mkString( diff -r 4703aebadd23 -r 0ce25f816414 progs/lecture2.scala --- a/progs/lecture2.scala Mon Nov 07 12:11:54 2016 +0000 +++ b/progs/lecture2.scala Mon Nov 07 12:55:15 2016 +0000 @@ -1,1 +1,2 @@ // sudoku +// some none