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
#include <cstdlib> | |
#include <type_traits> | |
using std::enable_if; | |
using std::size_t; | |
//////////////////////////////////////////////////////////////////////////////// | |
// Utility | |
//////////////////////////////////////////////////////////////////////////////// |
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 RankNTypes #-} | |
module List where | |
import Control.Applicative (Applicative, pure, (<*>), (<$>)) | |
import Data.Foldable (Foldable, foldr) | |
import Data.Traversable (Traversable, traverse) | |
import Prelude hiding (foldr) | |
newtype ListC a = | |
ListC { |
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
data AbstractInteger = Zero | Succ AbstractInteger | Pred AbstractInteger | |
deriving (Eq, Show) | |
instance Ord AbstractInteger where | |
-- compare :: AbstractInteger -> AbstractInteger -> Ordering | |
compare (Pred x) (Pred y) = compare x y | |
compare (Pred _) Zero = LT | |
compare (Pred _) (Succ _) = LT | |
compare Zero (Pred _) = GT | |
compare Zero Zero = EQ |
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
-- | |
-- lab2.hs | |
-- | |
-- Sum a list of integers recursively. | |
sumIntegers1 :: [Integer] -> Integer | |
sumIntegers1 (x:xs) = x + sumIntegers1 xs | |
sumIntegers1 [] = 0 | |
-- Sum a list of integers in terms of foldl. |
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
add_and_double :: Double -> Double -> Double | |
add_and_double x y = (x + y) * 2 | |
(+*) :: Double -> Double -> Double | |
(+*) x y = x `add_and_double` y | |
solve_quadratic_equation :: Double -> Double -> Double -> (Double, Double) | |
solve_quadratic_equation a b c = (x1, x2) | |
where disc = sqrt (b ** 2 - 4 * a * c) | |
x1 = (disc - b) / (2 * a) |
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
from collections import deque | |
def has_universal_sink (A): | |
V = len(A) | |
if not V: | |
return False | |
Q = deque(xrange(V)) | |
while len(Q) > 1: | |
u = Q.popleft() | |
v = Q.popleft() |