updated jars
authorChristian Urban <christian.urban@kcl.ac.uk>
Thu, 03 Nov 2022 09:55:11 +0000
changeset 431 ef68136b9a96
parent 430 274c865b3878
child 432 de701b64a4e0
updated jars
core_solution1/collatz.jar
core_solution2/docdiff.jar
core_solution3/postfix.jar
core_solution3/postfix2.jar
core_templates1/collatz.jar
core_templates2/docdiff.jar
core_templates3/postfix.jar
core_templates3/postfix2.jar
cws/main_cw01.pdf
cws/main_cw01.tex
main_solution1/drumb.jar
main_solution1/drumb.scala
main_solution3/re.jar
main_solution4/knight3.scala
main_templates1/drumb.jar
main_templates2/wordle.jar
main_templates3/re.jar
main_templates4/README.md
main_templates4/knight1.jar
main_templates4/knight2.jar
main_templates4/knight3.jar
main_templates4/knight4.jar
main_templates5/bf.jar
main_templates5/bfc.jar
Binary file core_solution1/collatz.jar has changed
Binary file core_solution2/docdiff.jar has changed
Binary file core_solution3/postfix.jar has changed
Binary file core_solution3/postfix2.jar has changed
Binary file core_templates1/collatz.jar has changed
Binary file core_templates2/docdiff.jar has changed
Binary file core_templates3/postfix.jar has changed
Binary file core_templates3/postfix2.jar has changed
Binary file cws/main_cw01.pdf has changed
--- a/cws/main_cw01.tex	Wed Nov 02 21:49:42 2022 +0000
+++ b/cws/main_cw01.tex	Thu Nov 03 09:55:11 2022 +0000
@@ -206,7 +206,13 @@
   \end{verbatim}
 
   as profit for that year, and our new balance for 2011 is \$125 when
-  converted to a \texttt{Long}.\mbox{}\hfill\mbox{[1 Mark]}
+  converted to a \texttt{Long}. Since \texttt{yearly\_yield} should
+  produce a \texttt{Long}, there are a number of ways how to round
+  doubles.  One way to do the calculation is to calculate the profit
+  first as \texttt{Double}, and then round the result down to a \texttt{Long}
+  (using \texttt{.toLong}) and add it to the balance (which is also a
+  \texttt{Long}).\\
+  \mbox{}\hfill\mbox{[1 Mark]}
   
 \item[(7)] Write a function that calculates the overall balance
   for a range of years where each year the yearly profit is compounded to
@@ -237,9 +243,9 @@
 of companies that went bust or were de-listed over the years.
 So where does this leave our fictional character Mr T.~Drumb? Well, given
 his inheritance, a really dumb investment strategy would have done
-equally well, if not much better. And one would assume this guy is
-by now locked up in prison and the key thrown away, but alas he
-is still around annoying commonsense people.\medskip
+equally well, if not much better. Anyhow, one would assume that this
+guy is by now locked up in a prison and the key thrown away, but alas he
+is still around annoying commonsense people. What a pity.\medskip
 
 \end{document}
 
Binary file main_solution1/drumb.jar has changed
--- a/main_solution1/drumb.scala	Wed Nov 02 21:49:42 2022 +0000
+++ b/main_solution1/drumb.scala	Thu Nov 03 09:55:11 2022 +0000
@@ -123,40 +123,14 @@
 
 def yearly_yield(data: List[List[Option[Double]]], balance: Long, index: Int): Long = {
   val somes = data(index).flatten
-  println(s"somes: $somes")
   val somes_length = somes.length
   if (somes_length == 0) balance
   else {
     val portion: Double = balance.toDouble / somes_length.toDouble
-    println(s"portion: $portion")
-    val b = balance + (for (x <- somes) yield (x * portion)).sum.toLong
-    println(s"balance $b")
-    println(s"profit ${(for (x <- somes) yield (x * portion)).sum}")
-    b
+    balance + (for (x <- somes) yield (x * portion)).sum.toLong
   }
 }
 
-val dd = List(List(Some(0.9)), List(Some(0.9)))
-yearly_yield(dd, 100, 0)
-
-def yearly_yield2(data: List[List[Option[Double]]], balance: Long, index: Int) : Long = {
-
-    val share = balance/data(index).flatten.size.toDouble
-    println(s"portion: $share")
-    def count(data: List[Option[Double]], prof: Double, share: Double) : Double = data match{
-        case Nil => prof
-        case x::rest  => count(rest,prof + (x.getOrElse(0.0) * share), share)
-    }
-    val balance_double = count(data(index), 0.0, share)
-    println(balance_double)
-    println(s"balance ${balance_double + balance}")
-    println(s"profit $balance_double")
-    //if (balance_double >= balance_double.toLong.toDouble+0.5) (balance_double + 1).toLong else balance_double.toLong
-    (balance_double.toLong + balance)
-}
-
-yearly_yield2(dd, 100, 0)
-
 // test case using the deltas calculated above
 //println("Task 6 yield from Google and Apple in 2010 with  balance 100")
 
@@ -166,7 +140,6 @@
 
 
 //val goog_aapl_yield = yearly_yield(goog_aapl_deltas, 100, 0)
-//val goog_aapl_yield = yearly_yield2(goog_aapl_deltas, 100, 0)
 //println("Rounded yield: " ++ goog_aapl_yield.toString ++ "\n")
 
 
@@ -188,20 +161,10 @@
   }
 }
 
-def compound_yield2(data: List[List[Option[Double]]], balance: Long, index: Int): Long = {
-  if (index >= data.length) balance else {
-    val new_balance = yearly_yield2(data, balance, index)
-    compound_yield2(data, new_balance, index + 1)
-  }
-}
-
 def investment(portfolio: List[String], years: Range, start_balance: Long): Long = {
   compound_yield(get_deltas(get_prices(portfolio, years)), start_balance, 0)
 }
 
-def investment2(portfolio: List[String], years: Range, start_balance: Long): Long = {
-  compound_yield2(get_deltas(get_prices(portfolio, years)), start_balance, 0)
-}
 
 
 //test cases for the two portfolios given above
@@ -213,25 +176,6 @@
 }
 
 
-investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2000, 100)
-investment2(List("GOOG", "AAPL", "BIDU"), 2000 to 2000, 100)
-
-investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2001, 100)
-investment2(List("GOOG", "AAPL", "BIDU"), 2000 to 2001, 100)
-
-investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2002, 100)
-investment2(List("GOOG", "AAPL", "BIDU"), 2000 to 2002, 100) 
-
-investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2003, 100)
-investment2(List("GOOG", "AAPL", "BIDU"), 2000 to 2003, 100) 
-
-investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2004, 100) 
-investment2(List("GOOG", "AAPL", "BIDU"), 2000 to 2004, 100) 
-
-investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2005, 100) 
-investment2(List("GOOG", "AAPL", "BIDU"), 2000 to 2005, 100) 
-
-
 
 
 
@@ -248,3 +192,5 @@
 
 
 
+
+
Binary file main_solution3/re.jar has changed
--- a/main_solution4/knight3.scala	Wed Nov 02 21:49:42 2022 +0000
+++ b/main_solution4/knight3.scala	Thu Nov 03 09:55:11 2022 +0000
@@ -69,5 +69,5 @@
 }
 
 
-val dim = 30 //75
-M4c.print_board(dim, M4c.tour_on_mega_board(dim, List((0, 0))).get)
+//val dim = 30 //75
+//M4c.print_board(dim, M4c.tour_on_mega_board(dim, List((0, 0))).get)
Binary file main_templates1/drumb.jar has changed
Binary file main_templates2/wordle.jar has changed
Binary file main_templates3/re.jar has changed
--- a/main_templates4/README.md	Wed Nov 02 21:49:42 2022 +0000
+++ b/main_templates4/README.md	Thu Nov 03 09:55:11 2022 +0000
@@ -5,4 +5,5 @@
 * reference jar:
      [knight1.jar](https://nms.kcl.ac.uk/christian.urban/knight1.jar),
      [knight2.jar](https://nms.kcl.ac.uk/christian.urban/knight2.jar),
-     [knight3.jar](https://nms.kcl.ac.uk/christian.urban/knight3.jar)
\ No newline at end of file
+     [knight3.jar](https://nms.kcl.ac.uk/christian.urban/knight3.jar),
+     [knight4.jar](https://nms.kcl.ac.uk/christian.urban/knight4.jar)
\ No newline at end of file
Binary file main_templates4/knight1.jar has changed
Binary file main_templates4/knight2.jar has changed
Binary file main_templates4/knight3.jar has changed
Binary file main_templates4/knight4.jar has changed
Binary file main_templates5/bf.jar has changed
Binary file main_templates5/bfc.jar has changed