This file contains 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
-- Some code for parsing natural language, transforming grammar trees into statements in | |
-- propositional logic, and infering things from those propositions. | |
-- | |
-- This code is pretty unstructured, but I might salvage some of some day. | |
-- I'm leaving this here on the off chance that someone stumbles upon this and finds it | |
-- useful, enjoy! | |
module Main where | |
import Data.List.Split |
This file contains 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
first (x,_,_) = x | |
second (_,y,_) = y | |
third (_,_,z) = z | |
filterFirst p x = p (first x) | |
filterSecond p x = p (second x) | |
filterThird p x = p (third x) | |
exists :: Int -> (a -> Bool) -> [(a,a,a)] -> [(a,a,a)] | |
exists 0 p xs = filter (filterFirst p) xs |
This file contains 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
-- Outputs the number of strings of length six with the digits 0-9 with only two numbers used | |
-- (e.a. "100110", "611661", "899889") in 119 characters of Haskell. Enjoy! | |
import Data.List | |
z x|length x<6=z("0"++x)|length x==6=x | |
main=print$length$filter((==2).length)$map(nub.z.show)[0..999999] |
This file contains 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 ViewPatterns #-} | |
module Main where | |
import Data.Ratio | |
-- Runs the euclidian algorithm, returning the GCD along with a list of quotients, | |
-- or equivantley, a continued fraction representation of a/b in list form | |
euclidGCD :: (Integral a) => a -> a -> (a,[a]) | |
euclidGCD a b = go a b [] |
This file contains 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
-- Saw a (joke?) stack exchange post about an extensible fizzbuzz implementation. | |
-- I was bored, so I thought I'd give my take on something similar in Haskell: | |
import qualified Data.Map.Strict as M | |
import Control.Monad (join) | |
fizzBuzz :: M.Map Int String -> Int -> String -> [String] | |
fizzBuzz dict n default_value = map (toWords . divisors) [1..n] | |
where keys = M.keys dict | |
divisors n = filter (\x -> (n `mod` x) == 0) keys |
This file contains 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
# Visual single variable normality test plot | |
# Useful for testing normality assumptions in DOX. | |
normTest <- function(data){ | |
n <- length(data) | |
expected <- pnorm((1:n)/(n+1)) | |
plot(x=expected,y=sort(data),xlab="Expected Norm. Dist.",ylab="Data") | |
} |
This file contains 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
-- Long binary division algorithm, used for the CSCI 342 final project (floating point emulation). | |
-- Pro tip: Apparently integer division works just as well as this if you do some bit shifting. | |
longBinaryDivision :: Integer -> Integer -> [Bool] | |
longBinaryDivision num denom = go (createDivadend num) denom num 0 | |
where go :: [Bool] -> Word32 -> Word32 -> Int -> [Bool] | |
go divadend divisor remainder count | |
| divisor == remainder = [True] | |
| divisor < remainder = [True] ++ go (tail divadend) divisor (carryDown (remainder - divisor)) (count +1) | |
| divisor > remainder = [False] ++ go (tail divadend) divisor (carryDown remainder) (count +1) |
This file contains 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
-- Linear correlation stuff for MATH 211, yay? | |
-- An error, but a bit more condescending than usual. | |
(ಠ_ಠ) x = error ("ಠ_ಠ "++x++" ಠ_ಠ") | |
ccoeff :: [Double] -> [Double] -> Double | |
ccoeff xs ys = (n*xyΣ - xΣ*yΣ)/((n*x²Σ - xΣ**2.0)*(n*y²Σ-yΣ**2.0))**0.5 | |
where xΣ = sum xs | |
yΣ = sum ys | |
xyΣ = sum $ zipWith (*) xs ys |
This file contains 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
-- Simple time module, no fuss over real world complications, just a simple way | |
-- to calculate sums and differenes of hours and minutes on a 12 hour | |
-- clock using divs and mods. | |
module SimpleTime where | |
-- Time in a simple hour:minute format | |
data Time = Time Int Int | |
-- Helper function to display times correctly |
This file contains 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
-- | |
-- An implementation of the Calkin-Wilf sequence in Haskell -- gives a bijection between the natural numbers | |
-- and the (positive) rationals. | |
-- | |
-- See https://en.wikipedia.org/wiki/Calkin%E2%80%93Wilf_tree for more info | |
-- | |
import Data.Ratio | |
calkinWilfNext q = 1 / (2 * ( (floor q) % 1 ) - q + 1) |
OlderNewer