summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-02-07 15:30:41 -0600
committerJesse Luehrs <doy@tozt.net>2013-02-07 15:30:41 -0600
commit285740580fde9d451f8f5589484cb94fab5596c2 (patch)
tree56a7f5f994bd21cba8b0b3ef6bbe2fbf0facfb53
parent44d3a187dd080d37a960a48ab3bb286ac1fa7bc8 (diff)
downloadrosalind-285740580fde9d451f8f5589484cb94fab5596c2.tar.gz
rosalind-285740580fde9d451f8f5589484cb94fab5596c2.zip
scala solution
-rw-r--r--DNA.scala18
1 files changed, 18 insertions, 0 deletions
diff --git a/DNA.scala b/DNA.scala
new file mode 100644
index 0000000..d382594
--- /dev/null
+++ b/DNA.scala
@@ -0,0 +1,18 @@
+import io._
+
+def countNucleotides (dna: Stream[Char]): List[Int] = {
+ var a, c, g, t = 0
+ for (base <- dna) {
+ base match {
+ case 'A' => a += 1
+ case 'C' => c += 1
+ case 'G' => g += 1
+ case 'T' => t += 1
+ case c => println("Unknown character: " + c)
+ }
+ }
+ List(a, c, g, t)
+}
+
+val dna = Source.fromInputStream(System.in).toStream.takeWhile(_ != '\n')
+println(countNucleotides(dna).mkString(" "))