progs/lecture1.scala
changeset 15 52713e632ac0
parent 14 2d9defa8ad7f
child 18 87e55eb309ed
equal deleted inserted replaced
14:2d9defa8ad7f 15:52713e632ac0
     1 // toList, toSet, toDouble
     1 
     2 // function definition
       
     3 // smart strings
       
     4 // maps
       
     5 // recursion
       
     6 // webpages
     2 // webpages
     7 
     3 
     8 
     4 
     9 //**Assignment (values)**
     5 //**Assignment (values)**
    10 //=======================
     6 //=======================
    25 
    21 
    26 //**Printing/Strings**
    22 //**Printing/Strings**
    27 //====================
    23 //====================
    28 
    24 
    29 println("test")
    25 println("test")
       
    26 
       
    27 
    30 val tst = "This is a " + "test" 
    28 val tst = "This is a " + "test" 
    31 println(tst)
    29 println(tst)
    32 
    30 
    33 val lst = List(1,2,3,1)
    31 val lst = List(1,2,3,1)
    34 
    32 
    80 
    78 
    81 def fact(n: Int): Int = 
    79 def fact(n: Int): Int = 
    82   if (n == 0) 1 else n * fact(n - 1)
    80   if (n == 0) 1 else n * fact(n - 1)
    83 
    81 
    84 
    82 
       
    83 
       
    84 
       
    85 
    85 def fact2(n: BigInt): BigInt = 
    86 def fact2(n: BigInt): BigInt = 
    86   if (n == 0) 1 else n * fact2(n - 1)
    87   if (n == 0) 1 else n * fact2(n - 1)
    87 
    88 
    88 def fib(n: Int): Int =
    89 def fib(n: Int): Int =
    89   if (n == 0) 1 else
    90   if (n == 0) 1 else
    91 
    92 
    92 
    93 
    93 //a recursive function
    94 //a recursive function
    94 def gcd(x: Int, y: Int): Int = 2 //??? 
    95 def gcd(x: Int, y: Int): Int = 2 //??? 
    95 
    96 
       
    97 //**String Interpolations**
       
    98 //=========================
    96 
    99 
    97 
   100 
    98 //**Assert/Testing**
   101 //**Assert/Testing**
    99 ====================
   102 ====================
   100 
   103