-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (39 loc) · 1.55 KB
/
Program.cs
File metadata and controls
49 lines (39 loc) · 1.55 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace MagicCountryResolver
{
class Program
{
private static string[] _countries;
static void Main(string[] args)
{
if (args.Length < 2 )
Quit();
Func<string, string, bool> validatorFunction = null;
if (args[0].ToLower() == "none")
validatorFunction = (word, wordToCompareTo) => !word.HasAnyLetters(wordToCompareTo);
else if (args[0].ToLower() == "all")
validatorFunction = (word, wordToCompareTo) => word.HasAllLetters(wordToCompareTo);
else
Quit();
_countries = File.ReadAllLines("../countries.txt");
List<string> foundCountries = GetCountries(args[1], validatorFunction).ToList();
foreach (var country in foundCountries)
Console.WriteLine(country);
Console.WriteLine();
Console.WriteLine("A total of {0} countries.", foundCountries.Count());
}
private static void Quit()
{
Console.WriteLine("Give me a mode ('none' or 'all') and a word to compare against!");
Environment.Exit(0);
}
private static IEnumerable<string> GetCountries(string input, Func<string, string, bool> validatorFunction)
{
input = input.ToLower();
return _countries.Where(country => validatorFunction(country.ToLower(), input));
}
}
}