This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(add-to-list 'load-path "~/emacs/haskell") | |
(load "~/emacs/haskell/haskell-site-file" ) | |
(require 'inf-haskell) | |
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode) | |
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent) | |
(setq haskell-program-name "ghci") | |
(defun flymake-get-Haskell-cmdline (source base-dir) | |
(list "flycheck_haskell.pl" | |
(list source base-dir))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Doc where | |
import Control.Monad | |
import System.Directory | |
qualify :: FilePath -> IO String | |
qualify x = liftM (\y -> | |
y ++ "/.cabal/share/doc/" ++ x ++ "/html/doc-index.html" | |
) getHomeDirectory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p9_fix :: Int -> Int -> ( Int, Int ) | |
p9_fix x y = | |
case ( x > y || x == y ) of | |
True -> | |
let y' = x + 1 | |
in | |
(x,y') | |
False -> | |
(x,y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p9_is_correct :: Int -> Int -> Int -> Bool | |
p9_is_correct x y z = | |
x^2 + y^2 == z^2 && | |
x + y + z == 1000 && | |
x < y && y < z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Check the actual problem for this 1000 digit number. | |
p8 :: String | |
p8 = "73167176531330624..." | |
p8_five [] = [] | |
p8_five x = take 5 x : p8_five ( tail x ) | |
-- Take a string, break it into seperate integers, and then get a product of those integers. | |
prod_char x = product $ map digitToInt x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Ahh, that's better! | |
p7 = ( filter isprime [ 1.. ] ) !! 10001 | |
{- | |
1. [1..] - An infinite list, starting with 1, of integers. [1,2,3.. and so on] | |
2. (filter isprime x ) - Filter out of that list the numbers for which isprime is true. | |
3. !! 10001 - Take the 10001th element from that list. | |
-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
problem_six = | |
let sum_of_squares = sum $ map (\x -> x * x ) [1..100] | |
sum_of_numbers = sum [1..100] | |
in | |
( sum_of_numbers * sum_of_numbers ) - sum_of_squares |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The Haskell Wiki solution to this still seems like witchcraft. | |
-- foldr1 lcm [1..20] | |
c_s :: Int -> [ Int ] | |
c_s x = nub $ map ( x `mod` ) [ 1..20 ] | |
p5_iter :: Int -> Int | |
p5_iter x = case length $ nub $ map ( x `mod` ) [ 1..20 ] of | |
1 -> | |
x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (sort) | |
problem_four :: Int | |
problem_four = | |
head . reverse . sort $ | |
filter (>0) $ concat $ map (\x -> | |
map( \y -> fix x y ) nx | |
) nx | |
where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gpfsearch :: ( Integral a ) => a -> a -> a | |
gpfsearch f x | x == f = x | |
| divides x f = gpfsearch f ( div x f ) | |
| otherwise = gpfsearch ( f + 1 ) x | |
where divides x y = mod x y == 0 |