import Char

lessPrimes :: IO ()
lessPrimes = do
  putStr "Zahl eingeben: "
  n <- getLine >>= return . read
  print (takeWhile (<n) primes)

primes :: [Int]
primes = sieve [2..]
 where
  sieve (x:xs) = x : sieve (filter ((0/=).(`mod`x)) xs)


diamond :: Int -> IO ()
diamond n = draw 1
 where
  draw m = if n<=m then line m else line m >> draw (m+1) >> line m
  line m = putStr (replicate (n-m) ' ') >> putStrLn (right (2*m-3))
  right k = "*" ++ if k<0 then "" else replicate k ' ' ++ "*"


-- Einfacher als Franks Lösung, weil mein Mac Umlaute in einem Zeichen kodiert
htmlEncoder :: String -> String -> IO ()
htmlEncoder infile outfile
  = readFile infile >>= writeFile outfile . concatMap encode

encode :: Char -> String
encode c = maybe [c] id $ lookup c (zip "ßäÄöÖüÜ" codes)
 where
  codes = "&szlig;":concatMap (\c -> [uml c, uml (toUpper c)]) "aou"
  uml c = "&" ++ c : "uml;"

