--- a/README Sat Dec 16 23:53:28 2017 +0000
+++ b/README Mon Jan 15 23:15:34 2018 +0000
@@ -1,7 +1,13 @@
+
+CW8A
+
+(1) There is an ontime submission (with full marks) by
+ assignment20178-fahim1997, but no late submission?
+==================================
Calling ediff from the command line
--- a/TAs Sat Dec 16 23:53:28 2017 +0000
+++ b/TAs Mon Jan 15 23:15:34 2018 +0000
@@ -40,4 +40,18 @@
6 => 1 (6)
15 => 0 (16)
---------
-272 submissions
\ No newline at end of file
+272 submissions
+
+
+
+CW8, Part1 (6 marks) Part 2 (4 Marks)
+ (late) (late)
+101 => 6 (101) 180 => 4 (179)
+2 => 5 (2) 1 => 3 (1)
+125 => 4 (125) 11 => 2 (11)
+8 => 3 (8) 18 => 1 (18)
+14 => 2 (14) 63 => 0 (63)
+4 => 1 (5)
+15 => 0 (14)
+--------- ----------
+269 submissions 273 submissions (272)
\ No newline at end of file
Binary file cws/cw01.pdf has changed
--- a/cws/cw01.tex Sat Dec 16 23:53:28 2017 +0000
+++ b/cws/cw01.tex Mon Jan 15 23:15:34 2018 +0000
@@ -308,6 +308,9 @@
\frac{price_{new} - price_{old}}{price_{old}}
\]
+ If the change factor is defined, you should return it
+ as \texttt{Some(change factor)}; if not, you should return
+ \texttt{None}.
\item[(2.b)] Write a function that calculates all change factors
(deltas) for the prices we obtained under Task 1. For the running
@@ -320,7 +323,9 @@
\end{verbatim}
That means Google did a bit badly in 2010, while Apple did very well.
- Both did OK in 2011.\\
+ Both did OK in 2011. Make sure you handle the cases where a company is
+ not listed in a year. In such cases the change factor should be \texttt{None}
+ (see 2.a).\\
\mbox{}\hfill\mbox{[1 Mark]}
\item[(3.a)] Write a function that calculates the ``yield'', or
--- a/handouts/scala-ho.tex Sat Dec 16 23:53:28 2017 +0000
+++ b/handouts/scala-ho.tex Mon Jan 15 23:15:34 2018 +0000
@@ -6,6 +6,10 @@
%cheat sheet
%http://worldline.github.io/scala-cheatsheet/
+% case class, apply, unappy
+% see https://medium.com/@thejasbabu/scala-pattern-matching-9c9e73ba9a8a
+
+
\begin{document}
\section*{A Crash-Course on Scala}
--- a/progs/lecture2.scala Sat Dec 16 23:53:28 2017 +0000
+++ b/progs/lecture2.scala Mon Jan 15 23:15:34 2018 +0000
@@ -295,6 +295,41 @@
sum(add(10), 0, 2)
+
+
+// some automatic timing in each evaluation
+package wrappers {
+
+ object wrap {
+
+ def timed[R](block: => R): R = {
+ val t0 = System.nanoTime()
+ val result = block
+ println("Elapsed time: " + (System.nanoTime - t0) + "ns")
+ result
+ }
+
+ def apply[A](a: => A): A = {
+ timed(a)
+ }
+ }
+}
+
+$intp.setExecutionWrapper("wrappers.wrap")
+
+// Iteration
+
+def fib(n: Int) : Int =
+ if (n <= 1) 1 else fib(n - 1) + fib(n - 2)
+
+fib(10)
+
+
+Iterator.iterate((1,1)){ case (n: Int, m: Int) => (n + m, n) }.drop(9).next
+
+
+
+
// Function Composition
//======================
--- a/progs/mandelbrot.scala Sat Dec 16 23:53:28 2017 +0000
+++ b/progs/mandelbrot.scala Mon Jan 15 23:15:34 2018 +0000
@@ -75,8 +75,8 @@
val delta_x = (end.a - start.a) / W
val delta_y = (end.b - start.b) / H
- for (y0 <- (0 until H).par) {
- for (x0 <- (0 until W).par) {
+ for (y0 <- (0 until H)) {
+ for (x0 <- (0 until W)) {
val c = start + Complex(x0 * delta_x, y0 * delta_y)
@@ -124,10 +124,21 @@
// some more computations with example 3
val delta = (exc2 - exc1) * 0.0333
-//time_needed(
-// for (i <- (0 to 12))
-// mandelbrot(exc1 + delta * i,
-// exc2 - delta * i, 1000))
+time_needed(
+ for (i <- (0 to 12))
+ mandelbrot(exc1 + delta * i,
+ exc2 - delta * i, 1000))val exc1 = Complex(0.435396403, 0.367981352)
+val exc2 = Complex(0.451687191, 0.380210061)
+
+//time_needed(mandelbrot(exc1, exc2, 1000))
+
+// some more computations with example 3
+val delta = (exc2 - exc1) * 0.0333
+
+time_needed(
+ for (i <- (0 to 12))
+ mandelbrot(exc1 + delta * i,
+ exc2 - delta * i, 1000))
--- a/testing1/collatz.scala Sat Dec 16 23:53:28 2017 +0000
+++ b/testing1/collatz.scala Mon Jan 15 23:15:34 2018 +0000
@@ -1,5 +1,7 @@
// Part 1 about the 3n+1 conjecture
//==================================
+package CW6a
+
object CW6a {
@@ -18,3 +20,4 @@
}
+
--- a/testing1/drumb.scala Sat Dec 16 23:53:28 2017 +0000
+++ b/testing1/drumb.scala Mon Jan 15 23:15:34 2018 +0000
@@ -45,10 +45,10 @@
// test case
-val prices_fb = get_prices(List("FB"), 2012 to 2014)
-val prices_goap = get_prices(List("GOOG", "AAPL"), 2010 to 2014)
-val prices_bidu = get_prices(List("BIDU"), 2004 to 2008)
-val prices_goapfb = get_prices(List("GOOG", "AAPL", "FB"), 2010 to 2016)
+val p_fb = get_prices(List("FB"), 2012 to 2014)
+val p = get_prices(List("GOOG", "AAPL"), 2010 to 2012)
+
+val tt = get_prices(List("BIDU"), 2004 to 2008)
// (2) The first function below calculates the change factor (delta) between
// a price in year n and a price in year n+1. The second function calculates
@@ -67,11 +67,8 @@
// test case using the prices calculated above
-val deltas_fb = get_deltas(prices_fb)
-val deltas_goap = get_deltas(prices_goap)
-val deltas_bidu = get_deltas(prices_bidu)
-val deltas_goapfb = get_deltas(prices_goapfb)
-
+val d = get_deltas(p)
+val ttd = get_deltas(tt)
// (3) Write a function that given change factors, a starting balance and a year
// calculates the yearly yield, i.e. new balanace, according to our dump investment
@@ -87,85 +84,17 @@
if (somes_length == 0) balance
else {
val portion: Double = balance.toDouble / somes_length.toDouble
- (for (x <- somes) yield ((1.0 + x) * portion)).sum.toLong
- //balance + (for (x <- somes) yield (x * portion)).sum.toLong
- }
-}
-
-def yearly_yield_double(data: List[List[Option[Double]]], balance: Double, year: Int): Double = {
- val somes = data(year).flatten
- val somes_length = somes.length
- if (somes_length == 0) balance
- else {
- val portion: Double = balance / somes_length.toDouble
- balance + (for (x <- somes) yield (x * portion)).sum
+ balance + (for (x <- somes) yield (x * portion)).sum.toLong
}
}
def compound_yield(data: List[List[Option[Double]]], balance: Long, year: Int): Long = {
- println(balance)
if (year >= data.length) balance else {
val new_balance = yearly_yield(data, balance, year)
compound_yield(data, new_balance, year + 1)
}
}
-def compound_yield_double(data: List[List[Option[Double]]], balance: Double, year: Int): Long = {
- if (year >= data.length) balance.toLong else {
- val new_balance = yearly_yield_double(data, balance.toDouble, year)
- compound_yield_double(data, new_balance, year + 1)
- }
-}
-
-val prices_fb = get_prices(List("FB"), 2012 to 2014)
-val prices_goap = get_prices(List("GOOG", "AAPL"), 2010 to 2014)
-val prices_bidu = get_prices(List("BIDU"), 2004 to 2008)
-val prices_goapfb = get_prices(List("GOOG", "AAPL", "FB"), 2010 to 2016)
-
-val deltas_fb = get_deltas(prices_fb)
-val deltas_goap = get_deltas(prices_goap)
-val deltas_bidu = get_deltas(prices_bidu)
-val deltas_goapfb = get_deltas(prices_goapfb)
-
-
-yearly_yield(deltas_bidu, 100, 0)
-yearly_yield(deltas_bidu, 100, 1)
-yearly_yield(deltas_bidu, 100, 2)
-yearly_yield(deltas_bidu, 192, 3)
-//598
-
-yearly_yield(deltas_fb, 100, 0)
-yearly_yield(deltas_fb, 100, 1)
-//yearly_yield(deltas_fb, 195, 2)
-
-yearly_yield(deltas_goap, 100, 0)
-yearly_yield(deltas_goap, 125, 1)
-yearly_yield(deltas_goap, 146, 2)
-yearly_yield(deltas_goap, 177, 3)
-//yearly_yield(deltas_goap, 227, 4)
-
-yearly_yield(deltas_goapfb, 100, 0)
-yearly_yield(deltas_goapfb, 125, 1)
-yearly_yield(deltas_goapfb, 146, 2)
-yearly_yield(deltas_goapfb, 177, 3)
-yearly_yield(deltas_goapfb, 267, 4)
-yearly_yield(deltas_goapfb, 337, 5)
-//416
-
-compound_yield(deltas_goapfb.take(1), 100, 0)
-compound_yield(deltas_goapfb.take(2), 100, 0)
-compound_yield(deltas_goapfb.take(3), 100, 0)
-compound_yield(deltas_goapfb.take(4), 100, 0)
-compound_yield(deltas_goapfb.take(5), 100, 0)
-compound_yield(deltas_goapfb.take(6), 100, 0)
-
-compound_yield_double(deltas_goapfb.take(1), 100.0, 0)
-compound_yield_double(deltas_goapfb.take(2), 100.0, 0)
-compound_yield_double(deltas_goapfb.take(3), 100.0, 0)
-compound_yield_double(deltas_goapfb.take(4), 100.0, 0)
-compound_yield_double(deltas_goapfb.take(5), 100.0, 0)
-compound_yield_double(deltas_goapfb.take(6), 100.0, 0)
-
//yearly_yield(d, 100, 0)
//compound_yield(d.take(6), 100, 0)
@@ -183,18 +112,6 @@
compound_yield(get_deltas(get_prices(portfolio, years)), start_balance, 0)
}
-def investment_double(portfolio: List[String], years: Range, start_balance: Long): Long = {
- compound_yield_double(get_deltas(get_prices(portfolio, years)), start_balance.toDouble, 0)
-}
-
-
-investment(rstate_portfolio, 1978 to 2017, 100)
-investment(blchip_portfolio, 1978 to 2017, 100)
-
-investment_double(rstate_portfolio, 1978 to 2017, 100)
-investment_double(blchip_portfolio, 1978 to 2017, 100)
-
-
/*
val q1 = get_deltas(get_prices(List("GOOG", "AAPL", "BIDU"), 2000 to 2017))
yearly_yield(q1, 100, 0)
--- a/testing3/bf.scala Sat Dec 16 23:53:28 2017 +0000
+++ b/testing3/bf.scala Mon Jan 15 23:15:34 2018 +0000
@@ -48,7 +48,7 @@
}
}
-
+//jumpLeft("[******]***", 7, 0)
// (2c) Complete the run function that interpretes (runs) a brainf***
// program: the arguments are a program, a program counter,
@@ -172,6 +172,284 @@
[<+>-[<+>-[<+>-[<[-]>>[-]+>+<<-]]]]]]]]]]<[>+<-]+>>]<<[<<]>>]""", Map())
+start("""+++++[>+++++++++<-],[[>--.++>+<<-]>+.->[<.>-]<<,]""", Map())
+
*/
+
+def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match {
+ case (Nil, acc) => acc
+ case (c :: cs, Nil) => splice(cs, List((c, 1)))
+ case (c :: cs, (d, n) :: acc) =>
+ if (c == d) splice(cs, (c, n + 1) :: acc)
+ else splice(cs, (c, 1) :: (d, n) :: acc)
}
+
+def spl(s: String) = splice(s.toList, Nil).reverse
+
+
+// simple instructions
+def instr(c: Char) : String = c match {
+ case '>' => "ptr++;"
+ case '<' => "ptr--;"
+ case '+' => "(*ptr)++;"
+ case '-' => "(*ptr)--;"
+ case '.' => "putchar(*ptr);"
+ case ',' => "*ptr = getchar();\n"
+ case '[' => "while(*ptr){"
+ case ']' => "}"
+ case _ => ""
+}
+
+def instrs(prog: String) : String =
+ prog.toList.map(instr(_)).mkString
+
+
+//optimised instructions
+
+def instr2(c: Char, n: Int) : String = c match {
+ case '>' => "ptr += " + n.toString + ";"
+ case '<' => "ptr -= " + n.toString + ";"
+ case '+' => "(*ptr) += " + n.toString + ";"
+ case '-' => "(*ptr) -= " + n.toString + ";"
+ case '.' => "putchar(*ptr);" * n
+ case ',' => "*ptr = getchar();\n" * n
+ case '[' => "while(*ptr){" * n
+ case ']' => "}" * n
+ case _ => ""
+}
+
+def instrs2(prog: String) : String =
+ spl(prog).map{ case (c, n) => instr2(c, n) }.mkString
+
+
+// peephole optimisers are at
+// https://github.com/Wilfred/bfc#peephole-optimisations
+// http://calmerthanyouare.org/2015/01/07/optimizing-brainfuck.html
+
+def compile_str(prog: String) : String = {
+ "#include <string.h>\n" ++
+ "#include <stdio.h>\n" ++
+ "char field[30000];\n" ++
+ "char *ptr = &field[15000];" ++
+ "int main()\n{\n" ++
+ "memset(field, '\\0', 30000);\n" ++
+ instrs2(prog) ++
+ "\n return 0;\n}"
+}
+
+def compile(name: String, prog: String) = {
+ val fw = new java.io.FileWriter(name + ".c")
+ fw.write(compile_str(prog))
+ fw.close()
+}
+
+import sys.process._
+
+def compile_run(prog: String) = {
+ compile("tmp", prog)
+ "gcc -O3 -o tmp tmp.c".!
+ "./tmp".!
+ ()
+}
+
+
+compile_run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
+ ..+++.>>.<-.<.+++.------.--------.>>+.>++.""")
+
+compile_run("""++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
+ ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
+ ]>.>+[>>]>+]""")
+
+compile_run(""" A mandelbrot set fractal viewer in brainf*** written by Erik Bosman
++++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
+>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
+<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
+>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>
+>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>
+>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>
+>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>
+[>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<
+<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>+++++++++++++++[[
+>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[
+>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[
+-<<+>>]<<[->>+>>+<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>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>
+>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
+<<<<<]]>>>]""")
+
+compile_run("""
+>+>+>+>+>++<[>[<+++>-
+
+ >>>>>
+ >+>+>+>+>++<[>[<+++>-
+
+ >>>>>
+ >+>+>+>+>++<[>[<+++>-
+
+ >>>>>
+ >+>+>+>+>++<[>[<+++>-
+
+ >>>>>
+ +++[->+++++<]>[-]<
+ <<<<<
+
+ ]<<]>[-]
+ <<<<<
+
+ ]<<]>[-]
+ <<<<<
+
+ ]<<]>[-]
+ <<<<<
+
+]<<]>.""")
+
+// benchmarks
+compile_run(""">++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
+[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
+++++++++[>++++++++++[>++++++++++[>++++++++++[>+
++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.""")
+
+//
+compile_run("""++++[>++++<-]>[>+>++>[+++++++>]+++[<]>-]>>>>>>>>-.
+<<<<.<..+++.<.>>>>.<<<.+++.------.>-.<<+.<------.""")
+
+compile_run("""++++++++[->-[->-[->-[-]<]<]<]
+>++++++++[<++++++++++>-]<[>+>+<<-]>-.>-----.>""")
+
+
+
+
+// register to BF compiler
+// https://gergo.erdi.hu/blog/2010-09-06-from_register_machines_to_brainfuck,_part_1/
+}