diff options
author | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-11-02 14:34:35 +0000 |
---|---|---|
committer | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-11-02 14:34:35 +0000 |
commit | b6778be91900b8161e705dc2598ef7af86842b0b (patch) | |
tree | d15e8ec18a37eec212f50f1ace27714d7e7d4d34 /test/pending | |
parent | ac6c76f26d884a94d0c9ff54f055d3f9ab750bac (diff) | |
download | scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.gz scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.bz2 scala-b6778be91900b8161e705dc2598ef7af86842b0b.zip |
Begone t1737...
Diffstat (limited to 'test/pending')
100 files changed, 3938 insertions, 166 deletions
diff --git a/test/pending/continuations-run/example0.scala b/test/pending/continuations-run/example0.scala index 44b1331339..de5ea54e9d 100644 --- a/test/pending/continuations-run/example0.scala +++ b/test/pending/continuations-run/example0.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test0.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example1.scala b/test/pending/continuations-run/example1.scala index 195a98e59f..e31d6af88c 100644 --- a/test/pending/continuations-run/example1.scala +++ b/test/pending/continuations-run/example1.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test1.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example16.scala b/test/pending/continuations-run/example16.scala index 5eb64046ed..561f0ab0eb 100644 --- a/test/pending/continuations-run/example16.scala +++ b/test/pending/continuations-run/example16.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test16Printf.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example2.scala b/test/pending/continuations-run/example2.scala index 0d96257c40..730f7cc63e 100644 --- a/test/pending/continuations-run/example2.scala +++ b/test/pending/continuations-run/example2.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test2.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example3.scala b/test/pending/continuations-run/example3.scala index 3f5052a4ad..41cf1cce0c 100644 --- a/test/pending/continuations-run/example3.scala +++ b/test/pending/continuations-run/example3.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test3.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example4.scala b/test/pending/continuations-run/example4.scala index 66c6774791..adcc7aa90e 100644 --- a/test/pending/continuations-run/example4.scala +++ b/test/pending/continuations-run/example4.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test4.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example5.scala b/test/pending/continuations-run/example5.scala index 0994bdee8a..241e8cd069 100644 --- a/test/pending/continuations-run/example5.scala +++ b/test/pending/continuations-run/example5.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test5.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example6.scala b/test/pending/continuations-run/example6.scala index 5207e3fc68..00f84fcd6c 100644 --- a/test/pending/continuations-run/example6.scala +++ b/test/pending/continuations-run/example6.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test6.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example7.scala b/test/pending/continuations-run/example7.scala index fb22387dac..64abc6d9a6 100644 --- a/test/pending/continuations-run/example7.scala +++ b/test/pending/continuations-run/example7.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test7.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example8.scala b/test/pending/continuations-run/example8.scala index 8e21e6c674..a5f953d3fc 100644 --- a/test/pending/continuations-run/example8.scala +++ b/test/pending/continuations-run/example8.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test8.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/example9.scala b/test/pending/continuations-run/example9.scala index 0f27c686f7..09d792c427 100644 --- a/test/pending/continuations-run/example9.scala +++ b/test/pending/continuations-run/example9.scala @@ -1,9 +1,9 @@ // $Id$ object Test { - + def main(args: Array[String]): Any = { examples.continuations.Test9Monads.main(args) } - + }
\ No newline at end of file diff --git a/test/pending/continuations-run/foreach.scala b/test/pending/continuations-run/foreach.scala index 4daade452c..76823e7604 100644 --- a/test/pending/continuations-run/foreach.scala +++ b/test/pending/continuations-run/foreach.scala @@ -5,16 +5,16 @@ import scala.util.continuations._ import scala.util.continuations.Loops._ object Test { - + def main(args: Array[String]): Any = { - - + + reset { - + val list = List(1,2,3,4,5) - + for (x <- list.suspendable) { - + shift { k: (Unit => Unit) => println(x) if (x < 3) @@ -22,12 +22,12 @@ object Test { else println("enough is enough") } - + } - + } - - + + } - + }
\ No newline at end of file diff --git a/test/pending/jvm/actorgc_leak.scala b/test/pending/jvm/actorgc_leak.scala index 5e2b9d51e1..de3e04f1e8 100644 --- a/test/pending/jvm/actorgc_leak.scala +++ b/test/pending/jvm/actorgc_leak.scala @@ -14,7 +14,7 @@ object Test { } } } - + class FatActor extends Actor { def act() { fat = new Array[Int](fatness) diff --git a/test/pending/jvm/cf-attributes.scala b/test/pending/jvm/cf-attributes.scala index b5dd7eb386..9e0e9d95de 100644 --- a/test/pending/jvm/cf-attributes.scala +++ b/test/pending/jvm/cf-attributes.scala @@ -52,14 +52,14 @@ object anonymousFunctions { } object anonymousClasses { - //InnerClass: + //InnerClass: // public abstract #_= #_ of #_; //Foo=class anonymousClasses$Foo of class anonymousClasses$ // public abstract #_= #_ of #_; //Foo$class=class anonymousClasses$Foo$class of class anonymousClasses$ trait Foo { def foo() { println("foo"); } override def toString = getClass.getName } - //InnerClass: + //InnerClass: // public final #_; //class anonymousClasses$$anon$1 of class anonymousClasses$ val x = new Foo() { override def foo() { println("foo (overriden)"); } @@ -105,7 +105,7 @@ trait Test2 { def printClass(cls: Class[_]) { println("\n[[ "+cls.getName+" ]]"); try { printInnerClasses(cls) } - catch { case e: Exception => println(e) } + catch { case e: Exception => println(e) } } } diff --git a/test/pending/jvm/javasigs.scala b/test/pending/jvm/javasigs.scala index 48fa37119a..8da59ab0a0 100644 --- a/test/pending/jvm/javasigs.scala +++ b/test/pending/jvm/javasigs.scala @@ -30,7 +30,7 @@ object Scalatest { s.start() s } - + /** Execute cmd, wait for the process to end and pipe it's output to stdout */ def exec(cmd: String) { @@ -50,12 +50,12 @@ object Scalatest { // Test correct java signatures for anonymous classes. Enclosing method attributes should // allow javac to see the type parameters in foo. See #3249. -class A[U] { +class A[U] { def bar[B](x : => B) = x def foo[C](c : C) : C = bar(c) } -object B { +object B { def bar[B](x : => B) = x def foo[C](c : C) : C = { class InnerB(x: C) diff --git a/test/pending/jvm/timeout.scala b/test/pending/jvm/timeout.scala index 3005beab2c..22b3647dce 100644 --- a/test/pending/jvm/timeout.scala +++ b/test/pending/jvm/timeout.scala @@ -16,7 +16,7 @@ object Test extends Application { case 'doTiming => val s = sender reactWithin(500) { - case TIMEOUT => + case TIMEOUT => s ! Timing(System.currentTimeMillis) } } diff --git a/test/pending/neg/plugin-after-terminal/src/ThePlugin.scala b/test/pending/neg/plugin-after-terminal/src/ThePlugin.scala index f3c913086e..2a4607392f 100644 --- a/test/pending/neg/plugin-after-terminal/src/ThePlugin.scala +++ b/test/pending/neg/plugin-after-terminal/src/ThePlugin.scala @@ -12,7 +12,7 @@ class ThePlugin(val global: Global) extends Plugin { val name = "afterterminal" val description = "Declares one plugin that wants to be after the terminal phase" val components = List[PluginComponent](thePhase) - + private object thePhase extends PluginComponent { val global = ThePlugin.this.global @@ -20,9 +20,9 @@ class ThePlugin(val global: Global) extends Plugin { val phaseName = ThePlugin.this.name - def newPhase(prev: Phase) = new ThePhase(prev) + def newPhase(prev: Phase) = new ThePhase(prev) } - + private class ThePhase(prev: Phase) extends Phase(prev) { def name = ThePlugin.this.name def run {} diff --git a/test/pending/neg/plugin-before-parser/src/ThePlugin.scala b/test/pending/neg/plugin-before-parser/src/ThePlugin.scala index 8714a55dc4..7ca896650d 100644 --- a/test/pending/neg/plugin-before-parser/src/ThePlugin.scala +++ b/test/pending/neg/plugin-before-parser/src/ThePlugin.scala @@ -12,7 +12,7 @@ class ThePlugin(val global: Global) extends Plugin { val name = "beforeparser" val description = "Declares one plugin that wants to be before the parser phase" val components = List[PluginComponent](thePhase) - + private object thePhase extends PluginComponent { val global = ThePlugin.this.global @@ -21,9 +21,9 @@ class ThePlugin(val global: Global) extends Plugin { val phaseName = ThePlugin.this.name - def newPhase(prev: Phase) = new ThePhase(prev) + def newPhase(prev: Phase) = new ThePhase(prev) } - + private class ThePhase(prev: Phase) extends Phase(prev) { def name = ThePlugin.this.name def run {} diff --git a/test/pending/neg/plugin-cyclic-dependency/src/ThePlugin.scala b/test/pending/neg/plugin-cyclic-dependency/src/ThePlugin.scala index 1dfc15cb28..bd94ce60d7 100644 --- a/test/pending/neg/plugin-cyclic-dependency/src/ThePlugin.scala +++ b/test/pending/neg/plugin-cyclic-dependency/src/ThePlugin.scala @@ -12,7 +12,7 @@ class ThePlugin(val global: Global) extends Plugin { val name = "cyclicdependency" val description = "Declares two phases that have a cyclic dependency" val components = List[PluginComponent](thePhase1,thePhase2) - + private object thePhase1 extends PluginComponent { val global = ThePlugin.this.global @@ -20,9 +20,9 @@ class ThePlugin(val global: Global) extends Plugin { val phaseName = ThePlugin.this.name + "1" - def newPhase(prev: Phase) = new ThePhase(prev) + def newPhase(prev: Phase) = new ThePhase(prev) } - + private object thePhase2 extends PluginComponent { val global = ThePlugin.this.global @@ -30,9 +30,9 @@ class ThePlugin(val global: Global) extends Plugin { val phaseName = ThePlugin.this.name + "2" - def newPhase(prev: Phase) = new ThePhase(prev) + def newPhase(prev: Phase) = new ThePhase(prev) } - + private class ThePhase(prev: Phase) extends Phase(prev) { def name = ThePlugin.this.name def run {} diff --git a/test/pending/neg/plugin-multiple-rafter/src/ThePlugin.scala b/test/pending/neg/plugin-multiple-rafter/src/ThePlugin.scala index 4c761517c1..819176fa88 100644 --- a/test/pending/neg/plugin-multiple-rafter/src/ThePlugin.scala +++ b/test/pending/neg/plugin-multiple-rafter/src/ThePlugin.scala @@ -12,7 +12,7 @@ class ThePlugin(val global: Global) extends Plugin { val name = "multi-rafter" val description = "" val components = List[PluginComponent](thePhase) - + private object thePhase extends PluginComponent { val global = ThePlugin.this.global @@ -20,9 +20,9 @@ class ThePlugin(val global: Global) extends Plugin { override val runsRightAfter = Some("explicitouter") val phaseName = ThePlugin.this.name - def newPhase(prev: Phase) = new ThePhase(prev) + def newPhase(prev: Phase) = new ThePhase(prev) } - + private class ThePhase(prev: Phase) extends Phase(prev) { def name = ThePlugin.this.name def run {} diff --git a/test/pending/neg/plugin-rafter-before-1/src/ThePlugin.scala b/test/pending/neg/plugin-rafter-before-1/src/ThePlugin.scala index c42a914066..81ba85ae80 100644 --- a/test/pending/neg/plugin-rafter-before-1/src/ThePlugin.scala +++ b/test/pending/neg/plugin-rafter-before-1/src/ThePlugin.scala @@ -12,7 +12,7 @@ class ThePlugin(val global: Global) extends Plugin { val name = "rafter-before-1" val description = "" val components = List[PluginComponent](thePhase1) - + private object thePhase1 extends PluginComponent { val global = ThePlugin.this.global @@ -20,9 +20,9 @@ class ThePlugin(val global: Global) extends Plugin { override val runsBefore = List[String]("erasure") val phaseName = ThePlugin.this.name - def newPhase(prev: Phase) = new ThePhase(prev) + def newPhase(prev: Phase) = new ThePhase(prev) } - + private class ThePhase(prev: Phase) extends Phase(prev) { def name = ThePlugin.this.name def run {} diff --git a/test/pending/neg/plugin-rightafter-terminal/src/ThePlugin.scala b/test/pending/neg/plugin-rightafter-terminal/src/ThePlugin.scala index 47dd06ec8a..9d6d30b327 100644 --- a/test/pending/neg/plugin-rightafter-terminal/src/ThePlugin.scala +++ b/test/pending/neg/plugin-rightafter-terminal/src/ThePlugin.scala @@ -12,18 +12,18 @@ class ThePlugin(val global: Global) extends Plugin { val name = "rightafterterminal" val description = "Declares one plugin that wants to be right after the terminal phase" val components = List[PluginComponent](thePhase) - + private object thePhase extends PluginComponent { val global = ThePlugin.this.global val runsAfter = List[String]() override val runsRightAfter = Some("terminal") - + val phaseName = ThePlugin.this.name - def newPhase(prev: Phase) = new ThePhase(prev) + def newPhase(prev: Phase) = new ThePhase(prev) } - + private class ThePhase(prev: Phase) extends Phase(prev) { def name = ThePlugin.this.name def run {} diff --git a/test/pending/neg/t0653.scala b/test/pending/neg/t0653.scala index 48f39447ba..26204a8b40 100644 --- a/test/pending/neg/t0653.scala +++ b/test/pending/neg/t0653.scala @@ -7,11 +7,11 @@ class Fix[Op[A]](x : Op[Fix[Op]]) class FixTest { // works // val zero = new Fix[One](new One) - + // don't work: val two = new Fix(new Two) // this was what I found here val zero = new Fix(new One) // this seems like something which could plausibly work - + // neg/t0653.scala:12: error: no type parameters for constructor Fix: (x: Op[Fix[Op[A]]])Fix[Op[A]] exist so that it can be applied to arguments (Two[Nothing,Nothing]) // --- because --- // argument expression's type is not compatible with formal parameter type; @@ -24,7 +24,7 @@ class FixTest { // argument expression's type is not compatible with formal parameter type; // found : One[Nothing] // required: ?Op[ Fix[?Op[ A ]] ] - // val zero = new Fix(new One) // this seems like something which could plausibly work + // val zero = new Fix(new One) // this seems like something which could plausibly work // ^ - // two errors found + // two errors found } diff --git a/test/pending/neg/t2080.scala b/test/pending/neg/t2080.scala index 0880a40faa..3f4306c091 100644 --- a/test/pending/neg/t2080.scala +++ b/test/pending/neg/t2080.scala @@ -14,4 +14,4 @@ object C extends B { } override def f(x : T) : T = { x.g; x } } -//It compiles without errors, but T in B and T in C are completely unrelated types. +//It compiles without errors, but T in B and T in C are completely unrelated types. diff --git a/test/pending/neg/t3152.scala b/test/pending/neg/t3152.scala index 27a314c484..3abc772076 100644 --- a/test/pending/neg/t3152.scala +++ b/test/pending/neg/t3152.scala @@ -3,6 +3,6 @@ package test object NotEnclosing { def main(args : Array[String]) : Unit = {} def compare[T](x: Ordered[T], y: Ordered[T]) = error("") - def mkEx: Ordered[_] = error("") - compare(mkEx, mkEx) + def mkEx: Ordered[_] = error("") + compare(mkEx, mkEx) } diff --git a/test/pending/neg/t963.scala b/test/pending/neg/t963.scala index 430ef090e4..3be0be1b84 100644 --- a/test/pending/neg/t963.scala +++ b/test/pending/neg/t963.scala @@ -5,8 +5,8 @@ trait A { } object B { - def f(x : { val y : A }) { x.y.v = x.y.v } - + def f(x : { val y : A }) { x.y.v = x.y.v } + var a : A = _ var b : Boolean = false def y : A = { diff --git a/test/pending/neg/tcpoly_typealias_eta.scala b/test/pending/neg/tcpoly_typealias_eta.scala index 0fb2c2d33e..033c911f7c 100644 --- a/test/pending/neg/tcpoly_typealias_eta.scala +++ b/test/pending/neg/tcpoly_typealias_eta.scala @@ -12,7 +12,7 @@ trait A3 { trait FooCov[+x] trait FooCon[-x] -trait FooBound[+x <: String] +trait FooBound[+x <: String] trait BOk1 extends A { type m/*[+x]*/ = FooCov/*[x]*/ @@ -30,8 +30,8 @@ trait BOk4 extends A3 { type m/*[+x]*/ = FooCov/*[x]*/ // weaker variance } -// there are two aspects to check: - // does type alias signature (not considering RHS) correspond to abstract type member in super class +// there are two aspects to check: + // does type alias signature (not considering RHS) correspond to abstract type member in super class // does RHS correspond to the type alias sig trait BInv extends A{ type m/*[x]*/ = FooCov/*[x]*/ // error: invariant x in alias def diff --git a/test/pending/neg/tcpoly_variance_enforce_getter_setter.scala b/test/pending/neg/tcpoly_variance_enforce_getter_setter.scala index 321d392cc4..deafba8d8a 100644 --- a/test/pending/neg/tcpoly_variance_enforce_getter_setter.scala +++ b/test/pending/neg/tcpoly_variance_enforce_getter_setter.scala @@ -1,12 +1,12 @@ trait coll[+m[+x]] -class FooInvar[x] +class FooInvar[x] class FooContra[-x] class FooCov[+x] object test { var ok: coll[FooCov] = _ - + var x: coll[FooInvar] = _ // TODO: error should be reported only once instead of separately for getter and setter var y: coll[FooContra] = _ } diff --git a/test/pending/neg/type-diagnostics.scala b/test/pending/neg/type-diagnostics.scala index 7f9a151dcd..a3a9172bb2 100644 --- a/test/pending/neg/type-diagnostics.scala +++ b/test/pending/neg/type-diagnostics.scala @@ -7,5 +7,5 @@ object TooManyParens { // Unspecified value parameter elem. // def f = Map(1 -> 2).keySet() // ^ - + } diff --git a/test/pending/pos/misc/B.scala b/test/pending/pos/misc/B.scala index 3a080e4712..afc30944f5 100644 --- a/test/pending/pos/misc/B.scala +++ b/test/pending/pos/misc/B.scala @@ -1,7 +1,7 @@ package test class B { - + def myA = new A() } diff --git a/test/pending/pos/no-widen-locals.scala b/test/pending/pos/no-widen-locals.scala index ba568f64eb..013e63f0a2 100644 --- a/test/pending/pos/no-widen-locals.scala +++ b/test/pending/pos/no-widen-locals.scala @@ -8,7 +8,7 @@ object Test { val X2 = 10 val X3 = 15 val X4 = 20 - + (x: @switch) match { case X1 => 1 case X2 => 2 diff --git a/test/pending/pos/sig/sigs.scala b/test/pending/pos/sig/sigs.scala index 72a293d0e6..bdb72a09bb 100644 --- a/test/pending/pos/sig/sigs.scala +++ b/test/pending/pos/sig/sigs.scala @@ -1,5 +1,5 @@ package test -class T { +class T { def foo[T <: String](x: T): T = x def bar[T](x: T): T = x class Inner { diff --git a/test/pending/pos/t0621.scala b/test/pending/pos/t0621.scala index d178bed0fb..1d2531c4bd 100644 --- a/test/pending/pos/t0621.scala +++ b/test/pending/pos/t0621.scala @@ -1,7 +1,7 @@ object Test { val x1 : List[T] forSome { type T } = List(42) val w1 = x1 match { case y : List[u] => ((z : u) => z)(y.head) } - + val x2 : T forSome { type T } = 42 val w2 = x2 match { case y : u => ((z : u) => z)(y) } } diff --git a/test/pending/pos/t1357.scala b/test/pending/pos/t1357.scala index fcdecb3ad3..7bc6d45034 100644 --- a/test/pending/pos/t1357.scala +++ b/test/pending/pos/t1357.scala @@ -6,7 +6,7 @@ object NonEmptyCons { object Main { type BT[+H, +T <: Tuple2[Tuple2[H, T], Tuple2[H, T]]] = Tuple2[H, T] - + // type T = Tuple2[String,String] type BinaryTree[+E] = BT[E, T forSome { type T <: Tuple2[BT[E, T], BT[E, T]] }] diff --git a/test/pending/pos/t1380/hallo.scala b/test/pending/pos/t1380/hallo.scala index 27ecd9fb8b..bb8fff2333 100644 --- a/test/pending/pos/t1380/hallo.scala +++ b/test/pending/pos/t1380/hallo.scala @@ -1,3 +1,3 @@ object hallo { - def main(args:Array[String]) = println("hallo") + def main(args:Array[String]) = println("hallo") } diff --git a/test/pending/pos/t1786.scala b/test/pending/pos/t1786.scala index d0cf8c7bac..dca2edaab4 100644 --- a/test/pending/pos/t1786.scala +++ b/test/pending/pos/t1786.scala @@ -1,10 +1,10 @@ /** This a consequence of the current type checking algorithm, where bounds * are checked only after variables are instantiated. I believe this will change once we go to contraint-based type inference. Assigning low priority until then. - * + * * */ class SomeClass(val intValue:Int) -class MyClass[T <: SomeClass](val myValue:T) +class MyClass[T <: SomeClass](val myValue:T) object Test extends Application { def myMethod(i:MyClass[_]) { diff --git a/test/pending/pos/t2173.scala b/test/pending/pos/t2173.scala index bbcca39826..cf1913d88b 100644 --- a/test/pending/pos/t2173.scala +++ b/test/pending/pos/t2173.scala @@ -4,9 +4,9 @@ class A[+U >: Null] { } // with the following error: -// +// // type arguments [A.this.R[X]] do not conform to class A's type parameter bounds [+U >: Null] -// +// // However, because type R[+X>:Null] is identical to X, it should carry X bounds and R[X] lower bound should be known to be X's lower bound, i.e. Null. -// +// // The same problem occurs with upper bounds. diff --git a/test/pending/pos/t4606.scala b/test/pending/pos/t4606.scala index f79d17d436..f4e5058483 100644 --- a/test/pending/pos/t4606.scala +++ b/test/pending/pos/t4606.scala @@ -1,9 +1,9 @@ object t4606 { class A(var x: Int) class B(x: Int) extends A(x) - trait C { self: B => - def foo = x - def bar = self.x + trait C { self: B => + def foo = x + def bar = self.x def baz = { val b: B = self b.x diff --git a/test/pending/pos/those-kinds-are-high.scala b/test/pending/pos/those-kinds-are-high.scala index d3ee2bf308..3012e72d7e 100644 --- a/test/pending/pos/those-kinds-are-high.scala +++ b/test/pending/pos/those-kinds-are-high.scala @@ -4,18 +4,18 @@ class A { class C1[T] extends Template[C1] with Container[T] class C2[T] extends Template[C2] with Container[T] - + /** Target expression: * List(new C1[String], new C2[String]) */ - + // Here's what would ideally be inferred. // // scala> :type List[Template[Container] with Container[String]](new C1[String], new C2[String]) // List[Template[Container] with Container[java.lang.String]] // // Here's what it does infer. - // + // // scala> :type List(new C1[String], new C2[String]) // <console>:8: error: type mismatch; // found : C1[String] @@ -27,11 +27,11 @@ class A { // // List[Container[String] with Template[Container[Any] with Template[Container[Any] with Template[Any]]] // - + /** Working version explicitly typed. */ def fExplicit = List[Template[Container] with Container[String]](new C1[String], new C2[String]) - + // nope // def fFail = List(new C1[String], new C2[String]) } diff --git a/test/pending/pos/unappgadteval.scala b/test/pending/pos/unappgadteval.scala index fce54723a1..89f6cabc43 100644 --- a/test/pending/pos/unappgadteval.scala +++ b/test/pending/pos/unappgadteval.scala @@ -21,30 +21,30 @@ object Suc { def unapply(a: Suc) = true } class Suc() extends Term[Int => Int] // Environments : -abstract class Env { +abstract class Env { def apply[a](v: Var[a]): a def extend[a](v: Var[a], x : a) = new Env { - def apply[b](w: Var[b]): b = w match { + def apply[b](w: Var[b]): b = w match { case _ : v.type => x // v eq w, hence a = b case _ => Env.this.apply(w) }} } -object empty extends Env { - def apply[a](x: Var[a]): a = throw new Error("not found : "+x.name) +object empty extends Env { + def apply[a](x: Var[a]): a = throw new Error("not found : "+x.name) } object Test { val v1 = new Var[util.Random]("random") val v2 = new Var[Int]("Int") val v3 = new Var[List[String]]("list") - + val anEnv = (empty .extend(v1, new util.Random) .extend(v2, 58) .extend(v3, Nil) ) - + def eval[a](t: Term[a], env : Env): a = t match { // First three work case v : Var[b] => env(v) // a = b @@ -54,9 +54,9 @@ object Test { // Next one fails like: // // found : (Int) => Int - // required: a + // required: a case i @ Suc() => { (y: Int) => y + 1 } // a = Int => Int - + // Next one fails like: // // error: '=>' expected but '[' found. @@ -64,11 +64,11 @@ object Test { // ^ case f @ Lam[b,c](x, e) => { (y: b) => eval(e, env.extend(x, y)) } // a = b=>c } - + val f1 = () => eval(v1, anEnv) val f2 = () => eval(v2, anEnv) val f3 = () => eval(v3, anEnv) - + def main(args: Array[String]): Unit = { println(f1()) println(f2()) diff --git a/test/pending/pos/virt.scala b/test/pending/pos/virt.scala index 6fe21246b0..99dcd747b2 100644 --- a/test/pending/pos/virt.scala +++ b/test/pending/pos/virt.scala @@ -1,9 +1,9 @@ object Virt extends Application { - class Foo { + class Foo { trait Inner <: { val x : Int = 3 } } - class Bar extends Foo { + class Bar extends Foo { trait Inner <: { val y : Int = x } } } diff --git a/test/pending/run/TestFlatMap.scala b/test/pending/run/TestFlatMap.scala index e6fb696aa2..dd5a0a0c2f 100644 --- a/test/pending/run/TestFlatMap.scala +++ b/test/pending/run/TestFlatMap.scala @@ -4,7 +4,7 @@ import scala.util.Random import scala.collection.parallel.CompositeThrowable object Test { - + def main(args: Array[String]) { val N = 1500 val M = 1500 @@ -12,7 +12,7 @@ object Test { var unmatchedRight = new PMHashSet[Int] Range(0, N).foreach{ x => unmatchedLeft += x} Range(0, M).foreach{ x => unmatchedRight += x} - + try { val matches = unmatchedLeft.flatMap{ lind: Int => val dists = unmatchedRight.seq.map{ rind: Int => @@ -25,5 +25,5 @@ object Test { case c: CompositeThrowable => for (t <- c.throwables) println("\n%s\n%s".format(t, t.getStackTrace.mkString("\n"))) } } - + } diff --git a/test/pending/run/hk-lub-fail.scala b/test/pending/run/hk-lub-fail.scala index 26bd85c943..b58a86ee75 100644 --- a/test/pending/run/hk-lub-fail.scala +++ b/test/pending/run/hk-lub-fail.scala @@ -30,7 +30,7 @@ object Test { val tps = List(quux1, quux2) map (_.tpe) val test = EmptyPackageClass.tpe.member(newTermName("Test")) val f = test.tpe.member(newTypeName("F")).tpe - + val fn = f.normalize.asInstanceOf[ExistentialType] val fn2 = fn.underlying.asInstanceOf[TypeRef] */ diff --git a/test/pending/run/instanceOfAndTypeMatching.scala b/test/pending/run/instanceOfAndTypeMatching.scala index 60b11ef0c1..e04ae13585 100644 --- a/test/pending/run/instanceOfAndTypeMatching.scala +++ b/test/pending/run/instanceOfAndTypeMatching.scala @@ -6,9 +6,9 @@ object Summary { class Inner { } def f() = { class MethodInner ; new MethodInner } } - + // 1 static issue: - // + // // Given method in MethodInner: def g(other: MethodInner) = () // method1.g(method1) fails to compile with type error. // @@ -20,7 +20,7 @@ object Summary { // traverse a method. // // 4 runtime issues: - // + // // From the outside: inner1.isInstanceOf[outer2.Inner] is true, should (maybe) be false // From inside inner1: inner2.isInstanceOf[Outer.this.Inner] is true, should (maybe) be false // From the outside: inner1 match { case _: outer2.Inner => true ... } is true, should definitely be false @@ -44,13 +44,13 @@ class Outer { def passInner(other: Inner) = () // pass only Inners from this Outer instance def passInner2(other: Outer.this.Inner) = () // same as above def passInnerSharp(other: Outer#Inner) = () // pass any Inner - + def compareSimpleWithTypeMatch(other: Any) = other match { case _: Inner => true case _ => false } def compareSimpleWithInstanceOf(other: Any) = other.isInstanceOf[Inner] - + def compareSharpWithTypeMatch(other: Any) = { other match { case _: Outer#Inner => true @@ -58,16 +58,16 @@ class Outer { } } def compareSharpWithInstanceOf(other: Any) = other.isInstanceOf[Outer#Inner] - + def comparePathWithTypeMatch(other: Any) = other match { case _: Outer.this.Inner => true case _ => false } - def comparePathWithInstanceOf(other: Any) = other.isInstanceOf[Outer.this.Inner] + def comparePathWithInstanceOf(other: Any) = other.isInstanceOf[Outer.this.Inner] } - + def f() = { - class MethodInner { + class MethodInner { def passOuter(other: Outer) = () // pass any Outer def passThisType(other: Outer.this.type) = () // pass only this Outer instance def passInner(other: Inner) = () // pass only Inners from this Outer instance @@ -75,14 +75,14 @@ class Outer { def passInnerSharp(other: Outer#Inner) = () // pass any Inner def passMethodInner(other: MethodInner) = () // pass only MethodInners from this Outer instance // is there any way to refer to Outer#MethodInner? Not that there should be. - + def compareWithInstanceOf(other: Any) = other.isInstanceOf[MethodInner] def compareWithTypeMatch(other: Any) = other match { case _: MethodInner => true case _ => false } } - + new MethodInner } } @@ -94,7 +94,7 @@ object Test { val inner2 = new outer2.Inner val method1 = outer1.f() val method2 = outer2.f() - + def testInnerStatic = { // these should all work inner1.passOuter(outer1) @@ -104,7 +104,7 @@ object Test { inner1.passInner2(inner1) inner1.passInnerSharp(inner1) inner1.passInnerSharp(inner2) - + // these should all fail to compile, and do // // inner1.passThisType(outer2) @@ -113,30 +113,30 @@ object Test { } def testInnerRuntime = { println("testInnerRuntime\n") - + List("These should be true under any scenario: ", - inner1.isInstanceOf[outer1.Inner] , + inner1.isInstanceOf[outer1.Inner] , inner1.isInstanceOf[Outer#Inner] , (inner1: Any) match { case _: Outer#Inner => true ; case _ => false } , (inner1: Any) match { case _: outer1.Inner => true ; case _ => false } , inner1.compareSharpWithTypeMatch(inner2) , inner1.compareSharpWithInstanceOf(inner2) ) foreach println - + List("These should be true under current proposal: ", - inner1.compareSimpleWithInstanceOf(inner2) + inner1.compareSimpleWithInstanceOf(inner2) ) foreach println - + List("These should be false under current proposal: ", inner1.compareSimpleWithTypeMatch(inner2) , - inner1.comparePathWithTypeMatch(inner2) + inner1.comparePathWithTypeMatch(inner2) ) foreach println - - List("These return true but I think should return false: ", + + List("These return true but I think should return false: ", inner1.isInstanceOf[outer2.Inner] , // true inner1.comparePathWithInstanceOf(inner2) // true ) foreach println - + List("These are doing the wrong thing under current proposal", (inner1: Any) match { case _: outer2.Inner => true ; case _ => false } // should be false ) foreach println @@ -159,7 +159,7 @@ object Test { // method1.passMethodInner(method1) // ^ method1.passMethodInner(method1) - + // these should all fail to compile, and do // // method1.passThisType(outer2) @@ -167,24 +167,24 @@ object Test { // method1.passInner2(inner2) // method1.passMethodInner(method2) } - + def testMethodInnerRuntime = { println("\ntestMethodInnerRuntime\n") - + List("These should be true under any scenario: ", method1.compareWithInstanceOf(method1) , - method1.compareWithTypeMatch(method1) + method1.compareWithTypeMatch(method1) ) foreach println - + List("These should be true under current proposal: ", method1.compareWithInstanceOf(method2) ) foreach println - + List("These are doing the wrong thing under current proposal", method1.compareWithTypeMatch(method2) // should be false ) foreach println } - + def main(args: Array[String]): Unit = { testInnerRuntime testMethodInnerRuntime diff --git a/test/pending/run/sigtp.scala b/test/pending/run/sigtp.scala index 3e162cfdba..f8e050dbdc 100644 --- a/test/pending/run/sigtp.scala +++ b/test/pending/run/sigtp.scala @@ -12,6 +12,6 @@ final class Bug[A, B](val key: A) extends BugBase[A, Bug[A, B]] { object Test extends SigTest { def main(args: Array[String]): Unit = { show[BugBase[_, _]]() - show[Bug[_, _]]() + show[Bug[_, _]]() } } diff --git a/test/pending/run/string-reverse.scala b/test/pending/run/string-reverse.scala index 51b16bcd6a..976a970dec 100644 --- a/test/pending/run/string-reverse.scala +++ b/test/pending/run/string-reverse.scala @@ -6,13 +6,13 @@ object Test { val ys = "Les Misérables" val xs2 = new StringBuilder(xs) val ys2 = new StringBuilder(ys) - + def main(args: Array[String]): Unit = { val out = new java.io.PrintStream(System.out, true, "UTF-8") - + out.println("Strings") List(xs, xs.reverse, ys, ys.reverse) foreach (out println _) - + out.println("StringBuilder") out.println(xs2.toString) out.println(xs2.reverseContents().toString) diff --git a/test/pending/run/structural-types-vs-anon-classes.scala b/test/pending/run/structural-types-vs-anon-classes.scala index cf68f831f5..23410e3955 100644 --- a/test/pending/run/structural-types-vs-anon-classes.scala +++ b/test/pending/run/structural-types-vs-anon-classes.scala @@ -3,14 +3,14 @@ object Test { class Leg class Tail class Monkey(arms: List[Arm], legs :List[Leg], tail: Tail) - + def makeAwesomeMonkey(arms: List[Arm], legs: List[Leg], tail: Tail) = { object m extends Monkey(arms, legs, tail) { def beAwesome () = "I can fly! I can fly!" } m } - + def main(args: Array[String]): Unit = { println(makeAwesomeMonkey(Nil, Nil, new Tail) beAwesome) } diff --git a/test/pending/run/t0508x.scala b/test/pending/run/t0508x.scala index 0c1ffde3ed..12d3d09711 100644 --- a/test/pending/run/t0508x.scala +++ b/test/pending/run/t0508x.scala @@ -4,12 +4,12 @@ }; def foo[A >: Nothing <: Any, B >: Nothing <: Any, C >: Nothing <: Any] - (unapply1: (A) => Option[(B, C)], v: A): Unit = + (unapply1: (A) => Option[(B, C)], v: A): Unit = unapply1.apply(v) match { - case Some((fst @ _, snd @ _)) => + case Some((fst @ _, snd @ _)) => scala.Predef.println(scala.Tuple2.apply[java.lang.String, java.lang.String]("first: ".+(fst), " second: ".+(snd))) case _ => scala.Predef.println(":(") - } + } Test.this.foo[Test.Foo, String, Int]({ ((eta$0$1: Test.Foo) => Test.this.Foo.unapply(eta$0$1)) }, Test.this.Foo.apply("this might be fun", 10)); diff --git a/test/pending/run/t1980.scala b/test/pending/run/t1980.scala index 38353c6270..71c178d634 100644 --- a/test/pending/run/t1980.scala +++ b/test/pending/run/t1980.scala @@ -2,7 +2,7 @@ // Reported by: extempore Owned by: odersky // Priority: normal Component: Compiler // Keywords: Cc: paulp@… -// Fixed in version: +// Fixed in version: // Description scala> def foo() = { println("foo") ; 5 } diff --git a/test/pending/run/t2318.scala b/test/pending/run/t2318.scala index 7bb666706f..e42cbb9680 100644 --- a/test/pending/run/t2318.scala +++ b/test/pending/run/t2318.scala @@ -2,7 +2,7 @@ import java.security._ object Test { trait Bar { def bar: Unit } - + object Mgr extends SecurityManager { override def checkPermission(perm: Permission) = perm match { case _: java.lang.RuntimePermission => () @@ -11,11 +11,11 @@ object Test { case _ => super.checkPermission(perm) } } - + def t1() = { val p = Runtime.getRuntime().exec("ls"); type Destroyable = { def destroy() : Unit } - def doDestroy( obj : Destroyable ) : Unit = obj.destroy(); + def doDestroy( obj : Destroyable ) : Unit = obj.destroy(); doDestroy( p ); } def t2() = { @@ -27,12 +27,12 @@ object Test { val structural = b.asInstanceOf[{ def bar: Unit }] structural.bar } - + def main(args: Array[String]) { // figuring this will otherwise break on windows try t1() catch { case _: java.io.IOException => () } - + t2() } } diff --git a/test/pending/run/t3609.scala b/test/pending/run/t3609.scala index 030b417044..eb25afd667 100755 --- a/test/pending/run/t3609.scala +++ b/test/pending/run/t3609.scala @@ -11,7 +11,7 @@ object Test extends Application { } // This code prints 1. If we remove comment, then it will print 4. -// Moreover following code prints 3 (which is most strange thing): +// Moreover following code prints 3 (which is most strange thing): object Test2 extends Application { class A diff --git a/test/pending/run/t3669.scala b/test/pending/run/t3669.scala index 4fd698c1a5..c60ba98538 100644 --- a/test/pending/run/t3669.scala +++ b/test/pending/run/t3669.scala @@ -1,5 +1,5 @@ trait MyTrait[T <: { var id: U }, U] { - def test(t: T): T = { + def test(t: T): T = { val v: U = t.id t.id = v t diff --git a/test/pending/run/t3857.scala b/test/pending/run/t3857.scala index 94f52f72fe..62bdc39da9 100644 --- a/test/pending/run/t3857.scala +++ b/test/pending/run/t3857.scala @@ -8,6 +8,6 @@ object Test extends SigTest { def main(args: Array[String]): Unit = { show[ScalaGeneric]() show[ScalaGeneric2Trait]() - show[ScalaGeneric2]() + show[ScalaGeneric2]() } } diff --git a/test/pending/run/t4283/IllegalAccess.scala b/test/pending/run/t4283/IllegalAccess.scala index 12de7e4649..33039c9350 100644 --- a/test/pending/run/t4283/IllegalAccess.scala +++ b/test/pending/run/t4283/IllegalAccess.scala @@ -2,7 +2,7 @@ package other object IllegalAccess { def main(args: Array[String]) { - val x = (new test.ScalaBipp).make.get.asInstanceOf[test.ScalaBipp].f() + val x = (new test.ScalaBipp).make.get.asInstanceOf[test.ScalaBipp].f() println(x) val y = (new test.ScalaBipp).make.get.f() println(y) diff --git a/test/pending/scalacheck/process.scala b/test/pending/scalacheck/process.scala index 1e06c4669e..f3aa872361 100644 --- a/test/pending/scalacheck/process.scala +++ b/test/pending/scalacheck/process.scala @@ -1,4 +1,4 @@ -/** process tests. +/** process tests. */ import java.io.{ File, FileNotFoundException, IOException, InputStream, OutputStream, FileInputStream } @@ -11,7 +11,7 @@ import scala.tools.nsc.io.{ File => SFile } /** This has scrounged bits of sbt to flesh it out enough to run. */ package processtest { - + object exit { def fn(code: Int) = System.exit(code) @@ -77,7 +77,7 @@ object IO { class ProcessSpecification extends Properties("Process I/O") { implicit val exitCodeArb: Arbitrary[Array[Byte]] = Arbitrary(Gen.choose(0, 10) flatMap { size => - Gen.resize(size, Arbitrary.arbArray[Byte].arbitrary) + Gen.resize(size, Arbitrary.arbArray[Byte].arbitrary) }) /*property("Correct exit code") = forAll( (exitCode: Byte) => checkExit(exitCode)) diff --git a/test/pending/script/t2365/Test.scala b/test/pending/script/t2365/Test.scala index 53581d256b..110dea2ab6 100644 --- a/test/pending/script/t2365/Test.scala +++ b/test/pending/script/t2365/Test.scala @@ -17,17 +17,17 @@ object Test for(i <- 0 until 150) println(i + " " + test(A.apply) + " " + test(A2.apply) + " " + test(A3.apply) + " " + test(A3.apply)) } - + def test(withF0: StructF0 => Int): Int = { // Some large jar val jar = File("../../../../lib/scalacheck.jar").toURL // load a class in a separate loader that will be passed to A val loader = new java.net.URLClassLoader(Array(File(".").toURL, jar)) // load a real class to fill perm gen space - Class.forName("org.scalacheck.Properties", true, loader).newInstance + Class.forName("org.scalacheck.Properties", true, loader).newInstance // create a class from another class loader with an apply: Int method val b = Class.forName("B", true, loader).newInstance - + // pass instance to a, which will call apply using structural type reflection. // This should hold on to the class for B, which means bLoader will not get collected withF0(b.asInstanceOf[StructF0]) diff --git a/test/pending/shootout/fasta.check b/test/pending/shootout/fasta.check new file mode 100644 index 0000000000..f1caba0d62 --- /dev/null +++ b/test/pending/shootout/fasta.check @@ -0,0 +1,171 @@ +>ONE Homo sapiens alu +GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA +TCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACT +AAAAATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAG +GCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCG +CCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAAGGCCGGGCGCGGT +GGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCA +GGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAA +TTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAG +AATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCCA +GCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAAGGCCGGGCGCGGTGGCTCACGCCTGT +AATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGACC +AGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAATTAGCCGGGCGTG +GTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACC +CGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCCAGCCTGGGCGACAG +AGCGAGACTCCGTCTCAAAAAGGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTT +TGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACA +TGGTGAAACCCCGTCTCTACTAAAAATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCT +GTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGG +TTGCAGTGAGCCGAGATCGCGCCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGT +CTCAAAAAGGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGG +CGGGCGGATCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCG +TCTCTACTAAAAATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTA +CTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCG +AGATCGCGCCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAAGGCCG +GGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACC +TGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAA +TACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGA +GGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACT +GCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAAGGCCGGGCGCGGTGGCTC +ACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGT +TCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAATTAGC +CGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCG +CTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCCAGCCTG +GGCGACAGAGCGAGACTCCG +>TWO IUB ambiguity codes +cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg +tactDtDagcctatttSVHtHttKtgtHMaSattgWaHKHttttagacatWatgtRgaaa +NtactMcSMtYtcMgRtacttctWBacgaaatatagScDtttgaagacacatagtVgYgt +cattHWtMMWcStgttaggKtSgaYaaccWStcgBttgcgaMttBYatcWtgacaYcaga +gtaBDtRacttttcWatMttDBcatWtatcttactaBgaYtcttgttttttttYaaScYa +HgtgttNtSatcMtcVaaaStccRcctDaataataStcYtRDSaMtDttgttSagtRRca +tttHatSttMtWgtcgtatSSagactYaaattcaMtWatttaSgYttaRgKaRtccactt +tattRggaMcDaWaWagttttgacatgttctacaaaRaatataataaMttcgDacgaSSt +acaStYRctVaNMtMgtaggcKatcttttattaaaaagVWaHKYagtttttatttaacct +tacgtVtcVaattVMBcttaMtttaStgacttagattWWacVtgWYagWVRctDattBYt +gtttaagaagattattgacVatMaacattVctgtBSgaVtgWWggaKHaatKWcBScSWa +accRVacacaaactaccScattRatatKVtactatatttHttaagtttSKtRtacaaagt +RDttcaaaaWgcacatWaDgtDKacgaacaattacaRNWaatHtttStgttattaaMtgt +tgDcgtMgcatBtgcttcgcgaDWgagctgcgaggggVtaaScNatttacttaatgacag +cccccacatYScaMgtaggtYaNgttctgaMaacNaMRaacaaacaKctacatagYWctg +ttWaaataaaataRattagHacacaagcgKatacBttRttaagtatttccgatctHSaat +actcNttMaagtattMtgRtgaMgcataatHcMtaBSaRattagttgatHtMttaaKagg +YtaaBataSaVatactWtataVWgKgttaaaacagtgcgRatatacatVtHRtVYataSa +KtWaStVcNKHKttactatccctcatgWHatWaRcttactaggatctataDtDHBttata +aaaHgtacVtagaYttYaKcctattcttcttaataNDaaggaaaDYgcggctaaWSctBa +aNtgctggMBaKctaMVKagBaactaWaDaMaccYVtNtaHtVWtKgRtcaaNtYaNacg +gtttNattgVtttctgtBaWgtaattcaagtcaVWtactNggattctttaYtaaagccgc +tcttagHVggaYtgtNcDaVagctctctKgacgtatagYcctRYHDtgBattDaaDgccK +tcHaaStttMcctagtattgcRgWBaVatHaaaataYtgtttagMDMRtaataaggatMt +ttctWgtNtgtgaaaaMaatatRtttMtDgHHtgtcattttcWattRSHcVagaagtacg +ggtaKVattKYagactNaatgtttgKMMgYNtcccgSKttctaStatatNVataYHgtNa +BKRgNacaactgatttcctttaNcgatttctctataScaHtataRagtcRVttacDSDtt +aRtSatacHgtSKacYagttMHtWataggatgactNtatSaNctataVtttRNKtgRacc +tttYtatgttactttttcctttaaacatacaHactMacacggtWataMtBVacRaSaatc +cgtaBVttccagccBcttaRKtgtgcctttttRtgtcagcRttKtaaacKtaaatctcac +aattgcaNtSBaaccgggttattaaBcKatDagttactcttcattVtttHaaggctKKga +tacatcBggScagtVcacattttgaHaDSgHatRMaHWggtatatRgccDttcgtatcga +aacaHtaagttaRatgaVacttagattVKtaaYttaaatcaNatccRttRRaMScNaaaD +gttVHWgtcHaaHgacVaWtgttScactaagSgttatcttagggDtaccagWattWtRtg +ttHWHacgattBtgVcaYatcggttgagKcWtKKcaVtgaYgWctgYggVctgtHgaNcV +taBtWaaYatcDRaaRtSctgaHaYRttagatMatgcatttNattaDttaattgttctaa +ccctcccctagaWBtttHtBccttagaVaatMcBHagaVcWcagBVttcBtaYMccagat +gaaaaHctctaacgttagNWRtcggattNatcRaNHttcagtKttttgWatWttcSaNgg +gaWtactKKMaacatKatacNattgctWtatctaVgagctatgtRaHtYcWcttagccaa +tYttWttaWSSttaHcaaaaagVacVgtaVaRMgattaVcDactttcHHggHRtgNcctt +tYatcatKgctcctctatVcaaaaKaaaagtatatctgMtWtaaaacaStttMtcgactt +taSatcgDataaactaaacaagtaaVctaggaSccaatMVtaaSKNVattttgHccatca +cBVctgcaVatVttRtactgtVcaattHgtaaattaaattttYtatattaaRSgYtgBag +aHSBDgtagcacRHtYcBgtcacttacactaYcgctWtattgSHtSatcataaatataHt +cgtYaaMNgBaatttaRgaMaatatttBtttaaaHHKaatctgatWatYaacttMctctt +ttVctagctDaaagtaVaKaKRtaacBgtatccaaccactHHaagaagaaggaNaaatBW +attccgStaMSaMatBttgcatgRSacgttVVtaaDMtcSgVatWcaSatcttttVatag +ttactttacgatcaccNtaDVgSRcgVcgtgaacgaNtaNatatagtHtMgtHcMtagaa +attBgtataRaaaacaYKgtRccYtatgaagtaataKgtaaMttgaaRVatgcagaKStc +tHNaaatctBBtcttaYaBWHgtVtgacagcaRcataWctcaBcYacYgatDgtDHccta +>THREE Homo sapiens frequency +aacacttcaccaggtatcgtgaaggctcaagattacccagagaacctttgcaatataaga +atatgtatgcagcattaccctaagtaattatattctttttctgactcaaagtgacaagcc +ctagtgtatattaaatcggtatatttgggaaattcctcaaactatcctaatcaggtagcc +atgaaagtgatcaaaaaagttcgtacttataccatacatgaattctggccaagtaaaaaa +tagattgcgcaaaattcgtaccttaagtctctcgccaagatattaggatcctattactca +tatcgtgtttttctttattgccgccatccccggagtatctcacccatccttctcttaaag +gcctaatattacctatgcaaataaacatatattgttgaaaattgagaacctgatcgtgat +tcttatgtgtaccatatgtatagtaatcacgcgactatatagtgctttagtatcgcccgt +gggtgagtgaatattctgggctagcgtgagatagtttcttgtcctaatatttttcagatc +gaatagcttctatttttgtgtttattgacatatgtcgaaactccttactcagtgaaagtc +atgaccagatccacgaacaatcttcggaatcagtctcgttttacggcggaatcttgagtc +taacttatatcccgtcgcttactttctaacaccccttatgtatttttaaaattacgttta +ttcgaacgtacttggcggaagcgttattttttgaagtaagttacattgggcagactcttg +acattttcgatacgactttctttcatccatcacaggactcgttcgtattgatatcagaag +ctcgtgatgattagttgtcttctttaccaatactttgaggcctattctgcgaaatttttg +ttgccctgcgaacttcacataccaaggaacacctcgcaacatgccttcatatccatcgtt +cattgtaattcttacacaatgaatcctaagtaattacatccctgcgtaaaagatggtagg +ggcactgaggatatattaccaagcatttagttatgagtaatcagcaatgtttcttgtatt +aagttctctaaaatagttacatcgtaatgttatctcgggttccgcgaataaacgagatag +attcattatatatggccctaagcaaaaacctcctcgtattctgttggtaattagaatcac +acaatacgggttgagatattaattatttgtagtacgaagagatataaaaagatgaacaat +tactcaagtcaagatgtatacgggatttataataaaaatcgggtagagatctgctttgca +attcagacgtgccactaaatcgtaatatgtcgcgttacatcagaaagggtaactattatt +aattaataaagggcttaatcactacatattagatcttatccgatagtcttatctattcgt +tgtatttttaagcggttctaattcagtcattatatcagtgctccgagttctttattattg +ttttaaggatgacaaaatgcctcttgttataacgctgggagaagcagactaagagtcgga +gcagttggtagaatgaggctgcaaaagacggtctcgacgaatggacagactttactaaac +caatgaaagacagaagtagagcaaagtctgaagtggtatcagcttaattatgacaaccct +taatacttccctttcgccgaatactggcgtggaaaggttttaaaagtcgaagtagttaga +ggcatctctcgctcataaataggtagactactcgcaatccaatgtgactatgtaatactg +ggaacatcagtccgcgatgcagcgtgtttatcaaccgtccccactcgcctggggagacat +gagaccacccccgtggggattattagtccgcagtaatcgactcttgacaatccttttcga +ttatgtcatagcaatttacgacagttcagcgaagtgactactcggcgaaatggtattact +aaagcattcgaacccacatgaatgtgattcttggcaatttctaatccactaaagcttttc +cgttgaatctggttgtagatatttatataagttcactaattaagatcacggtagtatatt +gatagtgatgtctttgcaagaggttggccgaggaatttacggattctctattgatacaat +ttgtctggcttataactcttaaggctgaaccaggcgtttttagacgacttgatcagctgt +tagaatggtttggactccctctttcatgtcagtaacatttcagccgttattgttacgata +tgcttgaacaatattgatctaccacacacccatagtatattttataggtcatgctgttac +ctacgagcatggtattccacttcccattcaatgagtattcaacatcactagcctcagaga +tgatgacccacctctaataacgtcacgttgcggccatgtgaaacctgaacttgagtagac +gatatcaagcgctttaaattgcatataacatttgagggtaaagctaagcggatgctttat +ataatcaatactcaataataagatttgattgcattttagagttatgacacgacatagttc +actaacgagttactattcccagatctagactgaagtactgatcgagacgatccttacgtc +gatgatcgttagttatcgacttaggtcgggtctctagcggtattggtacttaaccggaca +ctatactaataacccatgatcaaagcataacagaatacagacgataatttcgccaacata +tatgtacagaccccaagcatgagaagctcattgaaagctatcattgaagtcccgctcaca +atgtgtcttttccagacggtttaactggttcccgggagtcctggagtttcgacttacata +aatggaaacaatgtattttgctaatttatctatagcgtcatttggaccaatacagaatat +tatgttgcctagtaatccactataacccgcaagtgctgatagaaaatttttagacgattt +ataaatgccccaagtatccctcccgtgaatcctccgttatactaattagtattcgttcat +acgtataccgcgcatatatgaacatttggcgataaggcgcgtgaattgttacgtgacaga +gatagcagtttcttgtgatatggttaacagacgtacatgaagggaaactttatatctata +gtgatgcttccgtagaaataccgccactggtctgccaatgatgaagtatgtagctttagg +tttgtactatgaggctttcgtttgtttgcagagtataacagttgcgagtgaaaaaccgac +gaatttatactaatacgctttcactattggctacaaaatagggaagagtttcaatcatga +gagggagtatatggatgctttgtagctaaaggtagaacgtatgtatatgctgccgttcat +tcttgaaagatacataagcgataagttacgacaattataagcaacatccctaccttcgta +acgatttcactgttactgcgcttgaaatacactatggggctattggcggagagaagcaga +tcgcgccgagcatatacgagacctataatgttgatgatagagaaggcgtctgaattgata +catcgaagtacactttctttcgtagtatctctcgtcctctttctatctccggacacaaga +attaagttatatatatagagtcttaccaatcatgttgaatcctgattctcagagttcttt +ggcgggccttgtgatgactgagaaacaatgcaatattgctccaaatttcctaagcaaatt +ctcggttatgttatgttatcagcaaagcgttacgttatgttatttaaatctggaatgacg +gagcgaagttcttatgtcggtgtgggaataattcttttgaagacagcactccttaaataa +tatcgctccgtgtttgtatttatcgaatgggtctgtaaccttgcacaagcaaatcggtgg +tgtatatatcggataacaattaatacgatgttcatagtgacagtatactgatcgagtcct +ctaaagtcaattacctcacttaacaatctcattgatgttgtgtcattcccggtatcgccc +gtagtatgtgctctgattgaccgagtgtgaaccaaggaacatctactaatgcctttgtta +ggtaagatctctctgaattccttcgtgccaacttaaaacattatcaaaatttcttctact +tggattaactacttttacgagcatggcaaattcccctgtggaagacggttcattattatc +ggaaaccttatagaaattgcgtgttgactgaaattagatttttattgtaagagttgcatc +tttgcgattcctctggtctagcttccaatgaacagtcctcccttctattcgacatcgggt +ccttcgtacatgtctttgcgatgtaataattaggttcggagtgtggccttaatgggtgca +actaggaatacaacgcaaatttgctgacatgatagcaaatcggtatgccggcaccaaaac +gtgctccttgcttagcttgtgaatgagactcagtagttaaataaatccatatctgcaatc +gattccacaggtattgtccactatctttgaactactctaagagatacaagcttagctgag +accgaggtgtatatgactacgctgatatctgtaaggtaccaatgcaggcaaagtatgcga +gaagctaataccggctgtttccagctttataagattaaaatttggctgtcctggcggcct +cagaattgttctatcgtaatcagttggttcattaattagctaagtacgaggtacaactta +tctgtcccagaacagctccacaagtttttttacagccgaaacccctgtgtgaatcttaat +atccaagcgcgttatctgattagagtttacaactcagtattttatcagtacgttttgttt +ccaacattacccggtatgacaaaatgacgccacgtgtcgaataatggtctgaccaatgta +ggaagtgaaaagataaatat diff --git a/test/pending/shootout/fasta.scala b/test/pending/shootout/fasta.scala new file mode 100644 index 0000000000..8b711083a5 --- /dev/null +++ b/test/pending/shootout/fasta.scala @@ -0,0 +1,162 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + +import java.io._ + +object fasta { + def main(args: Array[String]) = { + + val ALU = + "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + + "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + + "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" + + "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" + + "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" + + "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" + + "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" + + val _IUB = Array( + Pair('a', 0.27), + Pair('c', 0.12), + Pair('g', 0.12), + Pair('t', 0.27), + + Pair('B', 0.02), + Pair('D', 0.02), + Pair('H', 0.02), + Pair('K', 0.02), + Pair('M', 0.02), + Pair('N', 0.02), + Pair('R', 0.02), + Pair('S', 0.02), + Pair('V', 0.02), + Pair('W', 0.02), + Pair('Y', 0.02) + ) + + val IUB = makeCumulative(_IUB) + + val _HomoSapiens = Array( + Pair('a', 0.3029549426680), + Pair('c', 0.1979883004921), + Pair('g', 0.1975473066391), + Pair('t', 0.3015094502008) + ) + + val HomoSapiens = makeCumulative(_HomoSapiens) + + + val n = Integer parseInt(args(0)) + val s = new FastaOutputStream(System.out) + + s.writeDescription("ONE Homo sapiens alu") + s.writeRepeatingSequence(ALU,n*2) + + s.writeDescription("TWO IUB ambiguity codes") + s.writeRandomSequence(IUB,n*3) + + s.writeDescription("THREE Homo sapiens frequency") + s.writeRandomSequence(HomoSapiens,n*5) + + s.close + } + + def makeCumulative(a: Array[Pair[Char,Double]]) = { + var cp = 0.0 + a map (frequency => + frequency match { + case Pair(code,percent) => + cp = cp + percent; new Frequency(code.toByte,cp) + } + ) + } + +} + + +// We could use instances of Pair or Tuple2 but specific labels +// make the code more readable than index numbers + +class Frequency(_code: Byte, _percent: Double){ + var code = _code; var percent = _percent; +} + + +// extend the Java BufferedOutputStream class + +class FastaOutputStream(out: OutputStream) extends BufferedOutputStream(out) { + + private val LineLength = 60 + private val nl = '\n'.toByte + + def writeDescription(desc: String) = { write( (">" + desc + "\n").getBytes ) } + + def writeRepeatingSequence(_alu: String, length: Int) = { + val alu = _alu.getBytes + var n = length; var k = 0; val kn = alu.length; + + while (n > 0) { + val m = if (n < LineLength) n else LineLength + + var i = 0 + while (i < m){ + if (k == kn) k = 0 + val b = alu(k) + if (count < buf.length){ buf(count) = b; count = count + 1 } + else { write(b) } // flush buffer + k = k+1 + i = i+1 + } + + write(nl) + n = n - LineLength + } + + } + + def writeRandomSequence(distribution: Array[Frequency], length: Int) = { + var n = length + while (n > 0) { + val m = if (n < LineLength) n else LineLength + + var i = 0 + while (i < m){ + val b = selectRandom(distribution) + if (count < buf.length){ buf(count) = b; count = count + 1 } + else { write(b) } // flush buffer + i = i+1 + } + + if (count < buf.length){ buf(count) = nl; count = count + 1 } + else { write(nl) } // flush buffer + n = n - LineLength + } + } + + private def selectRandom(distribution: Array[Frequency]): Byte = { + val n = distribution.length + val r = RandomNumber scaledTo(1.0) + + var i = 0 + while (i < n) { + if (r < distribution(i).percent) return distribution(i).code + i = i+1 + } + return distribution(n-1).code + } +} + + +object RandomNumber { + private val IM = 139968 + private val IA = 3877 + private val IC = 29573 + private var seed = 42 + + def scaledTo(max: Double) = { + seed = (seed * IA + IC) % IM + max * seed / IM + } +} diff --git a/test/pending/shootout/fasta.scala.runner b/test/pending/shootout/fasta.scala.runner new file mode 100644 index 0000000000..e95a749cf2 --- /dev/null +++ b/test/pending/shootout/fasta.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(25000,250000,2500000)) fasta.main(Array(n.toString)) +} diff --git a/test/pending/shootout/harmonic.scala-2.scala b/test/pending/shootout/harmonic.scala-2.scala new file mode 100644 index 0000000000..a55e164e50 --- /dev/null +++ b/test/pending/shootout/harmonic.scala-2.scala @@ -0,0 +1,14 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy (Scala novice) +*/ + +object harmonic { + def main(args: Array[String]) = { + val n = Integer.parseInt(args(0)); + var partialSum = 0.0; + + for (i <- Iterator.range(1,n+1)) partialSum = partialSum + 1.0/i; + Console.printf("{0,number,#.000000000}\n")(partialSum); + } +} diff --git a/test/pending/shootout/harmonic.scala-2.scala.runner b/test/pending/shootout/harmonic.scala-2.scala.runner new file mode 100644 index 0000000000..d0ea85742a --- /dev/null +++ b/test/pending/shootout/harmonic.scala-2.scala.runner @@ -0,0 +1,16 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy (Scala novice) +*/ +object Test extends Application { + for(n <- List(6000000,8000000,10000000)) harmonic.main(Array(n.toString)) +} +object harmonic { + def main(args: Array[String]) = { + val n = Integer.parseInt(args(0)); + var partialSum = 0.0; + + for (i <- Iterator.range(1,n+1)) partialSum = partialSum + 1.0/i; + Console.printf("{0,number,#.000000000}\n")(partialSum); + } +} diff --git a/test/pending/shootout/harmonic.scala-3.scala b/test/pending/shootout/harmonic.scala-3.scala new file mode 100644 index 0000000000..dc631fcf12 --- /dev/null +++ b/test/pending/shootout/harmonic.scala-3.scala @@ -0,0 +1,15 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy (Scala novice) +*/ + +object harmonic { + def main(args: Array[String]) = { + val n = Integer.parseInt(args(0)); + var partialSum = 0.0; + var i = 1; + + while (i < n){ partialSum = partialSum + 1.0/i; i = i + 1; } + Console.printf("{0,number,#.000000000}\n", partialSum); + } +} diff --git a/test/pending/shootout/harmonic.scala-3.scala.runner b/test/pending/shootout/harmonic.scala-3.scala.runner new file mode 100644 index 0000000000..b5eda3f034 --- /dev/null +++ b/test/pending/shootout/harmonic.scala-3.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(6000000,8000000,10000000)) harmonic.main(Array(n.toString)) +} diff --git a/test/pending/shootout/heapsort.scala b/test/pending/shootout/heapsort.scala new file mode 100644 index 0000000000..59b1fe27cb --- /dev/null +++ b/test/pending/shootout/heapsort.scala @@ -0,0 +1,72 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy (Scala novice) +*/ + +object heapsort { + def main(args: Array[String]) = { + val n = toPositiveInt(args); + + val numbers = new Array[Double](n+1); + for (i <- Iterator.range(1,n+1)) + numbers(i) = generate(100.0); + + heapsort(n, numbers); + + Console.printf("{0,number,#.000000000}\n", numbers(n)); + } + + + def heapsort(n: Int, ra: Array[Double]): Unit = { + var l = 0; var j = 0; var ir = 0; var i = 0; + var rra = 0.0d; + + if (n < 2) return; + l = (n >> 1) + 1; + ir = n; + while (true) { + if (l > 1) { l = l-1; rra = ra(l); } + else { + rra = ra(ir); + ra(ir) = ra(1); + ir = ir-1; + if (ir == 1) { + ra(1) = rra; + return; + } + } + i = l; + j = l << 1; + while (j <= ir) { + if (j < ir && ra(j) < ra(j+1)) { j = j+1; } + if (rra < ra(j)) { + ra(i) = ra(j); + i = j; + j = j + i; + } + else j = ir + 1; + } + ra(i) = rra; + } + } + + + private val IM = 139968; + private val IA = 3877; + private val IC = 29573; + private var seed = 42; + + private def generate(max: Double) = { + seed = (seed * IA + IC) % IM; + max * seed / IM; + } + + + private def toPositiveInt(s: Array[String]) = { + val i = + try { Integer.parseInt(s(0)); } + catch { case _ => 1 } + if (i>0) i; else 1; + } + +} diff --git a/test/pending/shootout/heapsort.scala.runner b/test/pending/shootout/heapsort.scala.runner new file mode 100644 index 0000000000..07e4ec7fbd --- /dev/null +++ b/test/pending/shootout/heapsort.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(20000,40000,60000,80000,100000)) heapsort.main(Array(n.toString)) +} diff --git a/test/pending/shootout/mandelbrot.scala-2.check b/test/pending/shootout/mandelbrot.scala-2.check Binary files differnew file mode 100644 index 0000000000..2f7bbbc6b0 --- /dev/null +++ b/test/pending/shootout/mandelbrot.scala-2.check diff --git a/test/pending/shootout/mandelbrot.scala-2.scala b/test/pending/shootout/mandelbrot.scala-2.scala new file mode 100644 index 0000000000..dffdc354a0 --- /dev/null +++ b/test/pending/shootout/mandelbrot.scala-2.scala @@ -0,0 +1,79 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + +// This test is in pending because it fails on windows only, +// but partest's output and the fact that this test outputs in +// binary makes it a challenge to debug remotely. However, +// it's easy to guess that it has to do with the BufferedOutputStream +// and some kind of windows-specific damage that requires an extra +// flush, or different line-ending characters, or any of the various +// write-once-know-quirks-everywhere aspects of java i/o. +// +// [partest] testing: [...]\files\shootout\mandelbrot.scala-2.scala [FAILED] +// [partest] P4 +// [partest] 200 200 +// [partest] +// ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ +// ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ +// [etc] + +import java.io.BufferedOutputStream + +object mandelbrot { + def main(args: Array[String]) = { + val side = Integer.parseInt(args(0)) + val limitSquared = 4.0 + val max = 50 + var bits = 0 + var bitnum = 0 + val w = new BufferedOutputStream(System.out) + + Console.println("P4\n" + side + " " + side) + + var y = 0 + while (y < side){ + + var x = 0 + while (x < side){ + + val cr = 2.0 * x / side - 1.5 + val ci = 2.0 * y / side - 1.0 + + var zr = 0.0; var zi = 0.0 + var tr = 0.0; var ti = 0.0 + + var j = max + do { + zi = 2.0 * zr * zi + ci + zr = tr - ti + cr + ti = zi*zi + tr = zr*zr + + j = j - 1 + } while (!(tr + ti > limitSquared) && j > 0) + + + bits = bits << 1 + if (!(tr + ti > limitSquared)) bits = bits + 1 + bitnum = bitnum + 1 + + if (x == side - 1){ + bits = bits << (8 - bitnum) + bitnum = 8 + } + + if (bitnum == 8){ + w.write(bits.toByte) + bits = 0 + bitnum = 0 + } + + x = x + 1 + } + y = y + 1 + } + w.close + } +} diff --git a/test/pending/shootout/mandelbrot.scala-2.scala.runner b/test/pending/shootout/mandelbrot.scala-2.scala.runner new file mode 100644 index 0000000000..27f69f6aec --- /dev/null +++ b/test/pending/shootout/mandelbrot.scala-2.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(200,400,600)) mandelbrot.main(Array(n.toString)) +} diff --git a/test/pending/shootout/message.check b/test/pending/shootout/message.check new file mode 100644 index 0000000000..354b2529b2 --- /dev/null +++ b/test/pending/shootout/message.check @@ -0,0 +1 @@ +500000 diff --git a/test/pending/shootout/message.javaopts b/test/pending/shootout/message.javaopts new file mode 100644 index 0000000000..1879c77427 --- /dev/null +++ b/test/pending/shootout/message.javaopts @@ -0,0 +1 @@ +-Xss128k diff --git a/test/pending/shootout/message.scala b/test/pending/shootout/message.scala new file mode 100644 index 0000000000..a7a1dacc9d --- /dev/null +++ b/test/pending/shootout/message.scala @@ -0,0 +1,47 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + + +import scala.concurrent._ + +object message { + def main(args: Array[String]) = { + val n = Integer.parseInt(args(0)) + val nActors = 500 + val finalSum = n * nActors + + case class Message(value: Int) + + class Incrementor(next: Pid) extends Actor { + var sum = 0 + + override def run() = { + while (true) { + receive { + case Message(value) => + val j = value + 1 + if (null != next){ + next ! Message(j) + } else { + sum = sum + j + if (sum >= finalSum){ + Console.println(sum); + System.exit(0) // exit without cleaning up + } + } + } + } + } + + def pid() = { this.start; this.self } + } + + def actorChain(i: Int, a: Pid): Pid = + if (i > 0) actorChain(i-1, new Incrementor(a).pid ) else a + + val firstActor = actorChain(nActors, null) + var i = n; while (i > 0){ firstActor ! Message(0); i = i-1 } + } +} diff --git a/test/pending/shootout/message.scala.runner b/test/pending/shootout/message.scala.runner new file mode 100644 index 0000000000..ffbee1640b --- /dev/null +++ b/test/pending/shootout/message.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(1000,2000,3000)) message.main(Array(n.toString)) +} diff --git a/test/pending/shootout/meteor.scala b/test/pending/shootout/meteor.scala new file mode 100644 index 0000000000..2fd702753a --- /dev/null +++ b/test/pending/shootout/meteor.scala @@ -0,0 +1,496 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + +// This is an un-optimised example implementation + + +import scala.collection.mutable._ + +object meteor { + def main(args: Array[String]) = { + val solver = new Solver( Integer.parseInt(args(0)) ) + solver.findSolutions + solver.printSolutions + } +} + + + + +// Solver.scala +// import scala.collection.mutable._ + +final class Solver (n: Int) { + private var countdown = n + private var first: String = _ + private var last: String = _ + + private val board = new Board() + + val pieces = Array( + new Piece(0), new Piece(1), new Piece(2), new Piece(3), new Piece(4), + new Piece(5), new Piece(6), new Piece(7), new Piece(8), new Piece(9) ) + + val unplaced = new BitSet(pieces.length) + + { unplaced ++= (0 until pieces.length) } + + + def findSolutions(): Unit = { + if (countdown == 0) return + + if (unplaced.size > 0){ + val emptyCellIndex = board.firstEmptyCellIndex + + for (k <- Iterator.range(0,pieces.length)){ + if (unplaced.contains(k)){ + unplaced -= k + + for (i <- Iterator.range(0,Piece.orientations)){ + val piece = pieces(k).nextOrientation + + for (j <- Iterator.range(0,Piece.size)){ + if (board.add(j,emptyCellIndex,piece)) { + + if (!shouldPrune) findSolutions + + board.remove(piece) + } + } + } + unplaced += k + } + } + } + else { + puzzleSolved + } + } + + private def puzzleSolved() = { + val b = board.asString + if (first == null){ + first = b; last = b + } else { + if (b < first){ first = b } else { if (b > last){ last = b } } + } + countdown = countdown - 1 + } + + private def shouldPrune() = { + board.unmark + !board.cells.forall(c => c.contiguousEmptyCells % Piece.size == 0) + } + + + def printSolutions() = { + + def printBoard(s: String) = { + var indent = false + var i = 0 + while (i < s.length){ + if (indent) Console.print(' ') + for (j <- Iterator.range(0,Board.cols)){ + Console.print(s.charAt(i)); Console.print(' ') + i = i + 1 + } + Console.print('\n') + indent = !indent + } + Console.print('\n') + } + + Console.print(n + " solutions found\n\n") + printBoard(first) + printBoard(last) + } + +/* + def printPieces() = + for (i <- Iterator.range(0,Board.pieces)) pieces(i).print +*/ + +} + + + + +// Board.scala +// import scala.collection.mutable._ + +object Board { + val cols = 5 + val rows = 10 + val size = rows * cols +} + +final class Board { + val cells = boardCells() + + val cellsPieceWillFill = new Array[BoardCell](Piece.size) + var cellCount = 0 + + def unmark() = for (c <- cells) c.unmark + + def asString() = + new String( cells map( + c => if (c.piece == null) '-'.toByte + else (c.piece.number + 48).toByte )) + + def firstEmptyCellIndex() = cells.findIndexOf(c => c.isEmpty) + + def add(pieceIndex: Int, boardIndex: Int, p: Piece) = { + cellCount = 0 + p.unmark + + find( p.cells(pieceIndex), cells(boardIndex)) + + val boardHasSpace = cellCount == Piece.size && + cellsPieceWillFill.forall(c => c.isEmpty) + + if (boardHasSpace) cellsPieceWillFill.foreach(c => c.piece = p) + + boardHasSpace + } + + def remove(piece: Piece) = for (c <- cells; if c.piece == piece) c.empty + + + private def find(p: PieceCell, b: BoardCell): Unit = { + if (p != null && !p.marked && b != null){ + cellsPieceWillFill(cellCount) = b + cellCount = cellCount + 1 + p.mark + for (i <- Iterator.range(0,Cell.sides)) find(p.next(i), b.next(i)) + } + } + + + private def boardCells() = { + val a = for (i <- Array.range(0,Board.size)) yield new BoardCell(i) + val m = (Board.size / Board.cols) - 1 + + for (i <- Iterator.range(0,a.length)){ + val row = i / Board.cols + val isFirst = i % Board.cols == 0 + val isLast = (i+1) % Board.cols == 0 + val c = a(i) + + if (row % 2 == 1) { + if (!isLast) c.next(Cell.NE) = a(i-(Board.cols-1)) + c.next(Cell.NW) = a(i-Board.cols) + if (row != m) { + if (!isLast) c.next(Cell.SE) = a(i+(Board.cols+1)) + c.next(Cell.SW) = a(i+Board.cols) + } + } else { + if (row != 0) { + if (!isFirst) c.next(Cell.NW) = a(i-(Board.cols+1)) + c.next(Cell.NE) = a(i-Board.cols) + } + if (row != m) { + if (!isFirst) c.next(Cell.SW) = a(i+(Board.cols-1)) + c.next(Cell.SE) = a(i+Board.cols) + } + } + if (!isFirst) c.next(Cell.W) = a(i-1) + if (!isLast) c.next(Cell.E) = a(i+1) + } + a + } + + +/* +// Printing all the board cells and their neighbours +// helps check that they are connected properly + + def printBoardCellsAndNeighbours() = { + Console.println("cell\tNW NE W E SW SE") + for (i <- Iterator.range(0,Board.size)){ + Console.print(i + "\t") + for (j <- Iterator.range(0,Cell.sides)){ + val c = cells(i).next(j) + if (c == null) + Console.print("-- ") + else + Console.printf("{0,number,00} ")(c.number) + } + Console.println("") + } + Console.println("") + } +*/ + +} + + + + +// Piece.scala + +object Piece { + val size = 5 + val rotations = Cell.sides + val flips = 2 + val orientations = rotations * flips +} + +final class Piece(_number: Int) { + val number = _number + val cells = for (i <- Array.range(0,Piece.size)) yield new PieceCell() + + { + number match { + case 0 => make0 + case 1 => make1 + case 2 => make2 + case 3 => make3 + case 4 => make4 + case 5 => make5 + case 6 => make6 + case 7 => make7 + case 8 => make8 + case 9 => make9 + } + } + + def flip() = for (c <- cells) c.flip + def rotate() = for (c <- cells) c.rotate + def unmark() = for (c <- cells) c.unmark + + + private var orientation = 0 + + def nextOrientation() = { + if (orientation == Piece.orientations) orientation = 0 + if (orientation % Piece.rotations == 0) flip else rotate + orientation = orientation + 1 + this + } + + + private def make0() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.E) = cells(3) + cells(3).next(Cell.W) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make1() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(2).next(Cell.W) = cells(3) + cells(3).next(Cell.E) = cells(2) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make2() = { + cells(0).next(Cell.W) = cells(1) + cells(1).next(Cell.E) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(2).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make3() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(1).next(Cell.W) = cells(2) + cells(2).next(Cell.E) = cells(1) + cells(1).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(1) + cells(2).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make4() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(1).next(Cell.E) = cells(3) + cells(3).next(Cell.W) = cells(1) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make5() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(0).next(Cell.SE) = cells(2) + cells(2).next(Cell.NW) = cells(0) + cells(1).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(1) + cells(2).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(2) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make6() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(2).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(2) + cells(1).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(1) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make7() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(0).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(0) + cells(2).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make8() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.NE) = cells(3) + cells(3).next(Cell.SW) = cells(2) + cells(3).next(Cell.E) = cells(4) + cells(4).next(Cell.W) = cells(3) + } + + private def make9() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.NE) = cells(3) + cells(3).next(Cell.SW) = cells(2) + cells(2).next(Cell.E) = cells(4) + cells(4).next(Cell.W) = cells(2) + cells(4).next(Cell.NW) = cells(3) + cells(3).next(Cell.SE) = cells(4) + } + +/* + def print() = { + Console.println("Piece # " + number) + Console.println("cell\tNW NE W E SW SE") + for (i <- Iterator.range(0,Piece.size)){ + Console.print(i + "\t") + for (j <- Iterator.range(0,Cell.sides)){ + val c = cells(i).next(j) + if (c == null) + Console.print("-- ") + else + for (k <- Iterator.range(0,Piece.size)){ + if (cells(k) == c) Console.printf(" {0,number,0} ")(k) + } + } + Console.println("") + } + Console.println("") + } +*/ + +} + + + + +// Cell.scala + +object Cell { + val NW = 0; val NE = 1 + val W = 2; val E = 3 + val SW = 4; val SE = 5 + + val sides = 6 +} + +abstract class Cell { + implicit def m: Manifest[T] + type T + val next = new Array[T](Cell.sides) + var marked = false + + def mark() = marked = true + def unmark() = marked = false +} + +// BoardCell.scala + +final class BoardCell(_number: Int) extends { + type T = BoardCell + implicit val m = manifest[BoardCell] +} with Cell { + val number = _number + var piece: Piece = _ + + def isEmpty() = piece == null + def empty() = piece = null + + def contiguousEmptyCells(): Int = { + if (!marked && isEmpty){ + mark + var count = 1 + + for (neighbour <- next) + if (neighbour != null && neighbour.isEmpty) + count = count + neighbour.contiguousEmptyCells + + count } else { 0 } + } +} + + + + +// PieceCell.scala + +final class PieceCell extends Cell { + type T = PieceCell + + def flip = { + var swap = next(Cell.NE) + next(Cell.NE) = next(Cell.NW) + next(Cell.NW) = swap + + swap = next(Cell.E) + next(Cell.E) = next(Cell.W) + next(Cell.W) = swap + + swap = next(Cell.SE) + next(Cell.SE) = next(Cell.SW) + next(Cell.SW) = swap + } + + def rotate = { + var swap = next(Cell.E) + next(Cell.E) = next(Cell.NE) + next(Cell.NE) = next(Cell.NW) + next(Cell.NW) = next(Cell.W) + next(Cell.W) = next(Cell.SW) + next(Cell.SW) = next(Cell.SE) + next(Cell.SE) = swap + } +} + + + + diff --git a/test/pending/shootout/meteor.scala-2.scala b/test/pending/shootout/meteor.scala-2.scala new file mode 100644 index 0000000000..2b42c19260 --- /dev/null +++ b/test/pending/shootout/meteor.scala-2.scala @@ -0,0 +1,496 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + +// This is an un-optimised example implementation +// classes BoardCell and PieceCell have Array + + +import scala.collection.mutable._ + +object meteor { + def main(args: Array[String]) = { + val solver = new Solver( Integer.parseInt(args(0)) ) + solver.findSolutions + solver.printSolutions + } +} + + + + +// Solver.scala +// import scala.collection.mutable._ + +final class Solver (n: Int) { + private var countdown = n + private var first: String = _ + private var last: String = _ + + private val board = new Board() + + val pieces = Array( + new Piece(0), new Piece(1), new Piece(2), new Piece(3), new Piece(4), + new Piece(5), new Piece(6), new Piece(7), new Piece(8), new Piece(9) ) + + val unplaced = new BitSet(pieces.length) + + { unplaced ++= (0 until pieces.length) } + + + def findSolutions(): Unit = { + if (countdown == 0) return + + if (unplaced.size > 0){ + val emptyCellIndex = board.firstEmptyCellIndex + + for (k <- Iterator.range(0,pieces.length)){ + if (unplaced.contains(k)){ + unplaced -= k + + for (i <- Iterator.range(0,Piece.orientations)){ + val piece = pieces(k).nextOrientation + + for (j <- Iterator.range(0,Piece.size)){ + if (board.add(j,emptyCellIndex,piece)) { + + if (!shouldPrune) findSolutions + + board.remove(piece) + } + } + } + unplaced += k + } + } + } + else { + puzzleSolved + } + } + + private def puzzleSolved() = { + val b = board.asString + if (first == null){ + first = b; last = b + } else { + if (b < first){ first = b } else { if (b > last){ last = b } } + } + countdown = countdown - 1 + } + + private def shouldPrune() = { + board.unmark + !board.cells.forall(c => c.contiguousEmptyCells % Piece.size == 0) + } + + + def printSolutions() = { + + def printBoard(s: String) = { + var indent = false + var i = 0 + while (i < s.length){ + if (indent) Console.print(' ') + for (j <- Iterator.range(0,Board.cols)){ + Console.print(s.charAt(i)); Console.print(' ') + i = i + 1 + } + Console.print('\n') + indent = !indent + } + Console.print('\n') + } + + Console.print(n + " solutions found\n\n") + printBoard(first) + printBoard(last) + } + +/* + def printPieces() = + for (i <- Iterator.range(0,Board.pieces)) pieces(i).print +*/ + +} + + + + +// Board.scala +// import scala.collection.mutable._ + +object Board { + val cols = 5 + val rows = 10 + val size = rows * cols +} + +final class Board { + val cells = boardCells() + + val cellsPieceWillFill = new Array[BoardCell](Piece.size) + var cellCount = 0 + + def unmark() = for (c <- cells) c.unmark + + def asString() = + new String( cells map( + c => if (c.piece == null) '-'.toByte + else (c.piece.number + 48).toByte )) + + def firstEmptyCellIndex() = cells.findIndexOf(c => c.isEmpty) + + + def add(pieceIndex: Int, boardIndex: Int, p: Piece) = { + cellCount = 0 + p.unmark + + find( p.cells(pieceIndex), cells(boardIndex)) + + val boardHasSpace = cellCount == Piece.size && + cellsPieceWillFill.forall(c => c.isEmpty) + + if (boardHasSpace) cellsPieceWillFill.foreach(c => c.piece = p) + + boardHasSpace + } + + def remove(piece: Piece) = for (c <- cells; if c.piece == piece) c.empty + + + private def find(p: PieceCell, b: BoardCell): Unit = { + if (p != null && !p.marked && b != null){ + cellsPieceWillFill(cellCount) = b + cellCount = cellCount + 1 + p.mark + for (i <- Iterator.range(0,Cell.sides)) find(p.next(i), b.next(i)) + } + } + + + private def boardCells() = { + val a = for (i <- Array.range(0,Board.size)) yield new BoardCell(i) + val m = (Board.size / Board.cols) - 1 + + for (i <- Iterator.range(0,a.length)){ + val row = i / Board.cols + val isFirst = i % Board.cols == 0 + val isLast = (i+1) % Board.cols == 0 + val c = a(i) + + if (row % 2 == 1) { + if (!isLast) c.next(Cell.NE) = a(i-(Board.cols-1)) + c.next(Cell.NW) = a(i-Board.cols) + if (row != m) { + if (!isLast) c.next(Cell.SE) = a(i+(Board.cols+1)) + c.next(Cell.SW) = a(i+Board.cols) + } + } else { + if (row != 0) { + if (!isFirst) c.next(Cell.NW) = a(i-(Board.cols+1)) + c.next(Cell.NE) = a(i-Board.cols) + } + if (row != m) { + if (!isFirst) c.next(Cell.SW) = a(i+(Board.cols-1)) + c.next(Cell.SE) = a(i+Board.cols) + } + } + if (!isFirst) c.next(Cell.W) = a(i-1) + if (!isLast) c.next(Cell.E) = a(i+1) + } + a + } + + +/* +// Printing all the board cells and their neighbours +// helps check that they are connected properly + + def printBoardCellsAndNeighbours() = { + Console.println("cell\tNW NE W E SW SE") + for (i <- Iterator.range(0,Board.size)){ + Console.print(i + "\t") + for (j <- Iterator.range(0,Cell.sides)){ + val c = cells(i).next(j) + if (c == null) + Console.print("-- ") + else + Console.printf("{0,number,00} ")(c.number) + } + Console.println("") + } + Console.println("") + } +*/ + +} + + + + +// Piece.scala + +object Piece { + val size = 5 + val rotations = Cell.sides + val flips = 2 + val orientations = rotations * flips +} + +final class Piece(_number: Int) { + val number = _number + val cells = for (i <- Array.range(0,Piece.size)) yield new PieceCell() + + { + number match { + case 0 => make0 + case 1 => make1 + case 2 => make2 + case 3 => make3 + case 4 => make4 + case 5 => make5 + case 6 => make6 + case 7 => make7 + case 8 => make8 + case 9 => make9 + } + } + + def flip() = for (c <- cells) c.flip + def rotate() = for (c <- cells) c.rotate + def unmark() = for (c <- cells) c.unmark + + + private var orientation = 0 + + def nextOrientation() = { + if (orientation == Piece.orientations) orientation = 0 + if (orientation % Piece.rotations == 0) flip else rotate + orientation = orientation + 1 + this + } + + + private def make0() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.E) = cells(3) + cells(3).next(Cell.W) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make1() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(2).next(Cell.W) = cells(3) + cells(3).next(Cell.E) = cells(2) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make2() = { + cells(0).next(Cell.W) = cells(1) + cells(1).next(Cell.E) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(2).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make3() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(1).next(Cell.W) = cells(2) + cells(2).next(Cell.E) = cells(1) + cells(1).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(1) + cells(2).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make4() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(1).next(Cell.E) = cells(3) + cells(3).next(Cell.W) = cells(1) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make5() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(0).next(Cell.SE) = cells(2) + cells(2).next(Cell.NW) = cells(0) + cells(1).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(1) + cells(2).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(2) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make6() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(2).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(2) + cells(1).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(1) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make7() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(0).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(0) + cells(2).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make8() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.NE) = cells(3) + cells(3).next(Cell.SW) = cells(2) + cells(3).next(Cell.E) = cells(4) + cells(4).next(Cell.W) = cells(3) + } + + private def make9() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.NE) = cells(3) + cells(3).next(Cell.SW) = cells(2) + cells(2).next(Cell.E) = cells(4) + cells(4).next(Cell.W) = cells(2) + cells(4).next(Cell.NW) = cells(3) + cells(3).next(Cell.SE) = cells(4) + } + +/* + def print() = { + Console.println("Piece # " + number) + Console.println("cell\tNW NE W E SW SE") + for (i <- Iterator.range(0,Piece.size)){ + Console.print(i + "\t") + for (j <- Iterator.range(0,Cell.sides)){ + val c = cells(i).next(j) + if (c == null) + Console.print("-- ") + else + for (k <- Iterator.range(0,Piece.size)){ + if (cells(k) == c) Console.printf(" {0,number,0} ")(k) + } + } + Console.println("") + } + Console.println("") + } +*/ + +} + + + + +// Cell.scala + +object Cell { + val NW = 0; val NE = 1 + val W = 2; val E = 3 + val SW = 4; val SE = 5 + + val sides = 6 +} + +abstract class Cell { + var marked = false + + def mark() = marked = true + def unmark() = marked = false +} + + + + +// BoardCell.scala + +final class BoardCell(_number: Int) extends Cell { + val next = new Array[BoardCell](Cell.sides) + val number = _number + var piece: Piece = _ + + def isEmpty() = piece == null + def empty() = piece = null + + def contiguousEmptyCells(): Int = { + if (!marked && isEmpty){ + mark + var count = 1 + + for (neighbour <- next) + if (neighbour != null && neighbour.isEmpty) + count = count + neighbour.contiguousEmptyCells + + count } else { 0 } + } +} + + + + +// PieceCell.scala + +final class PieceCell extends Cell { + val next = new Array[PieceCell](Cell.sides) + + def flip = { + var swap = next(Cell.NE) + next(Cell.NE) = next(Cell.NW) + next(Cell.NW) = swap + + swap = next(Cell.E) + next(Cell.E) = next(Cell.W) + next(Cell.W) = swap + + swap = next(Cell.SE) + next(Cell.SE) = next(Cell.SW) + next(Cell.SW) = swap + } + + def rotate = { + var swap = next(Cell.E) + next(Cell.E) = next(Cell.NE) + next(Cell.NE) = next(Cell.NW) + next(Cell.NW) = next(Cell.W) + next(Cell.W) = next(Cell.SW) + next(Cell.SW) = next(Cell.SE) + next(Cell.SE) = swap + } +} + + + + diff --git a/test/pending/shootout/meteor.scala-2.scala.runner b/test/pending/shootout/meteor.scala-2.scala.runner new file mode 100644 index 0000000000..dae384311f --- /dev/null +++ b/test/pending/shootout/meteor.scala-2.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(0)) meteor.main(Array(n.toString)) +} diff --git a/test/pending/shootout/meteor.scala-3.scala b/test/pending/shootout/meteor.scala-3.scala new file mode 100644 index 0000000000..01dacf90c6 --- /dev/null +++ b/test/pending/shootout/meteor.scala-3.scala @@ -0,0 +1,557 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + +// Most for-comprehension replaced by while loops + + + +import scala.collection.mutable._ + +object meteor { + def main(args: Array[String]) = { + val solver = new Solver( Integer.parseInt(args(0)) ) + solver.findSolutions + solver.printSolutions + } +} + + + + +// Solver.scala +// import scala.collection.mutable._ + +final class Solver (n: Int) { + private var countdown = n + private var first: String = _ + private var last: String = _ + + private val board = new Board() + + val pieces = Array( + new Piece(0), new Piece(1), new Piece(2), new Piece(3), new Piece(4), + new Piece(5), new Piece(6), new Piece(7), new Piece(8), new Piece(9) ) + + val unplaced = new BitSet(pieces.length) + + { unplaced ++= (0 until pieces.length) } + + + def findSolutions(): Unit = { + if (countdown == 0) return + + if (unplaced.size > 0){ + val emptyCellIndex = board.firstEmptyCellIndex + + var k = 0 + while (k < pieces.length){ + if (unplaced.contains(k)){ + unplaced -= k + + var i = 0 + while (i < Piece.orientations){ + val piece = pieces(k).nextOrientation + + var j = 0 + while (j < Piece.size){ + if (board.add(j,emptyCellIndex,piece)) { + + if (!shouldPrune) findSolutions + + board.remove(piece) + } + j = j + 1 + } + i = i + 1 + } + unplaced += k + } + k = k + 1 + } + } + else { + puzzleSolved + } + } + + private def puzzleSolved() = { + val b = board.asString + if (first == null){ + first = b; last = b + } else { + if (b < first){ first = b } else { if (b > last){ last = b } } + } + countdown = countdown - 1 + } + + private def shouldPrune(): Boolean = { + board.unmark + var i = 0 + while (i < board.cells.length){ + if (board.cells(i).contiguousEmptyCells % Piece.size != 0) return true + i = i + 1 + } + false + } + + + def printSolutions() = { + + def printBoard(s: String) = { + var indent = false + var i = 0 + while (i < s.length){ + if (indent) Console.print(' ') + var j = 0 + while (j < Board.cols){ + Console.print(s.charAt(i)); Console.print(' ') + j = j + 1 + i = i + 1 + } + Console.print('\n') + indent = !indent + } + Console.print('\n') + } + + Console.print(n + " solutions found\n\n") + printBoard(first) + printBoard(last) + } + +/* + def printPieces() = + for (i <- Iterator.range(0,Board.pieces)) pieces(i).print +*/ + +} + + + + + +// Board.scala +// import scala.collection.mutable._ + +object Board { + val cols = 5 + val rows = 10 + val size = rows * cols +} + +final class Board { + val cells = boardCells() + + val cellsPieceWillFill = new Array[BoardCell](Piece.size) + var cellCount = 0 + + def unmark() = { + var i = 0 + while (i < cells.length){ + cells(i).unmark + i = i + 1 + } + } + + def asString() = + new String( cells map( + c => if (c.piece == null) '-'.toByte + else (c.piece.number + 48).toByte )) + + def firstEmptyCellIndex() = cells.findIndexOf(c => c.isEmpty) + + + def add(pieceIndex: Int, boardIndex: Int, p: Piece): Boolean = { + cellCount = 0 + p.unmark + + find(p.cells(pieceIndex), cells(boardIndex)) + + if (cellCount != Piece.size) return false + + var i = 0 + while (i < cellCount){ + if (!cellsPieceWillFill(i).isEmpty) return false + i = i + 1 + } + + i = 0 + while (i < cellCount){ + cellsPieceWillFill(i).piece = p + i = i + 1 + } + + true + } + + def remove(piece: Piece) = { + var i = 0 + while (i < cells.length){ + if (cells(i).piece == piece) cells(i).empty + i = i + 1 + } + } + + private def find(p: PieceCell, b: BoardCell): Unit = { + if (p != null && !p.marked && b != null){ + cellsPieceWillFill(cellCount) = b + cellCount = cellCount + 1 + p.mark + + var i = 0 + while (i < Cell.sides){ + find(p.next(i), b.next(i)) + i = i + 1 + } + } + } + + + private def boardCells() = { + val a = for (i <- Array.range(0,Board.size)) yield new BoardCell(i) + val m = (Board.size / Board.cols) - 1 + + for (i <- Iterator.range(0,a.length)){ + val row = i / Board.cols + val isFirst = i % Board.cols == 0 + val isLast = (i+1) % Board.cols == 0 + val c = a(i) + + if (row % 2 == 1) { + if (!isLast) c.next(Cell.NE) = a(i-(Board.cols-1)) + c.next(Cell.NW) = a(i-Board.cols) + if (row != m) { + if (!isLast) c.next(Cell.SE) = a(i+(Board.cols+1)) + c.next(Cell.SW) = a(i+Board.cols) + } + } else { + if (row != 0) { + if (!isFirst) c.next(Cell.NW) = a(i-(Board.cols+1)) + c.next(Cell.NE) = a(i-Board.cols) + } + if (row != m) { + if (!isFirst) c.next(Cell.SW) = a(i+(Board.cols-1)) + c.next(Cell.SE) = a(i+Board.cols) + } + } + if (!isFirst) c.next(Cell.W) = a(i-1) + if (!isLast) c.next(Cell.E) = a(i+1) + } + a + } + +/* +// Printing all the board cells and their neighbours +// helps check that they are connected properly + + def printBoardCellsAndNeighbours() = { + Console.println("cell\tNW NE W E SW SE") + for (i <- Iterator.range(0,Board.size)){ + Console.print(i + "\t") + for (j <- Iterator.range(0,Cell.sides)){ + val c = cells(i).next(j) + if (c == null) + Console.print("-- ") + else + Console.printf("{0,number,00} ")(c.number) + } + Console.println("") + } + Console.println("") + } +*/ + +} + + + + +// Piece.scala + +object Piece { + val size = 5 + val rotations = Cell.sides + val flips = 2 + val orientations = rotations * flips +} + +final class Piece(_number: Int) { + val number = _number + val cells = for (i <- Array.range(0,Piece.size)) yield new PieceCell() + + { + number match { + case 0 => make0 + case 1 => make1 + case 2 => make2 + case 3 => make3 + case 4 => make4 + case 5 => make5 + case 6 => make6 + case 7 => make7 + case 8 => make8 + case 9 => make9 + } + } + + def flip() = { + var i = 0 + while (i < cells.length){ + cells(i).flip + i = i + 1 + } + } + + def rotate() = { + var i = 0 + while (i < cells.length){ + cells(i).rotate + i = i + 1 + } + } + + def unmark() = { + var i = 0 + while (i < cells.length){ + cells(i).unmark + i = i + 1 + } + } + + + private var orientation = 0 + + def nextOrientation() = { + if (orientation == Piece.orientations) orientation = 0 + if (orientation % Piece.rotations == 0) flip else rotate + orientation = orientation + 1 + this + } + + + private def make0() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.E) = cells(3) + cells(3).next(Cell.W) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make1() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(2).next(Cell.W) = cells(3) + cells(3).next(Cell.E) = cells(2) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make2() = { + cells(0).next(Cell.W) = cells(1) + cells(1).next(Cell.E) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(2).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make3() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(1).next(Cell.W) = cells(2) + cells(2).next(Cell.E) = cells(1) + cells(1).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(1) + cells(2).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make4() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(1).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(1) + cells(1).next(Cell.E) = cells(3) + cells(3).next(Cell.W) = cells(1) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make5() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(0).next(Cell.SE) = cells(2) + cells(2).next(Cell.NW) = cells(0) + cells(1).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(1) + cells(2).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(2) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make6() = { + cells(0).next(Cell.SW) = cells(1) + cells(1).next(Cell.NE) = cells(0) + cells(2).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(2) + cells(1).next(Cell.SE) = cells(3) + cells(3).next(Cell.NW) = cells(1) + cells(3).next(Cell.SW) = cells(4) + cells(4).next(Cell.NE) = cells(3) + } + + private def make7() = { + cells(0).next(Cell.SE) = cells(1) + cells(1).next(Cell.NW) = cells(0) + cells(0).next(Cell.SW) = cells(2) + cells(2).next(Cell.NE) = cells(0) + cells(2).next(Cell.SW) = cells(3) + cells(3).next(Cell.NE) = cells(2) + cells(3).next(Cell.SE) = cells(4) + cells(4).next(Cell.NW) = cells(3) + } + + private def make8() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.NE) = cells(3) + cells(3).next(Cell.SW) = cells(2) + cells(3).next(Cell.E) = cells(4) + cells(4).next(Cell.W) = cells(3) + } + + private def make9() = { + cells(0).next(Cell.E) = cells(1) + cells(1).next(Cell.W) = cells(0) + cells(1).next(Cell.E) = cells(2) + cells(2).next(Cell.W) = cells(1) + cells(2).next(Cell.NE) = cells(3) + cells(3).next(Cell.SW) = cells(2) + cells(2).next(Cell.E) = cells(4) + cells(4).next(Cell.W) = cells(2) + cells(4).next(Cell.NW) = cells(3) + cells(3).next(Cell.SE) = cells(4) + } + +/* + def print() = { + Console.println("Piece # " + number) + Console.println("cell\tNW NE W E SW SE") + for (i <- Iterator.range(0,Piece.size)){ + Console.print(i + "\t") + for (j <- Iterator.range(0,Cell.sides)){ + val c = cells(i).next(j) + if (c == null) + Console.print("-- ") + else + for (k <- Iterator.range(0,Piece.size)){ + if (cells(k) == c) Console.printf(" {0,number,0} ")(k) + } + } + Console.println("") + } + Console.println("") + } +*/ + +} + + + + +// Cell.scala + +object Cell { + val NW = 0; val NE = 1 + val W = 2; val E = 3 + val SW = 4; val SE = 5 + + val sides = 6 +} + +abstract class Cell { + var marked = false + + def mark() = marked = true + def unmark() = marked = false +} + + + + +// BoardCell.scala + +final class BoardCell(_number: Int) extends Cell { + val next = new Array[BoardCell](Cell.sides) + val number = _number + var piece: Piece = _ + + def isEmpty() = piece == null + def empty() = piece = null + + def contiguousEmptyCells(): Int = { + if (!marked && isEmpty){ + mark + var count = 1 + + var i = 0 + while (i < next.length){ + if (next(i) != null && next(i).isEmpty) + count = count + next(i).contiguousEmptyCells + i = i + 1 + } + + count } else { 0 } + } +} + + + + +// PieceCell.scala + +final class PieceCell extends Cell { + val next = new Array[PieceCell](Cell.sides) + + def flip = { + var swap = next(Cell.NE) + next(Cell.NE) = next(Cell.NW) + next(Cell.NW) = swap + + swap = next(Cell.E) + next(Cell.E) = next(Cell.W) + next(Cell.W) = swap + + swap = next(Cell.SE) + next(Cell.SE) = next(Cell.SW) + next(Cell.SW) = swap + } + + def rotate = { + var swap = next(Cell.E) + next(Cell.E) = next(Cell.NE) + next(Cell.NE) = next(Cell.NW) + next(Cell.NW) = next(Cell.W) + next(Cell.W) = next(Cell.SW) + next(Cell.SW) = next(Cell.SE) + next(Cell.SE) = swap + } +} + + + + diff --git a/test/pending/shootout/meteor.scala-3.scala.runner b/test/pending/shootout/meteor.scala-3.scala.runner new file mode 100644 index 0000000000..dae384311f --- /dev/null +++ b/test/pending/shootout/meteor.scala-3.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(0)) meteor.main(Array(n.toString)) +} diff --git a/test/pending/shootout/meteor.scala-4.scala b/test/pending/shootout/meteor.scala-4.scala new file mode 100644 index 0000000000..ee036f7fab --- /dev/null +++ b/test/pending/shootout/meteor.scala-4.scala @@ -0,0 +1,587 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + +// Most for-comprehension replaced by while loops +// BoardCells occupied by each Piece orientation are cached +// Piece orientations are cached + +import scala.collection.mutable._ + +object meteor { + def main(args: Array[String]) = { + val solver = new Solver( Integer.parseInt(args(0)) ) + solver.findSolutions + solver.printSolutions + } +} + + + + +// Solver.scala +// import scala.collection.mutable._ + +final class Solver (n: Int) { + private var countdown = n + private var first: String = _ + private var last: String = _ + + private val board = new Board() + + val pieces = Array( + new Piece(0), new Piece(1), new Piece(2), new Piece(3), new Piece(4), + new Piece(5), new Piece(6), new Piece(7), new Piece(8), new Piece(9) ) + + val unplaced = new BitSet(pieces.length) + + { unplaced ++= (0 until pieces.length) } + + + def findSolutions(): Unit = { + if (countdown == 0) return + + if (unplaced.size > 0){ + val emptyCellIndex = board.firstEmptyCellIndex + + var k = 0 + while (k < pieces.length){ + if (unplaced.contains(k)){ + unplaced -= k + + var i = 0 + while (i < Piece.orientations){ + val piece = pieces(k).nextOrientation + + var j = 0 + while (j < Piece.size){ + if (board.add(j,emptyCellIndex,piece)) { + + if (!shouldPrune) findSolutions + + board.remove(piece) + } + j = j + 1 + } + i = i + 1 + } + unplaced += k + } + k = k + 1 + } + } + else { + puzzleSolved + } + } + + private def puzzleSolved() = { + val b = board.asString + if (first == null){ + first = b; last = b + } else { + if (b < first){ first = b } else { if (b > last){ last = b } } + } + countdown = countdown - 1 + } + + private def shouldPrune(): Boolean = { + board.unmark + var i = 0 + while (i < board.cells.length){ + if (board.cells(i).contiguousEmptyCells % Piece.size != 0) return true + i = i + 1 + } + false + } + + + def printSolutions() = { + + def printBoard(s: String) = { + var indent = false + var i = 0 + while (i < s.length){ + if (indent) Console.print(' ') + var j = 0 + while (j < Board.cols){ + Console.print(s.charAt(i)); Console.print(' ') + j = j + 1 + i = i + 1 + } + Console.print('\n') + indent = !indent + } + Console.print('\n') + } + + Console.print(n + " solutions found\n\n") + printBoard(first) + printBoard(last) + } + +/* + def printPieces() = + for (i <- Iterator.range(0,Board.pieces)) pieces(i).print +*/ + +} + + + +// Board.scala +// import scala.collection.mutable._ + +object Board { + val cols = 5 + val rows = 10 + val size = rows * cols + val pieces = 10 + val noFit = new Array[BoardCell](0) +} + +final class Board { + val cells = boardCells() + + val cellsPieceWillFill = new Array[BoardCell](Piece.size) + var cellCount = 0 + + def unmark() = { + var i = 0 + while (i < cells.length){ + cells(i).unmark + i = i + 1 + } + } + + def asString() = + new String( cells map( + c => if (c.piece == null) '-'.toByte + else (c.piece.number + 48).toByte )) + + def firstEmptyCellIndex() = cells.findIndexOf(c => c.isEmpty) + + + private val cache: Array[Array[Array[Array[ Array[BoardCell] ]]]] = + for (i <- Array.range(0,Board.pieces)) + yield + for (j <- Array.range(0,Piece.orientations)) + yield + for (k <- Array.range(0,Piece.size)) // piece cell index + yield + for (m <- Array.range(0,Board.size)) // board cell index + yield (null: BoardCell) + + + def add(pieceIndex: Int, boardIndex: Int, p: Piece): Boolean = { + var a = cache(p.number)(p.orientation)(pieceIndex)(boardIndex) + + cellCount = 0 + p.unmark + + if (a == null){ + find(p.cells(pieceIndex), cells(boardIndex)) + + if (cellCount != Piece.size){ + cache(p.number)(p.orientation)(pieceIndex)(boardIndex) = Board.noFit + return false + } + + a = cellsPieceWillFill .filter(c => true) + cache(p.number)(p.orientation)(pieceIndex)(boardIndex) = a + } + else { + if (a == Board.noFit) return false + } + + var i = 0 + while (i < a.length){ + if (!a(i).isEmpty) return false + i = i + 1 + } + + i = 0 + while (i < a.length){ + a(i).piece = p + i = i + 1 + } + + true + } + + + def remove(piece: Piece) = { + var i = 0 + while (i < cells.length){ + if (cells(i).piece == piece) cells(i).empty + i = i + 1 + } + } + + + private def find(p: PieceCell, b: BoardCell): Unit = { + if (p != null && !p.marked && b != null){ + cellsPieceWillFill(cellCount) = b + cellCount = cellCount + 1 + p.mark + + var i = 0 + while (i < Cell.sides){ + find(p.next(i), b.next(i)) + i = i + 1 + } + } + } + + + private def boardCells() = { + val a = for (i <- Array.range(0,Board.size)) yield new BoardCell(i) + val m = (Board.size / Board.cols) - 1 + + for (i <- Iterator.range(0,a.length)){ + val row = i / Board.cols + val isFirst = i % Board.cols == 0 + val isLast = (i+1) % Board.cols == 0 + val c = a(i) + + if (row % 2 == 1) { + if (!isLast) c.next(Cell.NE) = a(i-(Board.cols-1)) + c.next(Cell.NW) = a(i-Board.cols) + if (row != m) { + if (!isLast) c.next(Cell.SE) = a(i+(Board.cols+1)) + c.next(Cell.SW) = a(i+Board.cols) + } + } else { + if (row != 0) { + if (!isFirst) c.next(Cell.NW) = a(i-(Board.cols+1)) + c.next(Cell.NE) = a(i-Board.cols) + } + if (row != m) { + if (!isFirst) c.next(Cell.SW) = a(i+(Board.cols-1)) + c.next(Cell.SE) = a(i+Board.cols) + } + } + if (!isFirst) c.next(Cell.W) = a(i-1) + if (!isLast) c.next(Cell.E) = a(i+1) + } + a + } + + +/* +// Printing all the board cells and their neighbours +// helps check that they are connected properly + + def printBoardCellsAndNeighbours() = { + Console.println("cell\tNW NE W E SW SE") + for (i <- Iterator.range(0,Board.size)){ + Console.print(i + "\t") + for (j <- Iterator.range(0,Cell.sides)){ + val c = cells(i).next(j) + if (c == null) + Console.print("-- ") + else + Console.printf("{0,number,00} ")(c.number) + } + Console.println("") + } + Console.println("") + } +*/ + +} + + + + +// Piece.scala + +object Piece { + val size = 5 + val rotations = Cell.sides + val flips = 2 + val orientations = rotations * flips +} + +final class Piece(_number: Int) { + val number = _number + + def unmark() = { + val c = cache(orientation) + var i = 0 + while (i < c.length){ + c(i).unmark + i = i + 1 + } + } + + def cells = cache(orientation) + + private val cache = + for (i <- Array.range(0,Piece.orientations)) + yield pieceOrientation(i) + + var orientation = 0 + + def nextOrientation() = { + orientation = (orientation + 1) % Piece.orientations + this + } + + + private def pieceOrientation(k: Int) = { + val cells = for (i <- Array.range(0,Piece.size)) yield new PieceCell() + makePiece(number,cells) + + var i = 0 + while (i < k){ + if (i % Piece.rotations == 0) + for (c <- cells) c.flip + else + for (c <- cells) c.rotate + + i = i + 1 + } + cells + } + + private def makePiece(number: Int, cells: Array[PieceCell]) = { + number match { + case 0 => make0(cells) + case 1 => make1(cells) + case 2 => make2(cells) + case 3 => make3(cells) + case 4 => make4(cells) + case 5 => make5(cells) + case 6 => make6(cells) + case 7 => make7(cells) + case 8 => make8(cells) + case 9 => make9(cells) + } + } + + private def make0(a: Array[PieceCell]) = { + a(0).next(Cell.E) = a(1) + a(1).next(Cell.W) = a(0) + a(1).next(Cell.E) = a(2) + a(2).next(Cell.W) = a(1) + a(2).next(Cell.E) = a(3) + a(3).next(Cell.W) = a(2) + a(3).next(Cell.SE) = a(4) + a(4).next(Cell.NW) = a(3) + } + + private def make1(a: Array[PieceCell]) = { + a(0).next(Cell.SE) = a(1) + a(1).next(Cell.NW) = a(0) + a(1).next(Cell.SW) = a(2) + a(2).next(Cell.NE) = a(1) + a(2).next(Cell.W) = a(3) + a(3).next(Cell.E) = a(2) + a(3).next(Cell.SW) = a(4) + a(4).next(Cell.NE) = a(3) + } + + private def make2(a: Array[PieceCell]) = { + a(0).next(Cell.W) = a(1) + a(1).next(Cell.E) = a(0) + a(1).next(Cell.SW) = a(2) + a(2).next(Cell.NE) = a(1) + a(2).next(Cell.SE) = a(3) + a(3).next(Cell.NW) = a(2) + a(3).next(Cell.SE) = a(4) + a(4).next(Cell.NW) = a(3) + } + + private def make3(a: Array[PieceCell]) = { + a(0).next(Cell.SW) = a(1) + a(1).next(Cell.NE) = a(0) + a(1).next(Cell.W) = a(2) + a(2).next(Cell.E) = a(1) + a(1).next(Cell.SW) = a(3) + a(3).next(Cell.NE) = a(1) + a(2).next(Cell.SE) = a(3) + a(3).next(Cell.NW) = a(2) + a(3).next(Cell.SE) = a(4) + a(4).next(Cell.NW) = a(3) + } + + private def make4(a: Array[PieceCell]) = { + a(0).next(Cell.SE) = a(1) + a(1).next(Cell.NW) = a(0) + a(1).next(Cell.SW) = a(2) + a(2).next(Cell.NE) = a(1) + a(1).next(Cell.E) = a(3) + a(3).next(Cell.W) = a(1) + a(3).next(Cell.SE) = a(4) + a(4).next(Cell.NW) = a(3) + } + + private def make5(a: Array[PieceCell]) = { + a(0).next(Cell.SW) = a(1) + a(1).next(Cell.NE) = a(0) + a(0).next(Cell.SE) = a(2) + a(2).next(Cell.NW) = a(0) + a(1).next(Cell.SE) = a(3) + a(3).next(Cell.NW) = a(1) + a(2).next(Cell.SW) = a(3) + a(3).next(Cell.NE) = a(2) + a(3).next(Cell.SW) = a(4) + a(4).next(Cell.NE) = a(3) + } + + private def make6(a: Array[PieceCell]) = { + a(0).next(Cell.SW) = a(1) + a(1).next(Cell.NE) = a(0) + a(2).next(Cell.SE) = a(1) + a(1).next(Cell.NW) = a(2) + a(1).next(Cell.SE) = a(3) + a(3).next(Cell.NW) = a(1) + a(3).next(Cell.SW) = a(4) + a(4).next(Cell.NE) = a(3) + } + + private def make7(a: Array[PieceCell]) = { + a(0).next(Cell.SE) = a(1) + a(1).next(Cell.NW) = a(0) + a(0).next(Cell.SW) = a(2) + a(2).next(Cell.NE) = a(0) + a(2).next(Cell.SW) = a(3) + a(3).next(Cell.NE) = a(2) + a(3).next(Cell.SE) = a(4) + a(4).next(Cell.NW) = a(3) + } + + private def make8(a: Array[PieceCell]) = { + a(0).next(Cell.E) = a(1) + a(1).next(Cell.W) = a(0) + a(1).next(Cell.E) = a(2) + a(2).next(Cell.W) = a(1) + a(2).next(Cell.NE) = a(3) + a(3).next(Cell.SW) = a(2) + a(3).next(Cell.E) = a(4) + a(4).next(Cell.W) = a(3) + } + + private def make9(a: Array[PieceCell]) = { + a(0).next(Cell.E) = a(1) + a(1).next(Cell.W) = a(0) + a(1).next(Cell.E) = a(2) + a(2).next(Cell.W) = a(1) + a(2).next(Cell.NE) = a(3) + a(3).next(Cell.SW) = a(2) + a(2).next(Cell.E) = a(4) + a(4).next(Cell.W) = a(2) + a(4).next(Cell.NW) = a(3) + a(3).next(Cell.SE) = a(4) + } + +/* + def print() = { + Console.println("Piece # " + number) + Console.println("cell\tNW NE W E SW SE") + for (i <- Iterator.range(0,Piece.size)){ + Console.print(i + "\t") + for (j <- Iterator.range(0,Cell.sides)){ + val c = cells(i).next(j) + if (c == null) + Console.print("-- ") + else + for (k <- Iterator.range(0,Piece.size)){ + if (cells(k) == c) Console.printf(" {0,number,0} ")(k) + } + } + Console.println("") + } + Console.println("") + } +*/ +} + + + + + +// Cell.scala + +object Cell { + val NW = 0; val NE = 1 + val W = 2; val E = 3 + val SW = 4; val SE = 5 + + val sides = 6 +} + +abstract class Cell { + var marked = false + + def mark() = marked = true + def unmark() = marked = false +} + + + + +// BoardCell.scala + +final class BoardCell(_number: Int) extends Cell { + val next = new Array[BoardCell](Cell.sides) + val number = _number + var piece: Piece = _ + + def isEmpty() = piece == null + def empty() = piece = null + + def contiguousEmptyCells(): Int = { + if (!marked && isEmpty){ + mark + var count = 1 + + var i = 0 + while (i < next.length){ + if (next(i) != null && next(i).isEmpty) + count = count + next(i).contiguousEmptyCells + i = i + 1 + } + + count } else { 0 } + } +} + + + + +// PieceCell.scala + +final class PieceCell extends Cell { + val next = new Array[PieceCell](Cell.sides) + + def flip = { + var swap = next(Cell.NE) + next(Cell.NE) = next(Cell.NW) + next(Cell.NW) = swap + + swap = next(Cell.E) + next(Cell.E) = next(Cell.W) + next(Cell.W) = swap + + swap = next(Cell.SE) + next(Cell.SE) = next(Cell.SW) + next(Cell.SW) = swap + } + + def rotate = { + var swap = next(Cell.E) + next(Cell.E) = next(Cell.NE) + next(Cell.NE) = next(Cell.NW) + next(Cell.NW) = next(Cell.W) + next(Cell.W) = next(Cell.SW) + next(Cell.SW) = next(Cell.SE) + next(Cell.SE) = swap + } +} + + + + diff --git a/test/pending/shootout/meteor.scala-4.scala.runner b/test/pending/shootout/meteor.scala-4.scala.runner new file mode 100644 index 0000000000..dae384311f --- /dev/null +++ b/test/pending/shootout/meteor.scala-4.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(0)) meteor.main(Array(n.toString)) +} diff --git a/test/pending/shootout/meteor.scala.runner b/test/pending/shootout/meteor.scala.runner new file mode 100644 index 0000000000..dae384311f --- /dev/null +++ b/test/pending/shootout/meteor.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(0)) meteor.main(Array(n.toString)) +} diff --git a/test/pending/shootout/methcall.scala b/test/pending/shootout/methcall.scala new file mode 100644 index 0000000000..9f7234c72d --- /dev/null +++ b/test/pending/shootout/methcall.scala @@ -0,0 +1,58 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy (Scala novice) +*/ + +object methcall { + def main(args: Array[String]) = { + var n = toPositiveInt(args); + var v: Boolean = false + + val toggle = new Toggle(true); + for (i <- Iterator.range(1,n)) v = toggle.activate.value; + + Console println( toggle.activate.value ); + + val ntoggle = new NToggle(true,3); + for (i <- Iterator.range(1,n)) v = ntoggle.activate.value; + + Console println( ntoggle.activate.value ); + } + + + private def toPositiveInt(s: Array[String]) = { + val i = + try { Integer.parseInt(s(0)); } + catch { case _ => 1 } + if (i>0) i; else 1; + } +} + + +private class Toggle(b: Boolean) { + var state = b; + + def value = state; + + def activate = { + state = !state; + this + } +} + + +private class NToggle(b: Boolean, trigger: Int) +extends Toggle(b) { + + val toggleTrigger = trigger; + var count = 0; + + override def activate = { + count = count + 1; + if (count >= toggleTrigger) { + state = !state; + count = 0; + } + this + } +} diff --git a/test/pending/shootout/methcall.scala.runner b/test/pending/shootout/methcall.scala.runner new file mode 100644 index 0000000000..555413cc6c --- /dev/null +++ b/test/pending/shootout/methcall.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(100000,400000,700000,1000000)) methcall.main(Array(n.toString)) +} diff --git a/test/pending/shootout/nsieve.scala-4.check b/test/pending/shootout/nsieve.scala-4.check new file mode 100644 index 0000000000..5ae0440a5a --- /dev/null +++ b/test/pending/shootout/nsieve.scala-4.check @@ -0,0 +1,9 @@ +Primes up to 1280000 98610 +Primes up to 640000 52074 +Primes up to 320000 27608 +Primes up to 2560000 187134 +Primes up to 1280000 98610 +Primes up to 640000 52074 +Primes up to 5120000 356244 +Primes up to 2560000 187134 +Primes up to 1280000 98610 diff --git a/test/pending/shootout/nsieve.scala-4.scala b/test/pending/shootout/nsieve.scala-4.scala new file mode 100644 index 0000000000..741eb80398 --- /dev/null +++ b/test/pending/shootout/nsieve.scala-4.scala @@ -0,0 +1,45 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + + +object nsieve { + + def nsieve(m: Int, isPrime: Array[Boolean]) = { + for (i <- List.range(2, m)) isPrime(i) = true + var count = 0 + + for (i <- List.range(2, m)){ + if (isPrime(i)){ + var k = i+i + while (k < m){ isPrime(k) = false; k = k+i } + count = count + 1 + } + } + count + } + + + def main(args: Array[String]) = { + val n = Integer.parseInt(args(0)) + val m = (1<<n)*10000 + val flags = new Array[Boolean](m+1) + + def printPrimes(m: Int) = { + + def pad(i: Int, width: Int) = { + val s = i.toString + List.range(0, width - s.length) + .map((i) => " ") .foldLeft("")((a,b) => a+b) + s + } + + Console.println("Primes up to " + pad(m,8) + pad(nsieve(m,flags),9)) + } + + + printPrimes(m) + printPrimes( (1<<n-1)*10000 ) + printPrimes( (1<<n-2)*10000 ) + } +} diff --git a/test/pending/shootout/nsieve.scala-4.scala.runner b/test/pending/shootout/nsieve.scala-4.scala.runner new file mode 100644 index 0000000000..67be6d5844 --- /dev/null +++ b/test/pending/shootout/nsieve.scala-4.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(7,8,9)) nsieve.main(Array(n.toString)) +} diff --git a/test/pending/shootout/pidigits.check b/test/pending/shootout/pidigits.check new file mode 100644 index 0000000000..ad4dc9962b --- /dev/null +++ b/test/pending/shootout/pidigits.check @@ -0,0 +1,100 @@ +3141592653 :10 +5897932384 :20 +6264338327 :30 +9502884197 :40 +1693993751 :50 +0582097494 :60 +4592307816 :70 +4062862089 :80 +9862803482 :90 +5342117067 :100 +9821480865 :110 +1328230664 :120 +7093844609 :130 +5505822317 :140 +2535940812 :150 +8481117450 :160 +2841027019 :170 +3852110555 :180 +9644622948 :190 +9549303819 :200 +6442881097 :210 +5665933446 :220 +1284756482 :230 +3378678316 :240 +5271201909 :250 +1456485669 :260 +2346034861 :270 +0454326648 :280 +2133936072 :290 +6024914127 :300 +3724587006 :310 +6063155881 :320 +7488152092 :330 +0962829254 :340 +0917153643 :350 +6789259036 :360 +0011330530 :370 +5488204665 :380 +2138414695 :390 +1941511609 :400 +4330572703 :410 +6575959195 :420 +3092186117 :430 +3819326117 :440 +9310511854 :450 +8074462379 :460 +9627495673 :470 +5188575272 :480 +4891227938 :490 +1830119491 :500 +2983367336 :510 +2440656643 :520 +0860213949 :530 +4639522473 :540 +7190702179 :550 +8609437027 :560 +7053921717 :570 +6293176752 :580 +3846748184 :590 +6766940513 :600 +2000568127 :610 +1452635608 :620 +2778577134 :630 +2757789609 :640 +1736371787 :650 +2146844090 :660 +1224953430 :670 +1465495853 :680 +7105079227 :690 +9689258923 :700 +5420199561 :710 +1212902196 :720 +0864034418 :730 +1598136297 :740 +7477130996 :750 +0518707211 :760 +3499999983 :770 +7297804995 :780 +1059731732 :790 +8160963185 :800 +9502445945 :810 +5346908302 :820 +6425223082 :830 +5334468503 :840 +5261931188 :850 +1710100031 :860 +3783875288 :870 +6587533208 :880 +3814206171 :890 +7766914730 :900 +3598253490 :910 +4287554687 :920 +3115956286 :930 +3882353787 :940 +5937519577 :950 +8185778053 :960 +2171226806 :970 +6130019278 :980 +7661119590 :990 +9216420198 :1000 diff --git a/test/pending/shootout/pidigits.scala b/test/pending/shootout/pidigits.scala new file mode 100644 index 0000000000..b0becafda8 --- /dev/null +++ b/test/pending/shootout/pidigits.scala @@ -0,0 +1,69 @@ +/* ------------------------------------------------------------------ */ +/* The Computer Language Shootout */ +/* http://shootout.alioth.debian.org/ */ +/* */ +/* Contributed by Anthony Borla */ +/* ------------------------------------------------------------------ */ + +object pidigits +{ + def main(args: Array[String]): Unit = + { + val N: Int = Integer.parseInt(args(0)); var i: Int = 10 + + while (i <= N) + { + System.out.println(pi_digits(10) + "\t:" + i) + i = i + 10 + } + + i = i - 10 + + if (i < N) + { + System.out.println(pi_digits(N - i) + "\t:" + N) + } + } + + def compose(a: Array[BigInt], b: Array[BigInt]): Array[BigInt] = + { + return Array(a(0) * b(0), + a(0) * b(1) + a(1) * b(3), + a(2) * b(0) + a(3) * b(2), + a(2) * b(1) + a(3) * b(3)) + } + + def extract(a: Array[BigInt], j: Int): BigInt = + { + return (a(0) * j + a(1)) / (a(2) * j + a(3)) + } + + def pi_digits(c: Int): String = + { + val r: StringBuffer = new StringBuffer(); var i: Int = 0 + + while (i < c) + { + var y: BigInt = extract(Z, 3) + + while (y != extract(Z, 4)) + { + K = K + 1; Z = compose(Z, Array(K, 4 * K + 2, 0, 2 * K + 1)) + y = extract(Z, 3) + } + +// Z = compose(Array(10, (-y) * 10, 0, 1), Z) + + Z = compose(Array(10, y * (-10), 0, 1), Z) + + r.append(y); i = i + 1; + } + + return r.toString() + } + + var K: Int = 0 + + var Z: Array[BigInt] = Array(1, 0, 0, 1) +} + diff --git a/test/pending/shootout/pidigits.scala.runner b/test/pending/shootout/pidigits.scala.runner new file mode 100644 index 0000000000..4bf5a8bde9 --- /dev/null +++ b/test/pending/shootout/pidigits.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(600,800,1000)) pidigits.main(Array(n.toString)) +} diff --git a/test/pending/shootout/prodcons.scala b/test/pending/shootout/prodcons.scala new file mode 100644 index 0000000000..d48d3e94d8 --- /dev/null +++ b/test/pending/shootout/prodcons.scala @@ -0,0 +1,64 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy (Scala novice) +*/ + +import concurrent.SyncVar; +import concurrent.ops._; + +object prodcons { + def main(args: Array[String]) = { + val n = toPositiveInt(args); + val buffer = new SharedBuffer(); + var p = 0; + var c = 0; + val cDone = new SyncVar[Boolean]; + + spawn { + while(p<n) { p=p+1; buffer put(p); } + } + + spawn { + var v: Int = _; + while(c<n) { c=c+1; v = buffer.get; } + cDone set true; + } + + cDone.get; + Console println(p + " " + c); + } + + + private def toPositiveInt(s: Array[String]) = { + val i = + try { Integer.parseInt(s(0)); } + catch { case _ => 1 } + if (i>0) i; else 1; + } +} + + +private class SharedBuffer() { + var contents: Int = _; + var available = false; + + def get = synchronized { + while (available == false) wait(); + available = false; + // Console println("\t" + "get " + contents); + notifyAll(); + contents + } + + def put(value: Int) = synchronized { + while (available == true) wait(); + contents = value; + available = true; + // Console println("put " + value); + notifyAll(); + } +} + + + + diff --git a/test/pending/shootout/prodcons.scala.runner b/test/pending/shootout/prodcons.scala.runner new file mode 100644 index 0000000000..75faf8ca6e --- /dev/null +++ b/test/pending/shootout/prodcons.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(30000,70000,100000,150000)) prodcons.main(Array(n.toString)) +} diff --git a/test/pending/shootout/random.scala b/test/pending/shootout/random.scala new file mode 100644 index 0000000000..0a86a35637 --- /dev/null +++ b/test/pending/shootout/random.scala @@ -0,0 +1,32 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy (Scala novice) +*/ + +object random { + def main(args: Array[String]) = { + var n = toPositiveInt(args); + var result: Double = 0 + + while (n>0) { result=generate(100.0); n=n-1; } + + Console.printf("{0,number,#.000000000}\n", result) + } + + private val IM = 139968; + private val IA = 3877; + private val IC = 29573; + private var seed = 42; + + def generate(max: Double) = { + seed = (seed * IA + IC) % IM; + max * seed / IM; + } + + private def toPositiveInt(s: Array[String]) = { + val i = + try { Integer.parseInt(s(0)); } + catch { case _ => 1 } + if (i>0) i; else 1; + } +} diff --git a/test/pending/shootout/random.scala.runner b/test/pending/shootout/random.scala.runner new file mode 100644 index 0000000000..11cbeef0f6 --- /dev/null +++ b/test/pending/shootout/random.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(9000,300000,600000,900000)) random.main(Array(n.toString)) +} diff --git a/test/pending/shootout/revcomp.scala-2.check b/test/pending/shootout/revcomp.scala-2.check new file mode 100644 index 0000000000..14d792ade8 --- /dev/null +++ b/test/pending/shootout/revcomp.scala-2.check @@ -0,0 +1,171 @@ +>ONE Homo sapiens alu +CGGAGTCTCGCTCTGTCGCCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAAC +CTCCGCCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACA +GGCGCGCGCCACCACGCCCGGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCAT +GTTGGCCAGGCTGGTCTCGAACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAA +AGTGCTGGGATTACAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTC +TGTCGCCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCGCCTCCCGG +GTTCAAGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGCGCGCCACC +ACGCCCGGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGGCCAGGCTG +GTCTCGAACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTA +CAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTCTGTCGCCCAGGCT +GGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCGCCTCCCGGGTTCAAGCGATTC +TCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGCGCGCCACCACGCCCGGCTAAT +TTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGGCCAGGCTGGTCTCGAACTCCT +GACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTACAGGCGTGAGCCA +CCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTCTGTCGCCCAGGCTGGAGTGCAGTGGC +GCGATCTCGGCTCACTGCAACCTCCGCCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCC +TCCCGAGTAGCTGGGATTACAGGCGCGCGCCACCACGCCCGGCTAATTTTTGTATTTTTA +GTAGAGACGGGGTTTCACCATGTTGGCCAGGCTGGTCTCGAACTCCTGACCTCAGGTGAT +CCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTACAGGCGTGAGCCACCGCGCCCGGCCT +TTTTGAGACGGAGTCTCGCTCTGTCGCCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTC +ACTGCAACCTCCGCCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTG +GGATTACAGGCGCGCGCCACCACGCCCGGCTAATTTTTGTATTTTTAGTAGAGACGGGGT +TTCACCATGTTGGCCAGGCTGGTCTCGAACTCCTGACCTCAGGTGATCCGCCCGCCTCGG +CCTCCCAAAGTGCTGGGATTACAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAG +TCTCGCTCTGTCGCCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCG +CCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGC +GCGCCACCACGCCCGGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGG +CCAGGCTGGTCTCGAACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGC +TGGGATTACAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTCTGTCG +CCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCGCCTCCCGGGTTCA +AGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGCGCGCCACCACGCC +CGGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGGCCAGGCTGGTCTC +GAACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTACAGGC +GTGAGCCACCGCGCCCGGCC +>TWO IUB ambiguity codes +TAGGDHACHATCRGTRGVTGAGWTATGYTGCTGTCABACDWVTRTAAGAVVAGATTTNDA +GASMTCTGCATBYTTCAAKTTACMTATTACTTCATARGGYACMRTGTTTTYTATACVAAT +TTCTAKGDACKADACTATATNTANTCGTTCACGBCGYSCBHTANGGTGATCGTAAAGTAA +CTATBAAAAGATSTGWATBCSGAKHTTABBAACGTSYCATGCAAVATKTSKTASCGGAAT +WVATTTNTCCTTCTTCTTDDAGTGGTTGGATACVGTTAYMTMTBTACTTTHAGCTAGBAA +AAGAGKAAGTTRATWATCAGATTMDDTTTAAAVAAATATTKTCYTAAATTVCNKTTRACG +ADTATATTTATGATSADSCAATAWAGCGRTAGTGTAAGTGACVGRADYGTGCTACHVSDT +CTVCARCSYTTAATATARAAAATTTAATTTACDAATTGBACAGTAYAABATBTGCAGBVG +TGATGGDCAAAATBNMSTTABKATTGGSTCCTAGBTTACTTGTTTAGTTTATHCGATSTA +AAGTCGAKAAASTGTTTTAWAKCAGATATACTTTTMTTTTGBATAGAGGAGCMATGATRA +AAGGNCAYDCCDDGAAAGTHGBTAATCKYTBTACBGTBCTTTTTGDTAASSWTAAWAARA +TTGGCTAAGWGRADTYACATAGCTCBTAGATAWAGCAATNGTATMATGTTKMMAGTAWTC +CCNTSGAAWATWCAAAAMACTGAADNTYGATNAATCCGAYWNCTAACGTTAGAGDTTTTC +ATCTGGKRTAVGAABVCTGWGBTCTDVGKATTBTCTAAGGVADAAAVWTCTAGGGGAGGG +TTAGAACAATTAAHTAATNAAATGCATKATCTAAYRTDTCAGSAYTTYHGATRTTWAVTA +BGNTCDACAGBCCRCAGWCRTCABTGMMAWGMCTCAACCGATRTGBCAVAATCGTDWDAA +CAYAWAATWCTGGTAHCCCTAAGATAACSCTTAGTGSAACAWTBGTCDTTDGACWDBAAC +HTTTNGSKTYYAAYGGATNTGATTTAARTTAMBAATCTAAGTBTCATYTAACTTADTGTT +TCGATACGAAHGGCYATATACCWDTKYATDCSHTDTCAAAATGTGBACTGSCCVGATGTA +TCMMAGCCTTDAAABAATGAAGAGTAACTHATMGVTTAATAACCCGGTTVSANTGCAATT +GTGAGATTTAMGTTTAMAAYGCTGACAYAAAAAGGCACAMYTAAGVGGCTGGAABVTACG +GATTSTYGTBVAKTATWACCGTGTKAGTDTGTATGTTTAAAGGAAAAAGTAACATARAAA +GGTYCAMNYAAABTATAGNTSATANAGTCATCCTATWADKAACTRGTMSACDGTATSAYT +AAHSHGTAABYGACTYTATADTGSTATAGAGAAATCGNTAAAGGAAATCAGTTGTNCYMV +TNACDRTATBNATATASTAGAAMSCGGGANRCKKMCAAACATTNAGTCTRMAATBMTACC +CGTACTTCTBGDSYAATWGAAAATGACADDCHAKAAAYATATTKTTTTCACANACWAGAA +AKATCCTTATTAYKHKCTAAACARTATTTTDATBTVWCYGCAATACTAGGKAAASTTDGA +MGGCHTTHAATVCAHDRYAGGRCTATACGTCMAGAGAGCTBTHGNACARTCCBDCTAAGA +GCGGCTTTARTAAAGAATCCNAGTAWBTGACTTGAATTACWTVACAGAAABCAATNAAAC +CGTNTRANTTGAYCMAWBADTANABRGGTKTHTWTAGTTVCTMBKTAGMTVKCCAGCANT +TVAGSWTTAGCCGCRHTTTCCTTHNTATTAAGAAGAATAGGMTRAARTCTABGTACDTTT +TATAAVDHAHTATAGATCCTAGTAAGYTWATDWCATGAGGGATAGTAAMDMNGBASTWAM +TSTATRBAYDABATGTATATYCGCACTGTTTTAACMCWBTATAWAGTATBTSTATVTTAR +CCTMTTAAKADATCAACTAATYTSVTAKGDATTATGCKTCAYCAKAATACTTKAANGAGT +ATTSDAGATCGGAAATACTTAAYAAVGTATMCGCTTGTGTDCTAATYTATTTTATTTWAA +CAGWRCTATGTAGMTGTTTGTTYKTNGTTKTCAGAACNTRACCTACKTGSRATGTGGGGG +CTGTCATTAAGTAAATNGSTTABCCCCTCGCAGCTCWHTCGCGAAGCAVATGCKACGHCA +ACAKTTAATAACASAAADATTWNYTGTAATTGTTCGTMHACHTWATGTGCWTTTTGAAHY +ACTTTGTAYAMSAAACTTAADAAATATAGTABMATATYAATGSGGTAGTTTGTGTBYGGT +TWSGSVGWMATTDMTCCWWCABTCSVACAGBAATGTTKATBGTCAATAATCTTCTTAAAC +ARVAATHAGYBWCTRWCABGTWWAATCTAAGTCASTAAAKTAAGVKBAATTBGABACGTA +AGGTTAAATAAAAACTRMDTWBCTTTTTAATAAAAGATMGCCTACKAKNTBAGYRASTGT +ASSTCGTHCGAAKTTATTATATTYTTTGTAGAACATGTCAAAACTWTWTHGKTCCYAATA +AAGTGGAYTMCYTAARCSTAAATWAKTGAATTTRAGTCTSSATACGACWAKAASATDAAA +TGYYACTSAACAAHAKTSHYARGASTATTATTHAGGYGGASTTTBGAKGATSANAACACD +TRGSTTRAAAAAAAACAAGARTCVTAGTAAGATAWATGVHAAKATWGAAAAGTYAHVTAC +TCTGRTGTCAWGATRVAAKTCGCAAVCGASWGGTTRTCSAMCCTAACASGWKKAWDAATG +ACRCBACTATGTGTCTTCAAAHGSCTATATTTCGTVWAGAAGTAYCKGARAKSGKAGTAN +TTTCYACATWATGTCTAAAADMDTWCAATSTKDACAMAADADBSAAATAGGCTHAHAGTA +CGACVGAATTATAAAGAHCCVAYHGHTTTACATSTTTATGNCCMTAGCATATGATAVAAG +>THREE Homo sapiens frequency +ATATTTATCTTTTCACTTCCTACATTGGTCAGACCATTATTCGACACGTGGCGTCATTTT +GTCATACCGGGTAATGTTGGAAACAAAACGTACTGATAAAATACTGAGTTGTAAACTCTA +ATCAGATAACGCGCTTGGATATTAAGATTCACACAGGGGTTTCGGCTGTAAAAAAACTTG +TGGAGCTGTTCTGGGACAGATAAGTTGTACCTCGTACTTAGCTAATTAATGAACCAACTG +ATTACGATAGAACAATTCTGAGGCCGCCAGGACAGCCAAATTTTAATCTTATAAAGCTGG +AAACAGCCGGTATTAGCTTCTCGCATACTTTGCCTGCATTGGTACCTTACAGATATCAGC +GTAGTCATATACACCTCGGTCTCAGCTAAGCTTGTATCTCTTAGAGTAGTTCAAAGATAG +TGGACAATACCTGTGGAATCGATTGCAGATATGGATTTATTTAACTACTGAGTCTCATTC +ACAAGCTAAGCAAGGAGCACGTTTTGGTGCCGGCATACCGATTTGCTATCATGTCAGCAA +ATTTGCGTTGTATTCCTAGTTGCACCCATTAAGGCCACACTCCGAACCTAATTATTACAT +CGCAAAGACATGTACGAAGGACCCGATGTCGAATAGAAGGGAGGACTGTTCATTGGAAGC +TAGACCAGAGGAATCGCAAAGATGCAACTCTTACAATAAAAATCTAATTTCAGTCAACAC +GCAATTTCTATAAGGTTTCCGATAATAATGAACCGTCTTCCACAGGGGAATTTGCCATGC +TCGTAAAAGTAGTTAATCCAAGTAGAAGAAATTTTGATAATGTTTTAAGTTGGCACGAAG +GAATTCAGAGAGATCTTACCTAACAAAGGCATTAGTAGATGTTCCTTGGTTCACACTCGG +TCAATCAGAGCACATACTACGGGCGATACCGGGAATGACACAACATCAATGAGATTGTTA +AGTGAGGTAATTGACTTTAGAGGACTCGATCAGTATACTGTCACTATGAACATCGTATTA +ATTGTTATCCGATATATACACCACCGATTTGCTTGTGCAAGGTTACAGACCCATTCGATA +AATACAAACACGGAGCGATATTATTTAAGGAGTGCTGTCTTCAAAAGAATTATTCCCACA +CCGACATAAGAACTTCGCTCCGTCATTCCAGATTTAAATAACATAACGTAACGCTTTGCT +GATAACATAACATAACCGAGAATTTGCTTAGGAAATTTGGAGCAATATTGCATTGTTTCT +CAGTCATCACAAGGCCCGCCAAAGAACTCTGAGAATCAGGATTCAACATGATTGGTAAGA +CTCTATATATATAACTTAATTCTTGTGTCCGGAGATAGAAAGAGGACGAGAGATACTACG +AAAGAAAGTGTACTTCGATGTATCAATTCAGACGCCTTCTCTATCATCAACATTATAGGT +CTCGTATATGCTCGGCGCGATCTGCTTCTCTCCGCCAATAGCCCCATAGTGTATTTCAAG +CGCAGTAACAGTGAAATCGTTACGAAGGTAGGGATGTTGCTTATAATTGTCGTAACTTAT +CGCTTATGTATCTTTCAAGAATGAACGGCAGCATATACATACGTTCTACCTTTAGCTACA +AAGCATCCATATACTCCCTCTCATGATTGAAACTCTTCCCTATTTTGTAGCCAATAGTGA +AAGCGTATTAGTATAAATTCGTCGGTTTTTCACTCGCAACTGTTATACTCTGCAAACAAA +CGAAAGCCTCATAGTACAAACCTAAAGCTACATACTTCATCATTGGCAGACCAGTGGCGG +TATTTCTACGGAAGCATCACTATAGATATAAAGTTTCCCTTCATGTACGTCTGTTAACCA +TATCACAAGAAACTGCTATCTCTGTCACGTAACAATTCACGCGCCTTATCGCCAAATGTT +CATATATGCGCGGTATACGTATGAACGAATACTAATTAGTATAACGGAGGATTCACGGGA +GGGATACTTGGGGCATTTATAAATCGTCTAAAAATTTTCTATCAGCACTTGCGGGTTATA +GTGGATTACTAGGCAACATAATATTCTGTATTGGTCCAAATGACGCTATAGATAAATTAG +CAAAATACATTGTTTCCATTTATGTAAGTCGAAACTCCAGGACTCCCGGGAACCAGTTAA +ACCGTCTGGAAAAGACACATTGTGAGCGGGACTTCAATGATAGCTTTCAATGAGCTTCTC +ATGCTTGGGGTCTGTACATATATGTTGGCGAAATTATCGTCTGTATTCTGTTATGCTTTG +ATCATGGGTTATTAGTATAGTGTCCGGTTAAGTACCAATACCGCTAGAGACCCGACCTAA +GTCGATAACTAACGATCATCGACGTAAGGATCGTCTCGATCAGTACTTCAGTCTAGATCT +GGGAATAGTAACTCGTTAGTGAACTATGTCGTGTCATAACTCTAAAATGCAATCAAATCT +TATTATTGAGTATTGATTATATAAAGCATCCGCTTAGCTTTACCCTCAAATGTTATATGC +AATTTAAAGCGCTTGATATCGTCTACTCAAGTTCAGGTTTCACATGGCCGCAACGTGACG +TTATTAGAGGTGGGTCATCATCTCTGAGGCTAGTGATGTTGAATACTCATTGAATGGGAA +GTGGAATACCATGCTCGTAGGTAACAGCATGACCTATAAAATATACTATGGGTGTGTGGT +AGATCAATATTGTTCAAGCATATCGTAACAATAACGGCTGAAATGTTACTGACATGAAAG +AGGGAGTCCAAACCATTCTAACAGCTGATCAAGTCGTCTAAAAACGCCTGGTTCAGCCTT +AAGAGTTATAAGCCAGACAAATTGTATCAATAGAGAATCCGTAAATTCCTCGGCCAACCT +CTTGCAAAGACATCACTATCAATATACTACCGTGATCTTAATTAGTGAACTTATATAAAT +ATCTACAACCAGATTCAACGGAAAAGCTTTAGTGGATTAGAAATTGCCAAGAATCACATT +CATGTGGGTTCGAATGCTTTAGTAATACCATTTCGCCGAGTAGTCACTTCGCTGAACTGT +CGTAAATTGCTATGACATAATCGAAAAGGATTGTCAAGAGTCGATTACTGCGGACTAATA +ATCCCCACGGGGGTGGTCTCATGTCTCCCCAGGCGAGTGGGGACGGTTGATAAACACGCT +GCATCGCGGACTGATGTTCCCAGTATTACATAGTCACATTGGATTGCGAGTAGTCTACCT +ATTTATGAGCGAGAGATGCCTCTAACTACTTCGACTTTTAAAACCTTTCCACGCCAGTAT +TCGGCGAAAGGGAAGTATTAAGGGTTGTCATAATTAAGCTGATACCACTTCAGACTTTGC +TCTACTTCTGTCTTTCATTGGTTTAGTAAAGTCTGTCCATTCGTCGAGACCGTCTTTTGC +AGCCTCATTCTACCAACTGCTCCGACTCTTAGTCTGCTTCTCCCAGCGTTATAACAAGAG +GCATTTTGTCATCCTTAAAACAATAATAAAGAACTCGGAGCACTGATATAATGACTGAAT +TAGAACCGCTTAAAAATACAACGAATAGATAAGACTATCGGATAAGATCTAATATGTAGT +GATTAAGCCCTTTATTAATTAATAATAGTTACCCTTTCTGATGTAACGCGACATATTACG +ATTTAGTGGCACGTCTGAATTGCAAAGCAGATCTCTACCCGATTTTTATTATAAATCCCG +TATACATCTTGACTTGAGTAATTGTTCATCTTTTTATATCTCTTCGTACTACAAATAATT +AATATCTCAACCCGTATTGTGTGATTCTAATTACCAACAGAATACGAGGAGGTTTTTGCT +TAGGGCCATATATAATGAATCTATCTCGTTTATTCGCGGAACCCGAGATAACATTACGAT +GTAACTATTTTAGAGAACTTAATACAAGAAACATTGCTGATTACTCATAACTAAATGCTT +GGTAATATATCCTCAGTGCCCCTACCATCTTTTACGCAGGGATGTAATTACTTAGGATTC +ATTGTGTAAGAATTACAATGAACGATGGATATGAAGGCATGTTGCGAGGTGTTCCTTGGT +ATGTGAAGTTCGCAGGGCAACAAAAATTTCGCAGAATAGGCCTCAAAGTATTGGTAAAGA +AGACAACTAATCATCACGAGCTTCTGATATCAATACGAACGAGTCCTGTGATGGATGAAA +GAAAGTCGTATCGAAAATGTCAAGAGTCTGCCCAATGTAACTTACTTCAAAAAATAACGC +TTCCGCCAAGTACGTTCGAATAAACGTAATTTTAAAAATACATAAGGGGTGTTAGAAAGT +AAGCGACGGGATATAAGTTAGACTCAAGATTCCGCCGTAAAACGAGACTGATTCCGAAGA +TTGTTCGTGGATCTGGTCATGACTTTCACTGAGTAAGGAGTTTCGACATATGTCAATAAA +CACAAAAATAGAAGCTATTCGATCTGAAAAATATTAGGACAAGAAACTATCTCACGCTAG +CCCAGAATATTCACTCACCCACGGGCGATACTAAAGCACTATATAGTCGCGTGATTACTA +TACATATGGTACACATAAGAATCACGATCAGGTTCTCAATTTTCAACAATATATGTTTAT +TTGCATAGGTAATATTAGGCCTTTAAGAGAAGGATGGGTGAGATACTCCGGGGATGGCGG +CAATAAAGAAAAACACGATATGAGTAATAGGATCCTAATATCTTGGCGAGAGACTTAAGG +TACGAATTTTGCGCAATCTATTTTTTACTTGGCCAGAATTCATGTATGGTATAAGTACGA +ACTTTTTTGATCACTTTCATGGCTACCTGATTAGGATAGTTTGAGGAATTTCCCAAATAT +ACCGATTTAATATACACTAGGGCTTGTCACTTTGAGTCAGAAAAAGAATATAATTACTTA +GGGTAATGCTGCATACATATTCTTATATTGCAAAGGTTCTCTGGGTAATCTTGAGCCTTC +ACGATACCTGGTGAAGTGTT diff --git a/test/pending/shootout/revcomp.scala-2.scala b/test/pending/shootout/revcomp.scala-2.scala new file mode 100644 index 0000000000..92260ad021 --- /dev/null +++ b/test/pending/shootout/revcomp.scala-2.scala @@ -0,0 +1,92 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + +import java.io._ +import scala.collection.mutable.Stack + +object revcomp { + + val IUB = IUBCodeComplements + + def IUBCodeComplements() = { + val code = "ABCDGHKMNRSTVWYabcdghkmnrstvwy".getBytes + val comp = "TVGHCDMKNYSABWRTVGHCDMKNYSABWR".getBytes + val a: Array[Byte] = new Array( 'z'.toByte ) + + for (indexValue <- code zip comp) + indexValue match { case Pair(i,v) => a(i) = v } + + a + } + + + type LineStack = Stack[Array[Byte]] + + def main(args: Array[String]) = { + val r = new BufferedReader(new InputStreamReader(System.in)) + val w = new BufferedOutputStream(System.out) + + var lines: LineStack = new Stack + var desc = "" + + var line = r.readLine + while (line != null) { + val c = line.charAt(0) + if (c == '>'){ + if (desc.length > 0){ + complementReverseWrite(desc, lines, w) + lines = new Stack + } + desc = line + } else { + if (c != ';') lines += line.getBytes + } + line = r.readLine + } + r.close + + if (desc.length > 0) complementReverseWrite(desc, lines, w) + w.close + } + + + def complementReverseWrite(desc: String, lines: LineStack, + w: BufferedOutputStream) = { + + def inplaceComplementReverse(b: Array[Byte]) = { + var i = 0 + var j = b.length - 1 + while (i < j){ + val swap = b(i) + b(i) = IUB( b(j) ) + b(j) = IUB( swap ) + i = i + 1 + j = j - 1 + } + if (i == j) b(i) = IUB( b(i) ) + } + + val nl = '\n'.toByte + w.write(desc.getBytes); w.write(nl) + + val n = 60 + val k = if (lines.isEmpty) 0 else lines.top.length + val isSplitLine = k < n + var isFirstLine = true + + while (!lines.isEmpty) { + val line = lines.pop + inplaceComplementReverse(line) + + if (isSplitLine){ + if (isFirstLine){ w.write(line); isFirstLine = false } + else { w.write(line,0,n-k); w.write(nl); w.write(line,n-k,k) } + } + else { w.write(line); w.write(nl) } + } + if (isSplitLine && !isFirstLine) w.write(nl) + } + +} diff --git a/test/pending/shootout/revcomp.scala-2.scala.runner b/test/pending/shootout/revcomp.scala-2.scala.runner new file mode 100644 index 0000000000..f51d6170c8 --- /dev/null +++ b/test/pending/shootout/revcomp.scala-2.scala.runner @@ -0,0 +1,6 @@ +object Test extends Application { + for(n <- List(25000,250000,2500000)) { + System.setIn(new java.io.FileInputStream(System.getProperty("partest.cwd")+"/revcomp-input"+n+".txt")) + revcomp.main(Array(n.toString)) + } +} diff --git a/test/pending/shootout/revcomp.scala-3.check b/test/pending/shootout/revcomp.scala-3.check new file mode 100644 index 0000000000..14d792ade8 --- /dev/null +++ b/test/pending/shootout/revcomp.scala-3.check @@ -0,0 +1,171 @@ +>ONE Homo sapiens alu +CGGAGTCTCGCTCTGTCGCCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAAC +CTCCGCCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACA +GGCGCGCGCCACCACGCCCGGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCAT +GTTGGCCAGGCTGGTCTCGAACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAA +AGTGCTGGGATTACAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTC +TGTCGCCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCGCCTCCCGG +GTTCAAGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGCGCGCCACC +ACGCCCGGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGGCCAGGCTG +GTCTCGAACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTA +CAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTCTGTCGCCCAGGCT +GGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCGCCTCCCGGGTTCAAGCGATTC +TCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGCGCGCCACCACGCCCGGCTAAT +TTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGGCCAGGCTGGTCTCGAACTCCT +GACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTACAGGCGTGAGCCA +CCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTCTGTCGCCCAGGCTGGAGTGCAGTGGC +GCGATCTCGGCTCACTGCAACCTCCGCCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCC +TCCCGAGTAGCTGGGATTACAGGCGCGCGCCACCACGCCCGGCTAATTTTTGTATTTTTA +GTAGAGACGGGGTTTCACCATGTTGGCCAGGCTGGTCTCGAACTCCTGACCTCAGGTGAT +CCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTACAGGCGTGAGCCACCGCGCCCGGCCT +TTTTGAGACGGAGTCTCGCTCTGTCGCCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTC +ACTGCAACCTCCGCCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTG +GGATTACAGGCGCGCGCCACCACGCCCGGCTAATTTTTGTATTTTTAGTAGAGACGGGGT +TTCACCATGTTGGCCAGGCTGGTCTCGAACTCCTGACCTCAGGTGATCCGCCCGCCTCGG +CCTCCCAAAGTGCTGGGATTACAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAG +TCTCGCTCTGTCGCCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCG +CCTCCCGGGTTCAAGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGC +GCGCCACCACGCCCGGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGG +CCAGGCTGGTCTCGAACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGC +TGGGATTACAGGCGTGAGCCACCGCGCCCGGCCTTTTTGAGACGGAGTCTCGCTCTGTCG +CCCAGGCTGGAGTGCAGTGGCGCGATCTCGGCTCACTGCAACCTCCGCCTCCCGGGTTCA +AGCGATTCTCCTGCCTCAGCCTCCCGAGTAGCTGGGATTACAGGCGCGCGCCACCACGCC +CGGCTAATTTTTGTATTTTTAGTAGAGACGGGGTTTCACCATGTTGGCCAGGCTGGTCTC +GAACTCCTGACCTCAGGTGATCCGCCCGCCTCGGCCTCCCAAAGTGCTGGGATTACAGGC +GTGAGCCACCGCGCCCGGCC +>TWO IUB ambiguity codes +TAGGDHACHATCRGTRGVTGAGWTATGYTGCTGTCABACDWVTRTAAGAVVAGATTTNDA +GASMTCTGCATBYTTCAAKTTACMTATTACTTCATARGGYACMRTGTTTTYTATACVAAT +TTCTAKGDACKADACTATATNTANTCGTTCACGBCGYSCBHTANGGTGATCGTAAAGTAA +CTATBAAAAGATSTGWATBCSGAKHTTABBAACGTSYCATGCAAVATKTSKTASCGGAAT +WVATTTNTCCTTCTTCTTDDAGTGGTTGGATACVGTTAYMTMTBTACTTTHAGCTAGBAA +AAGAGKAAGTTRATWATCAGATTMDDTTTAAAVAAATATTKTCYTAAATTVCNKTTRACG +ADTATATTTATGATSADSCAATAWAGCGRTAGTGTAAGTGACVGRADYGTGCTACHVSDT +CTVCARCSYTTAATATARAAAATTTAATTTACDAATTGBACAGTAYAABATBTGCAGBVG +TGATGGDCAAAATBNMSTTABKATTGGSTCCTAGBTTACTTGTTTAGTTTATHCGATSTA +AAGTCGAKAAASTGTTTTAWAKCAGATATACTTTTMTTTTGBATAGAGGAGCMATGATRA +AAGGNCAYDCCDDGAAAGTHGBTAATCKYTBTACBGTBCTTTTTGDTAASSWTAAWAARA +TTGGCTAAGWGRADTYACATAGCTCBTAGATAWAGCAATNGTATMATGTTKMMAGTAWTC +CCNTSGAAWATWCAAAAMACTGAADNTYGATNAATCCGAYWNCTAACGTTAGAGDTTTTC +ATCTGGKRTAVGAABVCTGWGBTCTDVGKATTBTCTAAGGVADAAAVWTCTAGGGGAGGG +TTAGAACAATTAAHTAATNAAATGCATKATCTAAYRTDTCAGSAYTTYHGATRTTWAVTA +BGNTCDACAGBCCRCAGWCRTCABTGMMAWGMCTCAACCGATRTGBCAVAATCGTDWDAA +CAYAWAATWCTGGTAHCCCTAAGATAACSCTTAGTGSAACAWTBGTCDTTDGACWDBAAC +HTTTNGSKTYYAAYGGATNTGATTTAARTTAMBAATCTAAGTBTCATYTAACTTADTGTT +TCGATACGAAHGGCYATATACCWDTKYATDCSHTDTCAAAATGTGBACTGSCCVGATGTA +TCMMAGCCTTDAAABAATGAAGAGTAACTHATMGVTTAATAACCCGGTTVSANTGCAATT +GTGAGATTTAMGTTTAMAAYGCTGACAYAAAAAGGCACAMYTAAGVGGCTGGAABVTACG +GATTSTYGTBVAKTATWACCGTGTKAGTDTGTATGTTTAAAGGAAAAAGTAACATARAAA +GGTYCAMNYAAABTATAGNTSATANAGTCATCCTATWADKAACTRGTMSACDGTATSAYT +AAHSHGTAABYGACTYTATADTGSTATAGAGAAATCGNTAAAGGAAATCAGTTGTNCYMV +TNACDRTATBNATATASTAGAAMSCGGGANRCKKMCAAACATTNAGTCTRMAATBMTACC +CGTACTTCTBGDSYAATWGAAAATGACADDCHAKAAAYATATTKTTTTCACANACWAGAA +AKATCCTTATTAYKHKCTAAACARTATTTTDATBTVWCYGCAATACTAGGKAAASTTDGA +MGGCHTTHAATVCAHDRYAGGRCTATACGTCMAGAGAGCTBTHGNACARTCCBDCTAAGA +GCGGCTTTARTAAAGAATCCNAGTAWBTGACTTGAATTACWTVACAGAAABCAATNAAAC +CGTNTRANTTGAYCMAWBADTANABRGGTKTHTWTAGTTVCTMBKTAGMTVKCCAGCANT +TVAGSWTTAGCCGCRHTTTCCTTHNTATTAAGAAGAATAGGMTRAARTCTABGTACDTTT +TATAAVDHAHTATAGATCCTAGTAAGYTWATDWCATGAGGGATAGTAAMDMNGBASTWAM +TSTATRBAYDABATGTATATYCGCACTGTTTTAACMCWBTATAWAGTATBTSTATVTTAR +CCTMTTAAKADATCAACTAATYTSVTAKGDATTATGCKTCAYCAKAATACTTKAANGAGT +ATTSDAGATCGGAAATACTTAAYAAVGTATMCGCTTGTGTDCTAATYTATTTTATTTWAA +CAGWRCTATGTAGMTGTTTGTTYKTNGTTKTCAGAACNTRACCTACKTGSRATGTGGGGG +CTGTCATTAAGTAAATNGSTTABCCCCTCGCAGCTCWHTCGCGAAGCAVATGCKACGHCA +ACAKTTAATAACASAAADATTWNYTGTAATTGTTCGTMHACHTWATGTGCWTTTTGAAHY +ACTTTGTAYAMSAAACTTAADAAATATAGTABMATATYAATGSGGTAGTTTGTGTBYGGT +TWSGSVGWMATTDMTCCWWCABTCSVACAGBAATGTTKATBGTCAATAATCTTCTTAAAC +ARVAATHAGYBWCTRWCABGTWWAATCTAAGTCASTAAAKTAAGVKBAATTBGABACGTA +AGGTTAAATAAAAACTRMDTWBCTTTTTAATAAAAGATMGCCTACKAKNTBAGYRASTGT +ASSTCGTHCGAAKTTATTATATTYTTTGTAGAACATGTCAAAACTWTWTHGKTCCYAATA +AAGTGGAYTMCYTAARCSTAAATWAKTGAATTTRAGTCTSSATACGACWAKAASATDAAA +TGYYACTSAACAAHAKTSHYARGASTATTATTHAGGYGGASTTTBGAKGATSANAACACD +TRGSTTRAAAAAAAACAAGARTCVTAGTAAGATAWATGVHAAKATWGAAAAGTYAHVTAC +TCTGRTGTCAWGATRVAAKTCGCAAVCGASWGGTTRTCSAMCCTAACASGWKKAWDAATG +ACRCBACTATGTGTCTTCAAAHGSCTATATTTCGTVWAGAAGTAYCKGARAKSGKAGTAN +TTTCYACATWATGTCTAAAADMDTWCAATSTKDACAMAADADBSAAATAGGCTHAHAGTA +CGACVGAATTATAAAGAHCCVAYHGHTTTACATSTTTATGNCCMTAGCATATGATAVAAG +>THREE Homo sapiens frequency +ATATTTATCTTTTCACTTCCTACATTGGTCAGACCATTATTCGACACGTGGCGTCATTTT +GTCATACCGGGTAATGTTGGAAACAAAACGTACTGATAAAATACTGAGTTGTAAACTCTA +ATCAGATAACGCGCTTGGATATTAAGATTCACACAGGGGTTTCGGCTGTAAAAAAACTTG +TGGAGCTGTTCTGGGACAGATAAGTTGTACCTCGTACTTAGCTAATTAATGAACCAACTG +ATTACGATAGAACAATTCTGAGGCCGCCAGGACAGCCAAATTTTAATCTTATAAAGCTGG +AAACAGCCGGTATTAGCTTCTCGCATACTTTGCCTGCATTGGTACCTTACAGATATCAGC +GTAGTCATATACACCTCGGTCTCAGCTAAGCTTGTATCTCTTAGAGTAGTTCAAAGATAG +TGGACAATACCTGTGGAATCGATTGCAGATATGGATTTATTTAACTACTGAGTCTCATTC +ACAAGCTAAGCAAGGAGCACGTTTTGGTGCCGGCATACCGATTTGCTATCATGTCAGCAA +ATTTGCGTTGTATTCCTAGTTGCACCCATTAAGGCCACACTCCGAACCTAATTATTACAT +CGCAAAGACATGTACGAAGGACCCGATGTCGAATAGAAGGGAGGACTGTTCATTGGAAGC +TAGACCAGAGGAATCGCAAAGATGCAACTCTTACAATAAAAATCTAATTTCAGTCAACAC +GCAATTTCTATAAGGTTTCCGATAATAATGAACCGTCTTCCACAGGGGAATTTGCCATGC +TCGTAAAAGTAGTTAATCCAAGTAGAAGAAATTTTGATAATGTTTTAAGTTGGCACGAAG +GAATTCAGAGAGATCTTACCTAACAAAGGCATTAGTAGATGTTCCTTGGTTCACACTCGG +TCAATCAGAGCACATACTACGGGCGATACCGGGAATGACACAACATCAATGAGATTGTTA +AGTGAGGTAATTGACTTTAGAGGACTCGATCAGTATACTGTCACTATGAACATCGTATTA +ATTGTTATCCGATATATACACCACCGATTTGCTTGTGCAAGGTTACAGACCCATTCGATA +AATACAAACACGGAGCGATATTATTTAAGGAGTGCTGTCTTCAAAAGAATTATTCCCACA +CCGACATAAGAACTTCGCTCCGTCATTCCAGATTTAAATAACATAACGTAACGCTTTGCT +GATAACATAACATAACCGAGAATTTGCTTAGGAAATTTGGAGCAATATTGCATTGTTTCT +CAGTCATCACAAGGCCCGCCAAAGAACTCTGAGAATCAGGATTCAACATGATTGGTAAGA +CTCTATATATATAACTTAATTCTTGTGTCCGGAGATAGAAAGAGGACGAGAGATACTACG +AAAGAAAGTGTACTTCGATGTATCAATTCAGACGCCTTCTCTATCATCAACATTATAGGT +CTCGTATATGCTCGGCGCGATCTGCTTCTCTCCGCCAATAGCCCCATAGTGTATTTCAAG +CGCAGTAACAGTGAAATCGTTACGAAGGTAGGGATGTTGCTTATAATTGTCGTAACTTAT +CGCTTATGTATCTTTCAAGAATGAACGGCAGCATATACATACGTTCTACCTTTAGCTACA +AAGCATCCATATACTCCCTCTCATGATTGAAACTCTTCCCTATTTTGTAGCCAATAGTGA +AAGCGTATTAGTATAAATTCGTCGGTTTTTCACTCGCAACTGTTATACTCTGCAAACAAA +CGAAAGCCTCATAGTACAAACCTAAAGCTACATACTTCATCATTGGCAGACCAGTGGCGG +TATTTCTACGGAAGCATCACTATAGATATAAAGTTTCCCTTCATGTACGTCTGTTAACCA +TATCACAAGAAACTGCTATCTCTGTCACGTAACAATTCACGCGCCTTATCGCCAAATGTT +CATATATGCGCGGTATACGTATGAACGAATACTAATTAGTATAACGGAGGATTCACGGGA +GGGATACTTGGGGCATTTATAAATCGTCTAAAAATTTTCTATCAGCACTTGCGGGTTATA +GTGGATTACTAGGCAACATAATATTCTGTATTGGTCCAAATGACGCTATAGATAAATTAG +CAAAATACATTGTTTCCATTTATGTAAGTCGAAACTCCAGGACTCCCGGGAACCAGTTAA +ACCGTCTGGAAAAGACACATTGTGAGCGGGACTTCAATGATAGCTTTCAATGAGCTTCTC +ATGCTTGGGGTCTGTACATATATGTTGGCGAAATTATCGTCTGTATTCTGTTATGCTTTG +ATCATGGGTTATTAGTATAGTGTCCGGTTAAGTACCAATACCGCTAGAGACCCGACCTAA +GTCGATAACTAACGATCATCGACGTAAGGATCGTCTCGATCAGTACTTCAGTCTAGATCT +GGGAATAGTAACTCGTTAGTGAACTATGTCGTGTCATAACTCTAAAATGCAATCAAATCT +TATTATTGAGTATTGATTATATAAAGCATCCGCTTAGCTTTACCCTCAAATGTTATATGC +AATTTAAAGCGCTTGATATCGTCTACTCAAGTTCAGGTTTCACATGGCCGCAACGTGACG +TTATTAGAGGTGGGTCATCATCTCTGAGGCTAGTGATGTTGAATACTCATTGAATGGGAA +GTGGAATACCATGCTCGTAGGTAACAGCATGACCTATAAAATATACTATGGGTGTGTGGT +AGATCAATATTGTTCAAGCATATCGTAACAATAACGGCTGAAATGTTACTGACATGAAAG +AGGGAGTCCAAACCATTCTAACAGCTGATCAAGTCGTCTAAAAACGCCTGGTTCAGCCTT +AAGAGTTATAAGCCAGACAAATTGTATCAATAGAGAATCCGTAAATTCCTCGGCCAACCT +CTTGCAAAGACATCACTATCAATATACTACCGTGATCTTAATTAGTGAACTTATATAAAT +ATCTACAACCAGATTCAACGGAAAAGCTTTAGTGGATTAGAAATTGCCAAGAATCACATT +CATGTGGGTTCGAATGCTTTAGTAATACCATTTCGCCGAGTAGTCACTTCGCTGAACTGT +CGTAAATTGCTATGACATAATCGAAAAGGATTGTCAAGAGTCGATTACTGCGGACTAATA +ATCCCCACGGGGGTGGTCTCATGTCTCCCCAGGCGAGTGGGGACGGTTGATAAACACGCT +GCATCGCGGACTGATGTTCCCAGTATTACATAGTCACATTGGATTGCGAGTAGTCTACCT +ATTTATGAGCGAGAGATGCCTCTAACTACTTCGACTTTTAAAACCTTTCCACGCCAGTAT +TCGGCGAAAGGGAAGTATTAAGGGTTGTCATAATTAAGCTGATACCACTTCAGACTTTGC +TCTACTTCTGTCTTTCATTGGTTTAGTAAAGTCTGTCCATTCGTCGAGACCGTCTTTTGC +AGCCTCATTCTACCAACTGCTCCGACTCTTAGTCTGCTTCTCCCAGCGTTATAACAAGAG +GCATTTTGTCATCCTTAAAACAATAATAAAGAACTCGGAGCACTGATATAATGACTGAAT +TAGAACCGCTTAAAAATACAACGAATAGATAAGACTATCGGATAAGATCTAATATGTAGT +GATTAAGCCCTTTATTAATTAATAATAGTTACCCTTTCTGATGTAACGCGACATATTACG +ATTTAGTGGCACGTCTGAATTGCAAAGCAGATCTCTACCCGATTTTTATTATAAATCCCG +TATACATCTTGACTTGAGTAATTGTTCATCTTTTTATATCTCTTCGTACTACAAATAATT +AATATCTCAACCCGTATTGTGTGATTCTAATTACCAACAGAATACGAGGAGGTTTTTGCT +TAGGGCCATATATAATGAATCTATCTCGTTTATTCGCGGAACCCGAGATAACATTACGAT +GTAACTATTTTAGAGAACTTAATACAAGAAACATTGCTGATTACTCATAACTAAATGCTT +GGTAATATATCCTCAGTGCCCCTACCATCTTTTACGCAGGGATGTAATTACTTAGGATTC +ATTGTGTAAGAATTACAATGAACGATGGATATGAAGGCATGTTGCGAGGTGTTCCTTGGT +ATGTGAAGTTCGCAGGGCAACAAAAATTTCGCAGAATAGGCCTCAAAGTATTGGTAAAGA +AGACAACTAATCATCACGAGCTTCTGATATCAATACGAACGAGTCCTGTGATGGATGAAA +GAAAGTCGTATCGAAAATGTCAAGAGTCTGCCCAATGTAACTTACTTCAAAAAATAACGC +TTCCGCCAAGTACGTTCGAATAAACGTAATTTTAAAAATACATAAGGGGTGTTAGAAAGT +AAGCGACGGGATATAAGTTAGACTCAAGATTCCGCCGTAAAACGAGACTGATTCCGAAGA +TTGTTCGTGGATCTGGTCATGACTTTCACTGAGTAAGGAGTTTCGACATATGTCAATAAA +CACAAAAATAGAAGCTATTCGATCTGAAAAATATTAGGACAAGAAACTATCTCACGCTAG +CCCAGAATATTCACTCACCCACGGGCGATACTAAAGCACTATATAGTCGCGTGATTACTA +TACATATGGTACACATAAGAATCACGATCAGGTTCTCAATTTTCAACAATATATGTTTAT +TTGCATAGGTAATATTAGGCCTTTAAGAGAAGGATGGGTGAGATACTCCGGGGATGGCGG +CAATAAAGAAAAACACGATATGAGTAATAGGATCCTAATATCTTGGCGAGAGACTTAAGG +TACGAATTTTGCGCAATCTATTTTTTACTTGGCCAGAATTCATGTATGGTATAAGTACGA +ACTTTTTTGATCACTTTCATGGCTACCTGATTAGGATAGTTTGAGGAATTTCCCAAATAT +ACCGATTTAATATACACTAGGGCTTGTCACTTTGAGTCAGAAAAAGAATATAATTACTTA +GGGTAATGCTGCATACATATTCTTATATTGCAAAGGTTCTCTGGGTAATCTTGAGCCTTC +ACGATACCTGGTGAAGTGTT diff --git a/test/pending/shootout/revcomp.scala-3.scala b/test/pending/shootout/revcomp.scala-3.scala new file mode 100644 index 0000000000..ae12f0499b --- /dev/null +++ b/test/pending/shootout/revcomp.scala-3.scala @@ -0,0 +1,147 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + +import java.io._ +import scala.collection.mutable.Stack + +object revcomp { + def main(args: Array[String]) = { + val out = new FastaOutputStream(System.out) + val in = new FastaInputStream(System.in) + + out.writeReverseComplement( in.readSequenceStack ) + out.writeReverseComplement( in.readSequenceStack ) + out.writeReverseComplement( in.readSequenceStack ) + + in.close + out.close + } +} + + +trait FastaByteStream { + val nl = '\n'.toByte + + type Line = Array[Byte] + type LineStack = Stack[Line] +} + + +// extend the Java BufferedInputStream class + +final class FastaInputStream(in: InputStream) + extends BufferedInputStream(in) with FastaByteStream { + + val gt = '>'.toByte + val sc = ';'.toByte + + def readSequenceStack(): Pair[Line,LineStack] = { + var header: Line = null + val lines: LineStack = new Stack + + var line = readLine() + while (line != null) { + val c = line(0) + if (c == gt){ // '>' + if (header == null){ + header = line + } else { + pos = pos - line.length - 1 // reposition to start of line + return Pair(header,lines) + } + } else { + if (c != sc) lines push line // ';' + } + line = readLine() + } + return Pair(header,lines) + } + + def readLine() = { + var bytes: Line = null + if (in == null) bytes + else { + mark(128) // mark the start of the line + if (count == 0) read() // fill buffer + + var i = markpos + while (i < count && buf(i) != nl) i = i + 1 + + if (i >= count){ // line extends past end of buffer + pos = i; read(); i = pos; // fill buffer again + while (i < count && buf(i) != nl) i = i + 1 + } + + if (i < count){ + bytes = new Array(i - markpos) + System.arraycopy(buf, markpos, bytes, 0, i - markpos); + pos = i+1 + } + } + bytes + } +} + + +// extend the Java BufferedOutputStream class + +final class FastaOutputStream(in: OutputStream) + extends BufferedOutputStream(in) with FastaByteStream { + + private val IUB = IUBCodeComplements + + private def IUBCodeComplements() = { + val code = "ABCDGHKMNRSTVWYabcdghkmnrstvwy".getBytes + val comp = "TVGHCDMKNYSABWRTVGHCDMKNYSABWR".getBytes + val iub: Array[Byte] = new Array( 'z'.toByte ) + + for (indexValue <- code zip comp) + indexValue match { case Pair(i,v) => iub(i) = v } + + iub + } + + def writeReverseComplement(sequence: Pair[Line,LineStack]) = { + + def inplaceComplementReverse(b: Array[Byte]) = { + var i = 0 + var j = b.length - 1 + while (i < j){ + val swap = b(i) + b(i) = IUB( b(j) ) + b(j) = IUB( swap ) + i = i + 1 + j = j - 1 + } + if (i == j) b(i) = IUB( b(i) ) + } + + sequence match { + case Pair(header,lines) => { + + write(header); write(nl) + + val k = if (lines.isEmpty) 0 else lines.top.length + val LineLength = 60 + val isSplitLine = k < LineLength + var isFirstLine = true + + while (!lines.isEmpty) { + val line = lines.pop + inplaceComplementReverse(line) + + if (isSplitLine){ + if (isFirstLine){ write(line); isFirstLine = false } + else { write(line,0,LineLength-k); write(nl); write(line,LineLength-k,k) } + } + else { write(line); write(nl) } + } + + if (isSplitLine && !isFirstLine) write(nl) + } + } + } + +} diff --git a/test/pending/shootout/revcomp.scala-3.scala.runner b/test/pending/shootout/revcomp.scala-3.scala.runner new file mode 100644 index 0000000000..f51d6170c8 --- /dev/null +++ b/test/pending/shootout/revcomp.scala-3.scala.runner @@ -0,0 +1,6 @@ +object Test extends Application { + for(n <- List(25000,250000,2500000)) { + System.setIn(new java.io.FileInputStream(System.getProperty("partest.cwd")+"/revcomp-input"+n+".txt")) + revcomp.main(Array(n.toString)) + } +} diff --git a/test/pending/shootout/sieve.scala b/test/pending/shootout/sieve.scala new file mode 100644 index 0000000000..b494980ee4 --- /dev/null +++ b/test/pending/shootout/sieve.scala @@ -0,0 +1,43 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy (Scala novice) +*/ + +object sieve { + def main(args: Array[String]) = { + var n = toPositiveInt(args); + val start = 2; + val stop = 8192; + val isPrime = new Array[Boolean](stop+1); + var count: Int = 0; + + while (n>0) { + count = 0; + + for (i <- Iterator.range(start,stop+1)) + isPrime(i)=true; + + for (i <- Iterator.range(start,stop+1)) { + if( isPrime(i) ) { + var k = i+i; + while (k<=stop) { isPrime(k)=false; k=k+i; } + count = count+1; + } + } + n=n-1; + } + + Console.println("Count: " + count); + } + + + private def toPositiveInt(s: Array[String]) = { + val i = + try { Integer.parseInt(s(0)); } + catch { case _ => 1 } + if (i>0) i; else 1; + } +} + + + diff --git a/test/pending/shootout/sieve.scala.runner b/test/pending/shootout/sieve.scala.runner new file mode 100644 index 0000000000..893c3abe90 --- /dev/null +++ b/test/pending/shootout/sieve.scala.runner @@ -0,0 +1,3 @@ +object Test extends Application { + for(n <- List(300,600,900,1200)) sieve.main(Array(n.toString)) +} |