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
| #include <vector> | |
| #include <iostream> | |
| #include <string> | |
| #include <algorithm> | |
| unsigned int sharedPrefixLength(const char *a, const char *b); | |
| std::string longestRepeatedString(const std::string s); | |
| int main() | |
| { |
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
| require 'formula' | |
| class Prettyping < ScriptFileFormula | |
| homepage 'https://bitbucket.org/denilsonsa/small_scripts/overview' | |
| url 'https://bitbucket.org/denilsonsa/small_scripts/raw/130bc1a6162fc14629cfd1cd30355d586cc38f5f/prettyping.sh' | |
| sha1 '748ce4a5cfd098f728de1c4c374949a82302dcf1' | |
| version '130bc1a' | |
| def install | |
| mv "prettyping.sh", "prettyping" |
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
| template <class T> struct Maybe { virtual ~Maybe() {}; }; | |
| template <class T> struct Nothing : public Maybe<T> {}; | |
| template <class T> struct Just : public Maybe<T> { Just(T v) : v(v) {} T v; }; | |
| template <class T> | |
| T fromMaybe(const Maybe<T>& maybeVal, const T& defaultVal) | |
| { | |
| if (const Just<T>* j = dynamic_cast<const Just<T>*>(&maybeVal)) { | |
| return j->v; | |
| } |
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 Prelude hiding (lookup) | |
| import Data.IORef | |
| import Data.Maybe | |
| type NatArray a = IORef (Int -> Maybe a) | |
| newArray :: IO (NatArray a) | |
| newArray = newIORef (const Nothing) | |
| lookup :: NatArray a -> Int -> IO (Maybe a) |
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.IORef | |
| f ref = writeIORef ref 2 | |
| main = do | |
| putStrLn "Look! Mutation!" | |
| myRef <- newIORef 1 | |
| v <- readIORef myRef | |
| (putStrLn . show) v | |
| f myRef |
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
| mk_assert pred_fn (expected, actual, formatter) = | |
| if pred_fn (expected, actual) | |
| then "Test passed" | |
| else "Expected '" ++ formatter expected ++ "' but got '" ++ formatter actual ++ "'" | |
| assert_equals = mk_assert (uncurry (==)) | |
| pass2 = assert_equals(42, 42, show) | |
| fail2 = assert_equals(1, 2, show) |
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
| data Set a = S { insert :: a -> Set a | |
| , member :: a -> Bool | |
| , size :: Int | |
| } | |
| emptySet = let insert xs n = makeSet (if n `elem` xs then xs else n : xs) | |
| member xs n = n `elem` xs | |
| size = length | |
| makeSet xs = S (insert xs) (member xs) (size xs) | |
| in makeSet [] |
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 Data.ByteString (ByteString) | |
| import qualified Data.ByteString.Char8 as B | |
| import Data.Enumerator (Iteratee, Enumeratee, ($=), (=$), (=$=), (==<<)) | |
| import qualified Data.Enumerator as E | |
| import qualified Data.Enumerator.Binary as EB | |
| import qualified Data.Enumerator.Text as ET | |
| import qualified Data.Enumerator.List as EL | |
| import Data.Text |
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.Vector (Vector (..), (!), (//)) | |
| import qualified Data.Vector as V | |
| import Data.List (sort) | |
| import Test.QuickCheck | |
| -- partition the given array using 3-way partitioning | |
| partition :: (Ord a) => Int -> Int -> Vector a -> (Vector a,Int,Int) | |
| partition lo hi a = partition' lo lo hi a | |
| where partition' i lt gt a | |
| | i > gt = (a,lt,gt) |
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 hiding (length) | |
| import Data.Text | |
| -- Calculates LCS of two strings without using a backtrack matrix. The helper | |
| -- function lcs' does the actual work. | |
| lcs :: Text -> Text -> Text | |
| lcs s1 s2 = lcs' "" (length s1,length s2) s1 s2 | |
| where lcs' acc (x,y) s1 s2 |