Created
January 10, 2012 12:30
-
-
Save kxbmap/1588803 to your computer and use it in GitHub Desktop.
Scala標準バージョンとScalazバージョン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val ACGT = "ACGT".to[Stream] | |
@annotation.tailrec | |
def solve0(n: Int, ss: Stream[List[Char]]): Stream[List[Char]] = | |
if (n == 0) ss | |
else solve0(n - 1, ACGT.flatMap(c => ss.map(c :: _))) | |
def solve(n: Int): Stream[String] = | |
solve0(n, Stream(Nil)) collect { | |
case cs if cs.containsSlice("AAG") => cs.mkString | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._, Scalaz._ | |
val ACGT = "ACGT".to[Stream] | |
def solve(n: Int): Stream[String] = | |
ACGT.replicateM(n) collect { | |
case cs if cs.containsSlice("AAG") => cs.mkString | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> solve(5) foreach println | |
AAAAG | |
AAAGA | |
AAAGC | |
AAAGG | |
AAAGT | |
AAGAA | |
AAGAC | |
AAGAG | |
AAGAT | |
AAGCA | |
AAGCC | |
AAGCG | |
AAGCT | |
AAGGA | |
AAGGC | |
AAGGG | |
AAGGT | |
AAGTA | |
AAGTC | |
AAGTG | |
AAGTT | |
ACAAG | |
AGAAG | |
ATAAG | |
CAAAG | |
CAAGA | |
CAAGC | |
CAAGG | |
CAAGT | |
CCAAG | |
CGAAG | |
CTAAG | |
GAAAG | |
GAAGA | |
GAAGC | |
GAAGG | |
GAAGT | |
GCAAG | |
GGAAG | |
GTAAG | |
TAAAG | |
TAAGA | |
TAAGC | |
TAAGG | |
TAAGT | |
TCAAG | |
TGAAG | |
TTAAG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment