Skip to content

Instantly share code, notes, and snippets.

@dysinger
Created March 26, 2016 19:35
Show Gist options
  • Select an option

  • Save dysinger/17dfb2e6d068e2f621bc to your computer and use it in GitHub Desktop.

Select an option

Save dysinger/17dfb2e6d068e2f621bc to your computer and use it in GitHub Desktop.
Prints out every dictionary word that could be a FCC ham call sign by replacing the numbers 1,3,4,0 with the letter I,E,A,O
import qualified Data.Char as C
import qualified Data.Set as S
main :: IO ()
main = do
let alpha = ['A' .. 'Z']
leetRegionNum = "IEAO"
oneByOnes =
[[a, n, b] | a <- "KNW"
, n <- leetRegionNum
, b <- alpha]
oneByTwos =
[a ++ [b] | a <- oneByOnes
, b <- alpha]
oneByThrees =
[a ++ [b] | a <- oneByTwos
, b <- alpha]
twoByOnes =
[[a, b, n, c] | a <- "AKNW"
, b <- alpha
, n <- leetRegionNum
, b `S.notMember`
if a == 'A'
then (S.fromList "HLMNOPQRSTUVWXYZ")
else (S.fromList "HLP")
, c <- alpha]
twoByTwos =
[a ++ [b] | a <- twoByOnes
, b <- alpha]
twoByThrees =
[a ++ [b] | a <- twoByTwos
, b <- alpha]
calls =
S.fromList
(concat
[ oneByOnes
, oneByTwos
, oneByThrees
, twoByOnes
, twoByTwos
, twoByThrees])
dict <-
pure . S.fromList . lines . map C.toUpper . filter (/= '\'') =<<
readFile "/usr/share/dict/american-english"
mapM_ putStrLn (S.intersection calls dict)
@dysinger

Copy link
Copy Markdown
Author

Output looks like:

ABACI
ABACK
ABACUS
ABAFT
ABASE
ABASED
ABASES
ABASH
ABATE
ABATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment