Skip to content

Instantly share code, notes, and snippets.

@joom
Last active August 29, 2015 14:03
Show Gist options
  • Save joom/37d5afbba1b62d381142 to your computer and use it in GitHub Desktop.
Save joom/37d5afbba1b62d381142 to your computer and use it in GitHub Desktop.
Find longest word with letters in alphabetical order in Turkish language
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Function (on)
up = ['A','B','C','Ç','D','E','F','G','Ğ','H','I','İ','J','K','L','M','N','O','Ö','P','R','S','Ş','T','U','Ü','V','Y','Z']
low = ['a','b','c','ç','d','e','f','g','ğ','h','ı','i','j','k','l','m','n','o','ö','p','r','s','ş','t','u','ü','v','y','z']
lower xs = map single xs
where single x = case (x `elemIndex` up) of
Nothing -> x
Just n -> low !! n
after a b = an <= bn
where (an, bn) = case (a `elemIndex` low, b `elemIndex` low) of
(Just x, Just y) -> (x, y)
(_, _) -> (1,0)
firstWord s = (splitOn " " s) !! 0
alph xs = and $ zipWith after xs (drop 1 xs)
main :: IO()
main = do
file <- readFile "dict.txt"
let words = lines file
print $ length words
let selected = filter alph (map (lower . firstWord) words)
print $ maximumBy (compare `on` length) selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment