Skip to content

Instantly share code, notes, and snippets.

@teunw
Created October 8, 2018 18:36
Show Gist options
  • Save teunw/edbc72996459df5bf10564e3d34df111 to your computer and use it in GitHub Desktop.
Save teunw/edbc72996459df5bf10564e3d34df111 to your computer and use it in GitHub Desktop.
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