Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
namespace CodeJamPractice
{
class Program
{
private const string BaseFolderPath = @"C:\path\to\CodeJam\";
static void Main(string[] args)
{
var inputLines = File.ReadAllLines(BaseFolderPath + @"AlienLanguage\A-large-practice.in");
//GetWordlength / DictionaryLength / Number of testCases
string[] ldnValues = inputLines[0].Split(' ');
int LettersInWord = int.Parse(ldnValues[0]);
int WordsInLanguage = int.Parse(ldnValues[1]);
int NumberOfTestCases = int.Parse(ldnValues[2]);
// Create a dictionary of (test case number , test case string) so that it can be paralellised and still keep its test number
int index = 1;
Dictionary<int, string> testCasesWithIndex = inputLines.Skip(1 + WordsInLanguage).Take(NumberOfTestCases).ToDictionary(x => index++, x => x);
var resultDict = new Dictionary<int, string>();
string allWords = string.Join("|", inputLines.Skip(1).Take(WordsInLanguage));
testCasesWithIndex.AsParallel().ForAll(kvp =>
{
int testCaseNumber = kvp.Key;
string testCase = kvp.Value;
var possibleValues = Regex.Matches(allWords, testCase.Replace("(", "[").Replace(")", "]"));
string result = string.Format("Case #{0}: {1}", testCaseNumber, possibleValues.Count);
resultDict[kvp.Key] = result;
});
string output = string.Join("\n", resultDict.OrderBy(kvp => kvp.Key).Select(kvp => kvp.Value));
File.WriteAllText(BaseFolderPath + @"AlienLanguage\output.txt", output);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment