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 <atomic> | |
#include <functional> | |
#include <iostream> | |
#include <unistd.h> | |
#include <type_traits> | |
#include <sys/eventfd.h> | |
#include <cstdarg> | |
using namespace std; |
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
template<int T> | |
constexpr int powVal = powVal<T/2> + 1; | |
template<> | |
constexpr int powVal<0> = 0; | |
template<> | |
constexpr int powVal<1> = 0; | |
template<typename... Ts> | |
struct TList; |
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 MultiParamTypeClasses #-} | |
data State s a = State (s -> (a, s)) | |
instance Functor (State s) where | |
fmap f (State g) = State $ \s -> case g s of | |
(a, s') -> (f a, s') | |
instance Monad (State s) where |
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
atoi :: String -> Integer | |
atoi = uncurry (*) . ((bool 1 (-1) . (=="-")) *** foldl (\v x -> v*10 + ord x - 48) 0) . break isDigit |
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 TypeFamilies, MultiParamTypeClasses, NoMonomorphismRestriction, FlexibleInstances, FlexibleContexts #-} | |
class First a where | |
ret :: a | |
instance First (a -> a) where | |
ret = id | |
instance First (r -> y) => First (r -> x -> y) where | |
ret r _ = ret r |
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
module Tmp where | |
import Data.Monoid | |
import Control.Monad | |
import Data.Char | |
import Control.Applicative | |
import Control.Lens | |
initMap :: [(Char, (Int, Int))] | |
initMap = ('0', (1, 3)) : zip (map (chr . (ord '0' +)) [1..9]) (flip (,) <$> [0..2] <*> [0..2]) |
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
replaceWithMax :: [Int] -> [Int] | |
replaceWithMax l = ans | |
where | |
(ans, maximum) = f (l, head l) | |
f (l:ls, m) = Control.Arrow.first (maximum:) $ f (ls, max m l) | |
f x = x | |
relabel :: Tree Int -> Tree Int | |
relabel t = ans |
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
type Zip' m a = m (Seq a, a, Seq a, Producer a m ()) | |
type Zip a = Zip' Identity a | |
forward :: Monad m => Zip' m a -> Zip' m a | |
forward m = do | |
(s, a, s', p) <- m | |
case viewl s' of | |
EmptyL -> next p >>= \x -> case x of | |
Left _ -> error "Stream dried up" |
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
//things to do- have to increase the size of the compressed array.. | |
//too much compression doesn't allow for distinction between similar characters. | |
//to isolate characters on a line we must form | |
//lets get this straight- | |
// | |
import java.io.*; | |
import javax.imageio.ImageIO; | |
import java.awt.image.BufferedImage; | |
public class OCR{ |