forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexdna2.fs
33 lines (28 loc) · 997 Bytes
/
regexdna2.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/// The Computer Language Benchmarks Game
/// http://shootout.alioth.debian.org/
///
/// Contributed by Valentin Kraevskiy
module Regexdna
open System.Text.RegularExpressions
let regex s = Regex(s, RegexOptions.Compiled)
let input = stdin.ReadToEnd()
let text = (regex ">.*\n|\n").Replace(input, "")
[ "agggtaaa|tttaccct"; "[cgt]gggtaaa|tttaccc[acg]"; "a[act]ggtaaa|tttacc[agt]t";
"ag[act]gtaaa|tttac[agt]ct"; "agg[act]taaa|ttta[agt]cct";
"aggg[acg]aaa|ttt[cgt]ccct"; "agggt[cgt]aa|tt[acg]accct";
"agggta[cgt]a|t[acg]taccct"; "agggtaa[cgt]|[acg]ttaccct" ]
|> List.iter (fun s -> printf "%s %i\n" s ((regex s).Matches text).Count)
let newText =
[ "B", "(c|g|t)"
"D", "(a|g|t)"
"H", "(a|c|t)"
"K", "(g|t)"
"M", "(a|c)"
"N", "(a|c|g|t)"
"R", "(a|g)"
"S", "(c|g)"
"V", "(a|c|g)"
"W", "(a|t)"
"Y", "(c|t)" ]
|> List.fold (fun s (code, alt) -> (regex code).Replace(s, alt)) text
printf "\n%i\n%i\n%i\n" input.Length text.Length newText.Length