# HG changeset patch # User Christian Urban # Date 1553118620 0 # Node ID ecd989eee8bd30e0b096285b6a584b5ddeb02301 # Parent 5a16bcb4105eedbd7cd15559c4085c2c409af4f9 updated diff -r 5a16bcb4105e -r ecd989eee8bd LINKS --- a/LINKS Sat Feb 02 13:38:47 2019 +0000 +++ b/LINKS Wed Mar 20 21:50:20 2019 +0000 @@ -1,3 +1,33 @@ +Why functional programming? + +Nice article and pictures of multicores. + +https://sigma.software/about/media/pillars-functional-programming-part-1 + + +===================== +lectures on scala + +https://github.com/scalasummerschool/lectures + + +===================== +an argument for pure functions and programming + +https://dev.to/pietvandongen/pure-bliss-with-pure-functions-in-java-1mba + +===================== +95 hardest sudoku problems +http://www.dos486.com/sudoku/top95.txt + + +===================== +code example (bar code decoder) + +https://habr.com/en/post/439768/ + +===================== + online tutorial for scala https://hub.mybinder.org/user/sbrunk-almond-examples-yw61qxqu/lab diff -r 5a16bcb4105e -r ecd989eee8bd README --- a/README Sat Feb 02 13:38:47 2019 +0000 +++ b/README Wed Mar 20 21:50:20 2019 +0000 @@ -1,3 +1,20 @@ +chowchingjimkcl + +Assignment 6 6 (main) 4 (advanced) +Assignment 7 6 (main) 3 (advanced) +Assignment 8 6 (amin) 4 (advanced) +Assignment 9 5 (main) 4 (advanced) +Assignment 10 6 (main) 4 (advanced) + +48 + + + + + + + + scalac -Ydelambdafy:inline -d docdiff.jar docdiff.scala gerp -h // gerp without filename diff -r 5a16bcb4105e -r ecd989eee8bd cws/cw02.pdf Binary file cws/cw02.pdf has changed diff -r 5a16bcb4105e -r ecd989eee8bd cws/cw02.tex --- a/cws/cw02.tex Sat Feb 02 13:38:47 2019 +0000 +++ b/cws/cw02.tex Wed Mar 20 21:50:20 2019 +0000 @@ -8,6 +8,11 @@ \section*{Coursework 7 (Scala)} +\mbox{}\hfill\textit{``What one programmer can do in one month,}\\ +\mbox{}\hfill\textit{two programmers can do in two months.''}\smallskip\\ +\mbox{}\hfill\textit{ --- Frederick P.~Brooks (author of The Mythical Man-Month)}\bigskip + +\noindent This coursework is worth 10\%. The first and second part are due on 22 November at 11pm; the third, more advanced part, is due on 20 December at 11pm. You are asked to implement Scala programs for diff -r 5a16bcb4105e -r ecd989eee8bd handouts/pep-ho.tex --- a/handouts/pep-ho.tex Sat Feb 02 13:38:47 2019 +0000 +++ b/handouts/pep-ho.tex Wed Mar 20 21:50:20 2019 +0000 @@ -32,6 +32,14 @@ %from program fragments. +%explain graph coloring program (examples from) +%https://www.metalevel.at/prolog/optimization + + +% nice example for map and reduce using Harry potter characters +% https://www.matthewgerstman.com/map-filter-reduce/ + + \begin{document} \fnote{\copyright{} Christian Urban, King's College London, 2017, 2018} diff -r 5a16bcb4105e -r ecd989eee8bd marking1/drumb_test2.sh --- a/marking1/drumb_test2.sh Sat Feb 02 13:38:47 2019 +0000 +++ b/marking1/drumb_test2.sh Wed Mar 20 21:50:20 2019 +0000 @@ -132,15 +132,17 @@ if [ $tsts -eq 0 ] then - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100" | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 " | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 " | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 " | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 " | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113" | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254" | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349" | tee -a $out - echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 83061" | tee -a $out + echo -e " All results need to be in the range of -/+ 1% of the given values." | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100" | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 " | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 " | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 " | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 " | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113" | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254" | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349" | tee -a $out + echo -e " investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 1990 to 2017, 100) == 83061" | tee -a $out + if (scala_assert "drumb.scala" "drumb_test7.scala") then diff -r 5a16bcb4105e -r ecd989eee8bd marking2/danube_test.sh --- a/marking2/danube_test.sh Sat Feb 02 13:38:47 2019 +0000 +++ b/marking2/danube_test.sh Wed Mar 20 21:50:20 2019 +0000 @@ -6,7 +6,12 @@ out=${1:-output} -echo "" > $out +# read marks for CW7 part 1 +marks=$(( `tail -1 $out` )) + +echo $marks + +echo "" >> $out echo "Below is the feedback for your submission danube.scala" >> $out echo "" >> $out @@ -15,32 +20,32 @@ # compilation tests function scala_compile { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out) } # functional tests function scala_assert { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null) } # purity test function scala_vars { - (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) + (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null) } # var, .par return, ListBuffer test # -echo "danube.scala does not contain vars, returns etc?" >> $out +echo "danube.scala does not contain vars, returns etc?" | tee -a $out if (scala_vars danube.scala) then - echo " --> fail (make triple-sure your program conforms to the required format)" >> $out - tsts0=$(( 0 )) + echo " --> test failed" | tee -a $out + tsts0=$(( 1 )) else - echo " --> success" >> $out + echo " --> success" | tee -a $out tsts0=$(( 0 )) fi @@ -49,14 +54,14 @@ if [ $tsts0 -eq 0 ] then - echo "danube.scala runs?" >> $out + echo "danube.scala runs?" | tee -a $out if (scala_compile danube.scala) then - echo " --> success" >> $out + echo " --> success" | tee -a $out tsts=$(( 0 )) else - echo " --> scala did not run danube.scala" >> $out + echo " --> scala did not run danube.scala" | tee -a $out tsts=$(( 1 )) fi else @@ -67,15 +72,16 @@ if [ $tsts -eq 0 ] then - echo "danube.scala tests:" >> $out - echo " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" >> $out - echo " get_csv_url(movies_url).length == 9742" >> $out + echo "danube.scala tests:" | tee -a $out + echo " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out + echo " get_csv_url(movies_url).length == 9742" | tee -a $out if (scala_assert "danube.scala" "danube_test1.scala") then - echo " --> success" >> $out + echo " --> success" | tee -a $out + marks=$(( marks + 1 )) else - echo " --> one of the tests failed" >> $out + echo " --> one of the tests failed" | tee -a $out fi fi @@ -83,17 +89,25 @@ if [ $tsts -eq 0 ] then - echo " val good_ratings = process_ratings(ratings)" >> $out - echo " val movie_names = process_movies(movies)" >> $out - echo " " >> $out - echo " good_ratings.length == 48580 " >> $out - echo " movie_names.length == 9742 " >> $out + echo " val good_ratings = process_ratings(ratings)" | tee -a $out + echo " val movie_names = process_movies(movies)" | tee -a $out + echo " " | tee -a $out + echo " good_ratings.length == 48580 " | tee -a $out + echo " movie_names.length == 9742 " | tee -a $out if (scala_assert "danube.scala" "danube_test2.scala") then - echo " --> success" >> $out + echo " --> success" | tee -a $out + marks=$(( marks + 1 )) else - echo " --> one of the tests failed" >> $out + echo " --> one of the tests failed" | tee -a $out fi fi + + +## final marks +echo "Overall mark for CW 7, Part 1 + 2" | tee -a $out +echo "$marks" | tee -a $out + + diff -r 5a16bcb4105e -r ecd989eee8bd solutions5/bf.scala --- a/solutions5/bf.scala Sat Feb 02 13:38:47 2019 +0000 +++ b/solutions5/bf.scala Wed Mar 20 21:50:20 2019 +0000 @@ -108,7 +108,7 @@ -/* + // some sample bf-programs collected from the Internet //===================================================== @@ -202,6 +202,23 @@ <]++++++++++.[-]<<<[<<]>>>+<[->[<+>-[<+>-[<+>-[<+>-[<+>-[<+>- [<+>-[<+>-[<+>-[<[-]>>[-]+>+<<-]]]]]]]]]]<[>+<-]+>>]<<[<<]>>]""") +// 2 to the power of 6 +//(example from a C-to-BF compiler at https://github.com/elikaski/BF-it) +run(""">>[-]>[-]++>[-]++++++><<<>>>>[-]+><>[-]<<[-]>[>+<<+>-]>[<+>-] + <><[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-] + <[>+>+<<-]>[<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<[[-]>[-]<<[>+> + +<<-]>>[<<+>>-][-]>[-]<<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-] + <<>>[-]>[-]<<<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<<>[-]<<[-] + >[>+<<+>-]>[<+>-]<><[-]>[-]<<<[>>+>+<<<-]>>>-[<<<+>>>-]<[-]>[-] + <<<[>>+>+<<<-]>>>[<<<+>>>-][-]><<>>[-]>[-]<<<[>>[-]<[>+>+<<-]> + [<+>-]+>[[-]<-<->>]<<<-]>>[<<+>>-]<<][-]>[-]<<[>+>+<<-]>>[<<+> + >-]<<<<<[-]>>>>[<<<<+>>>>-]<<<<><>[-]<<[-]>[>+<<+>-]>[<+>-]<> + <[-]>[-]>[-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<<>>[-]>[-]>[-]>[-]>[-]> + [-]>[-]>[-]>[-]>[-]<<<<<<<<<<>>++++++++++<<[->+>-[>+>>]>[+[-<+ + >]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<< + ]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++ + ++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<<><<<""") + // a Mandelbrot set generator in brainf*** written by Erik Bosman @@ -225,6 +242,6 @@ } time_needed(1, run(b1)) -*/ + }