Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. private static HashSet<string> dictionary;
  2. private static IOrderedEnumerable<string> results;
  3.  
  4. static IEnumerable<string> Process() {
  5. var retVal = new List<string>();
  6. foreach (var word in dictionary) {
  7. if (word == "ANNA") {
  8. Console.Write("");
  9. }
  10. if (dictionary.Contains(NextWord(word))) {
  11. Console.WriteLine(NextWord(word) + " <-- " + word);
  12. retVal.Add(word);
  13. }
  14. }
  15.  
  16. return retVal;
  17. }
  18.  
  19. static string NextWord(string word) {
  20. var chars = word.ToUpper().ToCharArray().Select(c => (c == 'Z') ? 'A' : (char)((int)c + 1)).ToArray();
  21. return new string(chars);
  22. }
  23.  
  24. static string PrevWord(string word) {
  25. var chars = word.ToUpper().ToCharArray().Select(c => (c == 'A') ? 'Z' : (char)((int)c - 1)).ToArray();
  26. return new string(chars);
  27. }
  28.  
  29. static HashSet<string> LoadWords() {
  30. IEnumerable<string> words;
  31. using (var sr = new StreamReader(@"\\bcna.corp\DFS\shared\QuantStrat\iCredit-iOS\words.txt")) {
  32. words = sr.ReadToEnd().Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
  33. }
  34. return new HashSet<string>(words.Select(w => w.ToUpper()));
  35. }
  36.  
  37. static void Main(string[] args) {
  38. dictionary = LoadWords();
  39. results = Process().OrderBy(w => w);
  40.  
  41. using (var sw = new StreamWriter(@"\\bcna.corp\DFS\shared\QuantStrat\iCredit-iOS\result.txt")) {
  42. foreach (var word in results) {
  43. sw.WriteLine(NextWord(word) + " <-- " + word);
  44. }
  45. }
  46.  
  47. return;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement