Created
December 24, 2017 14:34
-
-
Save DavidPx/d6c0da8eb553c3b65564636e3cc8a249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Query Kind="Statements"> | |
<NuGetReference>CsvHelper</NuGetReference> | |
<Namespace>CsvHelper</Namespace> | |
</Query> | |
// NPR Sunday Puzzle for 2017-12-24 | |
// city data: https://github.com/grammakov/USA-cities-and-states | |
var cities = new List<string>(); | |
var config = new CsvHelper.Configuration.Configuration{Delimiter = "|", HasHeaderRecord = true}; | |
var tr = File.OpenText(@"C:\temp\cities\USA-cities-and-states-master\us_cities_states_counties.csv"); | |
var reader = new CsvHelper.CsvReader(tr, config); | |
reader.Read(); | |
while (reader.Read()) | |
{ | |
var city = reader[0]; | |
if (!cities.Contains(city)) | |
{ | |
cities.Add(city); | |
} | |
} | |
cities | |
.Select ( | |
city => | |
{ | |
return city.Replace(" ", "").Replace(".", "").ToLower(); | |
}) | |
.Cast<IEnumerable<char>>() | |
.Where ( | |
city => city.Count() == 10 && city.Distinct().Count() == 3 | |
).Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment