Skip to content

Instantly share code, notes, and snippets.

@AspenForester
Last active October 12, 2018 20:49
Show Gist options
  • Save AspenForester/2581bcadbddd6a935ae4545dcb759c63 to your computer and use it in GitHub Desktop.
Save AspenForester/2581bcadbddd6a935ae4545dcb759c63 to your computer and use it in GitHub Desktop.
Inspired by Tom Scott's Basics video on longest word you can create with a seven segment display. This version gets all of the longest, not just first of the longest and is lax on what letters count, allowing S and O. It also gets the word list from github, just in case any new words are invented.
$Words = (invoke-webrequest -uri https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt).content -split ("`n")
<# Or If you have already downloaded the list
$Words = Get-Content -Path .\words_alpha.txt
#>
[regex]$NonLetters = "[gkmqvwxyz]"
$LongestWords = @()
foreach ($Word in $Words)
{
if ($Word -notmatch $NonLetters)
{
if ($word.length -eq $LongestWords[-1].length)
{
$LongestWords += $Word
}
elseif ($word.length -gt $LongestWords[-1].length)
{
$LongestWords = @()
$LongestWords += $Word
}
}
}
$LongestWords
$LongestWords[-1].Length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment