Created
October 8, 2018 18:36
-
-
Save teunw/edbc72996459df5bf10564e3d34df111 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
using System; | |
using System.Collections.Generic; | |
using System.Collections.Immutable; | |
using System.IO; | |
using System.Linq; | |
namespace ConsoleApp1 | |
{ | |
static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(File | |
.ReadAllText("words.txt") | |
.Split("\n").Length); | |
var possibleLetters = "ABCDEFHLNPRSTUY".ToCharArray(); | |
var words = File | |
.ReadAllText("words.txt") | |
.Split("\n") | |
// Convert every word to all UPPERCASE, easy comparison later | |
.Select(s => s.ToUpper()) | |
.ToImmutableList() | |
// Longest word first | |
.Sort((a, b) => b.Length - a.Length); | |
// First valid entry is longest word (because of the sorting) | |
var first = words.First(w => w.ToCharArray().All(possibleLetters.Contains)); | |
Console.WriteLine(first); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment