diff options
Diffstat (limited to 'test-nsc/files/run')
-rwxr-xr-x | test-nsc/files/run/Course-2002-02.scala | 26 | ||||
-rwxr-xr-x | test-nsc/files/run/Course-2002-05.scala | 16 | ||||
-rw-r--r-- | test-nsc/files/run/Course-2002-06.scala | 3 | ||||
-rwxr-xr-x | test-nsc/files/run/Course-2002-08.scala | 8 |
4 files changed, 22 insertions, 31 deletions
diff --git a/test-nsc/files/run/Course-2002-02.scala b/test-nsc/files/run/Course-2002-02.scala index 00f43501f4..a86ffebaf5 100755 --- a/test-nsc/files/run/Course-2002-02.scala +++ b/test-nsc/files/run/Course-2002-02.scala @@ -17,16 +17,13 @@ object M0 { object M1 { def cube(x: Int): Double = x * x * x; - def sumInts(a: Int, b: Int): Double = - if (a > b) 0 + def sumInts(a: Int, b: Int): Double = if (a > b) 0 else a + sumInts(a + 1, b); - def sumCubes(a: Int, b: Int): Double = - if (a > b) 0 + def sumCubes(a: Int, b: Int): Double = if (a > b) 0 else cube(a) + sumCubes(a + 1, b); - def sumReciprocals(a: Int, b: Int): Double = - if (a > b) 0 + def sumReciprocals(a: Int, b: Int): Double = if (a > b) 0 else 1.0/a + sumReciprocals(a + 1, b); def sumPi(n: Int): Double = { @@ -198,17 +195,14 @@ object M8 { //############################################################################ object M9 { - def accumulate[t](combiner: (t, t) => t, nullValue: t, f: Int => t, next: Int => Int) - (a: Int, b: Int): t = - if (a > b) nullValue + def accumulate[t](combiner: (t, t) => t, nullValue: t, f: Int => t, + next: Int => Int)(a: Int, b: Int): t = if (a > b) nullValue else combiner(f(a), accumulate(combiner, nullValue, f, next)(next(a), b)); def inc(x: Int) = x + 1; - def sum(f: Int => Double) = - accumulate((x: Double, y: Double) => x + y, 0d, f, inc); - def product(f: Int => Double) = - accumulate((x: Double, y: Double) => x * y, 1d, f, inc); + def sum(f: Int => Double) = accumulate((x: Double, y: Double) => x + y, 0d, f, inc); + def product(f: Int => Double) = accumulate((x: Double, y: Double) => x * y, 1d, f, inc); def sumInts = sum(x => x); def sumCubes = sum(x => x * x * x); @@ -323,8 +317,7 @@ object MC { //############################################################################ object MD { - def reduce(op: (Double,Double) => Double, zero:Double) - (f: Int => Double)(a: Int,b: Int): Double = { + def reduce(op: (Double,Double) => Double, zero:Double)(f: Int => Double)(a: Int,b: Int): Double = { def iter(a: Int, result: Double): Double = { if (a > b) result else iter(a + 1, op(result, f(a))) @@ -367,8 +360,7 @@ object MD { //############################################################################ object ME { - def reduce(op: (Double,Double) => Double, zero:Double) - (f: Int => Double)(a: Int,b: Int): Double = { + def reduce(op: (Double,Double) => Double, zero:Double)(f: Int => Double)(a: Int,b: Int): Double = { def iter(a: Int, result: Double): Double = { if (a > b) result else iter(a + 1, op(result, f(a))) diff --git a/test-nsc/files/run/Course-2002-05.scala b/test-nsc/files/run/Course-2002-05.scala index 6f40f7f99e..c761f88f5d 100755 --- a/test-nsc/files/run/Course-2002-05.scala +++ b/test-nsc/files/run/Course-2002-05.scala @@ -130,14 +130,14 @@ object M3 { else { def isSafe(column: int, placement: Placement): boolean = placement forall { - pos => pos._2 != column - && abs(pos._2 - column) != row - pos._1 + pos => (pos._2 != column && + abs(pos._2 - column) != row - pos._1) } def adjoinRow(placement: Placement): List[Placement] = range(1, n) - filter (column => isSafe(column, placement)) - map (column => Pair(row, column) :: placement); + .filter (column => isSafe(column, placement)) + .map (column => Pair(row, column) :: placement); placeQueens(row - 1) flatMap adjoinRow } @@ -173,10 +173,10 @@ object M4 { List(List()) else { def isSafe(col: Int, p: Placement, delta: Int): Boolean = - p.isEmpty || - (col != p.head && - abs(col - p.head) != delta && - isSafe(col, p.tail, delta + 1)); + (p.isEmpty || + (col != p.head && + abs(col - p.head) != delta && + isSafe(col, p.tail, delta + 1))); for ( val placement <- placeQueens(row - 1); diff --git a/test-nsc/files/run/Course-2002-06.scala b/test-nsc/files/run/Course-2002-06.scala index 8ce003333f..76bd581a73 100644 --- a/test-nsc/files/run/Course-2002-06.scala +++ b/test-nsc/files/run/Course-2002-06.scala @@ -155,8 +155,7 @@ object M0 { /** Transform the frame in which the painter is to be drawn, hence * changing the appearance of the painter */ - def transformPainter(origin: Vector, newX: Vector, newY: Vector) - (painter: Painter): Painter = { + def transformPainter(origin: Vector, newX: Vector, newY: Vector)(painter: Painter): Painter = { frame: Frame => { val newOrigin = frame.coordMap(origin); val newFrame = new Frame(newOrigin, diff --git a/test-nsc/files/run/Course-2002-08.scala b/test-nsc/files/run/Course-2002-08.scala index 7e06001732..a0d679d3d1 100755 --- a/test-nsc/files/run/Course-2002-08.scala +++ b/test-nsc/files/run/Course-2002-08.scala @@ -342,8 +342,8 @@ object M5 { halfAdder(ain, bin, sout, cout); def result = - (if (sout.getSignal) 1 else 0) + - (if (cout.getSignal) 2 else 0); + ((if (sout.getSignal) 1 else 0) + + (if (cout.getSignal) 2 else 0)); def test(a: Int, b: Int) = { ain setSignal (if (a == 0) false else true); @@ -372,8 +372,8 @@ object M5 { fullAdder(ain, bin, cin, sout, cout); def result = - (if (sout.getSignal) 1 else 0) + - (if (cout.getSignal) 2 else 0); + ((if (sout.getSignal) 1 else 0) + + (if (cout.getSignal) 2 else 0)); def test(a: Int, b: Int, c: Int) = { ain setSignal (if (a == 0) false else true); |