# HG changeset patch # User Christian Urban # Date 1544408610 0 # Node ID a359976a6f3e68ef0c3f89d389b36cd73dab8c93 # Parent 9bb36426c78198fea663ed8dbc5c30311e0eef6b updated diff -r 9bb36426c781 -r a359976a6f3e marking3/compare --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/marking3/compare Mon Dec 10 02:23:30 2018 +0000 @@ -0,0 +1,18 @@ +#!/bin/sh +###set -e + +trap "exit" INT + +files=${1:-assignment20188-*} + +for sd in $files; do + cd $sd + cp output output1 + #cmp -s output output1 > /dev/null + #if [ $? -eq 1 ]; then + # echo $sd + "is different" + #fi + cd .. +done + + diff -r 9bb36426c781 -r a359976a6f3e marking3/knight1_test.sh --- a/marking3/knight1_test.sh Sun Dec 09 01:36:49 2018 +0000 +++ b/marking3/knight1_test.sh Mon Dec 10 02:23:30 2018 +0000 @@ -31,6 +31,15 @@ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) } +function scala_assert_long { + (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) +} + +function scala_assert_elong { + (ulimit -t 90; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null) +} + + # purity test function scala_vars { @@ -115,12 +124,12 @@ then echo " all_tours from every position on the board" | tee -a $out echo " dim = 1: 1" | tee -a $out - echo " 2: 0,0,0,0" >> $out - echo " 3: 0,0,0,0,0,0,0,0,0" >> $out + echo " 2: 0,0,0,0" | tee -a $out + echo " 3: 0,0,0,0,0,0,0,0,0" | tee -a $out echo " 4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" | tee -a $out echo " 5: 304,0,56,0,304,0,56,0,56,0,56,0,64,0,56,0,56,0,56,0,304,0,56,0,304" | tee -a $out - if (scala_assert "knight1.scala" "knight1_test3a.scala") + if (time scala_assert_elong "knight1.scala" "knight1_test3a.scala") then echo " --> success" | tee -a $out marks=$(( marks + 1 )) @@ -133,7 +142,7 @@ then echo " enum_tours(5, List((0,2)) ) => 56 tours? and all correct?" | tee -a $out - if (scala_assert "knight1.scala" "knight1_test3b.scala") + if (time scala_assert "knight1.scala" "knight1_test3b.scala") then echo " --> success" | tee -a $out marks=$(( marks + 1 )) @@ -143,7 +152,7 @@ fi -### knight2a test +### knight4 test if [ $tsts1 -eq 0 ] then @@ -161,17 +170,17 @@ fi -### knight2b test +### knight5 test if [ $tsts1 -eq 0 ] then echo " is first_tour(8, List((0, 0))) ok? " | tee -a $out echo " is first_tour(4, List((0, 0))) == None " | tee -a $out - if (scala_assert "knight1.scala" "knight5_test.scala") + if (time scala_assert_long "knight1.scala" "knight1_test5.scala") then echo " --> success" | tee -a $out - marks=$(( marks + 2 )) + marks=$(( marks + 1 )) else echo " --> test failed" | tee -a $out fi diff -r 9bb36426c781 -r a359976a6f3e marking3/knight1_test3a.scala --- a/marking3/knight1_test3a.scala Sun Dec 09 01:36:49 2018 +0000 +++ b/marking3/knight1_test3a.scala Mon Dec 10 02:23:30 2018 +0000 @@ -1,32 +1,12 @@ -type Pos = (Int, Int) // a position on a chessboard -type Path = List[Pos] // a path...a list of positions +//type Pos = (Int, Int) // a position on a chessboard +//type Path = List[Pos] // a path...a list of positions def count_all_tours_urban(dim: Int) = { for (i <- (0 until dim).toList; j <- (0 until dim).toList) yield count_tours(dim, List((i, j))) } -def add_pair_urban(x: Pos)(y: Pos): Pos = - (x._1 + y._1, x._2 + y._2) - -def is_legal_urban(dim: Int, path: Path)(x: Pos): Boolean = - 0 <= x._1 && 0 <= x._2 && x._1 < dim && x._2 < dim && !path.contains(x) - -def moves_urban(x: Pos): List[Pos] = - List(( 1, 2),( 2, 1),( 2, -1),( 1, -2), - (-1, -2),(-2, -1),(-2, 1),(-1, 2)).map(add_pair_urban(x)) - -def legal_moves_urban(dim: Int, path: Path, x: Pos): List[Pos] = - moves_urban(x).filter(is_legal_urban(dim, path)) - -def correct_urban(dim: Int)(p: Path): Boolean = p match { - case Nil => true - case x::Nil => true - case x::y::p => if (legal_moves_urban(dim, p, y).contains(x)) correct_urban(dim)(y::p) else false -} - - assert(count_all_tours_urban(1) == List(1)) assert(count_all_tours_urban(2) == List(0, 0, 0, 0)) diff -r 9bb36426c781 -r a359976a6f3e marking3/knight1_test3b.scala --- a/marking3/knight1_test3b.scala Sun Dec 09 01:36:49 2018 +0000 +++ b/marking3/knight1_test3b.scala Mon Dec 10 02:23:30 2018 +0000 @@ -1,11 +1,6 @@ -type Pos = (Int, Int) // a position on a chessboard -type Path = List[Pos] // a path...a list of positions - -def count_all_tours_urban(dim: Int) = { - for (i <- (0 until dim).toList; - j <- (0 until dim).toList) yield count_tours(dim, List((i, j))) -} +//type Pos = (Int, Int) // a position on a chessboard +//type Path = List[Pos] // a path...a list of positions def add_pair_urban(x: Pos)(y: Pos): Pos = (x._1 + y._1, x._2 + y._2) diff -r 9bb36426c781 -r a359976a6f3e marking3/knight1_test4.scala --- a/marking3/knight1_test4.scala Sun Dec 09 01:36:49 2018 +0000 +++ b/marking3/knight1_test4.scala Mon Dec 10 02:23:30 2018 +0000 @@ -1,5 +1,5 @@ val f = (x:(Int, Int)) => if (x._1 > 3) Some(List(x)) else None -assert(CW7b.first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))) -assert(CW7b.first(List((1,0),(2,0),(3,0)), f) == None) +assert(first(List((1,0),(2,0),(3,0),(4,0)), f) == Some(List((4,0)))) +assert(first(List((1,0),(2,0),(3,0)), f) == None) diff -r 9bb36426c781 -r a359976a6f3e marking3/knight1_test5.scala --- a/marking3/knight1_test5.scala Sun Dec 09 01:36:49 2018 +0000 +++ b/marking3/knight1_test5.scala Mon Dec 10 02:23:30 2018 +0000 @@ -1,6 +1,6 @@ -type Pos = (Int, Int) // a position on a chessboard -type Path = List[Pos] // a path...a list of positions +//type Pos = (Int, Int) // a position on a chessboard +//type Path = List[Pos] // a path...a list of positions def add_pair_urban(x: Pos)(y: Pos): Pos = (x._1 + y._1, x._2 + y._2) diff -r 9bb36426c781 -r a359976a6f3e marking3/tails --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/marking3/tails Mon Dec 10 02:23:30 2018 +0000 @@ -0,0 +1,19 @@ +#!/bin/sh +###set -e + +trap "exit" INT + +files=${1:-assignment20188-*} + +for sd in $files; do + cd $sd + #echo $sd + marksone=$(( `tail -1 output` )) + markstwo=$(( `tail -1 output1` )) + if [ "$marksone" != "$markstwo" ]; then + echo $sd + "is different" + fi + cd .. +done + + diff -r 9bb36426c781 -r a359976a6f3e solutions5/bf.scala --- a/solutions5/bf.scala Sun Dec 09 01:36:49 2018 +0000 +++ b/solutions5/bf.scala Mon Dec 10 02:23:30 2018 +0000 @@ -107,6 +107,7 @@ def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m) + /* // some sample bf-programs collected from the Internet @@ -138,9 +139,13 @@ // hello world program 2 run("""++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>+ - +.<<+++++++++++++++.>.+++.------.--------.>+.>.""") + +.<<+++++++++++++++.>.+++.------.--------.>+.>.""") +// hello world program 3 +run("""+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++.. + +++.>-.------------.<++++++++.--------.+++.------.--------.>+.""") + // draws the Sierpinski triangle run("""++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[ ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<