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
-- rewrite after checking the actual formula :X | |
leibs_pi :: Double -> Double | |
leibs_pi n = 4 * sum [(-1.0)**n' / (2.0*n' + 1.0) | n' <- [0.0..(n-1)]] |
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
-- leibniz's pi formula | |
-- a very elementary take i guess :P | |
odd_ds :: Int -> [Double] | |
odd_ds n = [x | x <- take n [1.0,3.0..]] | |
y_eq :: Double -> Double -> Double | |
y_eq d s = s * (1.0 / d) | |
leibs_series :: [Double] -> Double -> Double |
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
-- just giving functors and the applicative operators a test drive | |
import Control.Applicative | |
import Data.Char | |
emails :: [String] | |
emails = ["[email protected]", "[email protected]", "somethingthatsmellslikeSPAM", "[email protected]", "[email protected]"] | |
hasAt :: [Char] -> Bool |
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
-- read a text file | |
-- print a line, wait for return by user, repeat. exits when no more lines to print | |
import System.Environment | |
import System.IO | |
import System.Exit | |
parse ["-h"] = putStrLn "./text_reader [-h] file" >> exitWith ExitSuccess | |
parse [f] = readFile f |
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 System.Random | |
import Control.Monad | |
subV :: Integer -> Integer -> Integer | |
subV x y | x == y = 0 | |
| otherwise = 1 | |
encode :: [Integer] -> [Integer] -> [Integer] | |
encode [] _ = [] | |
encode (p:ps) (v1:v1s) = [subV p v1] ++ encode ps v1s |
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
-- implementing a simple 2 key encrypt/decrypt | |
-- assuming a n-vector p (message) | |
-- generate a random n-vector v1 (key1) | |
-- and n-vector v2 (via subtract v1 from p) | |
subV :: Integer -> Integer -> Integer | |
subV x y | x == y = 0 | |
| otherwise = 1 | |
encode :: [Integer] -> [Integer] -> [Integer] |
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
{-# LANGUAGE OverloadedStrings #-} | |
import Prelude | |
import qualified Prelude as P | |
import Data.Monoid (mempty) | |
import Web.Scotty | |
import qualified Web.Scotty as S | |
import Text.Blaze.Html5 | |
import qualified Text.Blaze.Html5 as H |
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
let q s = putStrLn (s ++ show s) in q "let q s = putStrLn (s ++ show s) in q " | |
-- s is mapped to string "let q s = putStrLn (s ++ show s) in q " | |
-- q is mapped to expr putStrLn (s ++ show s) | |
-- show s produces a string with quotes escaped | |
-- e.g. show "hello" produces "\"hello\"" | |
-- 'in q' above seems to cause the expression to be evaluated | |
-- e.g. |
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.Char | |
type Bit = Int | |
-- in reverse order | |
bits2int :: [Bit] -> Int | |
bits2int bits = sum [w*b | (w,b) <- zip weights bits] | |
where weights = iterate (*2) 1 | |
int2bin :: Int -> [Bit] |
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
-- this works | |
expo :: Int -> Int -> Int | |
expo 0 n = 0 | |
expo m 0 = 1 | |
expo m n = m * (expo m (n - 1)) | |
-- not this one | |
-- attempt to load in ghci throws: exponentiation.hs:11:10: Parse error in pattern: n + 1 | |
expo :: Int -> Int -> Int | |
expo 0 n = 0 |