Programming Praxis – NPR Sunday Puzzle

In today’s Programming Praxis exercise, our goal is to find two words that consist of the letters A through F and two other letters. Let’s get started, shall we?

import Data.List

Checking if a word is valid is a simple matter of checking whether it has eight letters and whether it contains all six required letters.

npr :: String -> Bool
npr s = length s == 8 && null ("abcdef" \\ s)

With that out of the way, all that’s left to do is to search all the words in the ddictionary for the ones the satisfy the criterium.

main :: IO ()
main = mapM_ print . filter npr . lines =<< readFile "en_US.dic"

As expected, the only words found are boldface and feedback.

About these ads

Tags: , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 35 other followers

%d bloggers like this: