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 Network.SunlightLabs.Legislators where | |
import Network.SunlightLabs.Utils | |
import Network.SunlightLabs.JSON | |
import Control.Monad | |
import Data.Maybe | |
import Network.HTTP | |
import qualified Data.Map as M |
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 Euler where | |
import List | |
import Control.Parallel | |
import Char | |
is_by_5 x = x `mod` 5 == 0 | |
is_by_3 x = x `mod` 3 == 0 |
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
p1 :: Int | |
p1 = sum $ nub $ | |
filter (\x -> x `mod` 3 == 0) [1..999] ++ | |
filter (\x -> x `mod` 5 == 0) [ 1..999 ] |
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
fib :: ( Num t, Num t1 ) => t -> t1 | |
fib 0 = 0 | |
fib 1 = 1 | |
fib n = fib (n-1) + fib (n-2) | |
cnl_clink :: (Num t, Num a, Ord a) => t -> [a] | |
cnl_clink x = let lx = fib x | |
in | |
if lx > 4000000 then | |
[] |
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 |
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
-- 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
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
-- 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
-- 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 |
OlderNewer