The Computer Language
Benchmarks Game

regex-redux C# .NET Core #2 program

source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/
 *
 * contributed by Jimmy Tang
 * modified by Sindhudweep Narayan Sarkar
*/

using System;
using System.Linq;
using System.Threading;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class regexredux {
   static void Main() {
      string sequence = Console.In.ReadToEnd();
      int initialLength = sequence.Length;
            
      sequence = Regex.Replace(sequence, ">.*\n|\n", "");
      int codeLength = sequence.Length;
      
      string[] variants = {
      "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"
      };
      
      Parallel.For(0, variants.Length, i => 
         { 
            var pattern = new Regex(variants[i], RegexOptions.Compiled); 
            variants[i] += " " + pattern.Matches(sequence).Count; 
         });
      Console.WriteLine(string.Join("\n", variants));
      
      var dict = new Dictionary<string, string> {
         {"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)"} 
      };
      sequence = new Regex("[WYKMSRBDVHN]", RegexOptions.Compiled).Replace(sequence, m => dict[m.Value]);
      Console.WriteLine("\n{0}\n{1}\n{2}", initialLength, codeLength, sequence.Length);
   }
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
2.0.0 cdcd1928c9
"System.GC.Server": true


Mon, 14 Aug 2017 20:19:32 GMT

MAKE:
cp regexredux.csharpcore-2.csharpcore Program.cs
cp Include/csharpcore/tmp.csproj .
cp Include/csharpcore/runtimeconfig.template.json .
mkdir obj
cp Include/csharpcore/tmp.csproj.nuget.g.props ./obj
cp Include/csharpcore/tmp.csproj.nuget.g.targets ./obj
/usr/bin/dotnet build -c Release
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  tmp -> /home/dunham/benchmarksgame_quadcore/regexredux/tmp/bin/Release/netcoreapp2.0/tmp.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.52

6.20s to complete and log all make actions

COMMAND LINE:
/usr/bin/dotnet ./bin/Release/netcoreapp2.0/tmp.dll 0 < regexredux-input50000.txt

UNEXPECTED OUTPUT 

13c13
< 668262
---
> 273927

PROGRAM OUTPUT:
agggtaaa|tttaccct 3
[cgt]gggtaaa|tttaccc[acg] 12
a[act]ggtaaa|tttacc[agt]t 43
ag[act]gtaaa|tttac[agt]ct 27
agg[act]taaa|ttta[agt]cct 58
aggg[acg]aaa|ttt[cgt]ccct 16
agggt[cgt]aa|tt[acg]accct 15
agggta[cgt]a|t[acg]taccct 18
agggtaa[cgt]|[acg]ttaccct 20

508411
500000
668262