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
import Data.Char | |
char2Int :: Char -> Int | |
char2Int l = ord l - ord 'a' | |
int2Char :: Int -> Char | |
int2Char i = chr (ord 'a' + i) | |
charAdvance :: Int -> Char -> Char | |
charAdvance i c | isLower c = int2Char (((char2Int c) + i) `mod` 26) |
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
makeString :: Char -> Int -> String | |
makeString _ 0 = [] | |
makeString c i = c : (makeString c (i - 1)) | |
putStringsLn :: [String] -> IO () | |
putStringsLn [] = return () | |
putStringsLn (s : ss) = do | |
putStrLn s | |
putStringsLn ss | |
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
#pragma once | |
#include <algorithm> | |
template<typename IT> | |
void bubble_sort(IT begin, IT end) { | |
while (true) { | |
bool c = false; // changed? | |
for (IT i = begin; i != end-1; i = i+1) { | |
if (*i > *(i+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
#pragma once | |
#include <algorithm> | |
template <typename IT> | |
void insertion_sort(IT begin, IT end) { | |
for (IT i = begin; i != end; ++i) { | |
for (IT j = i; j != begin; --j) { | |
if (*(j-1) > *j) std::iter_swap(j-1, j); | |
else break; |
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
#pragma once | |
#include <algorithm> | |
#include <vector> | |
namespace { | |
template <typename IT> | |
void inner_merge(IT begin, IT middle, IT end) { | |
using Container = std::vector<typename std::iterator_traits<IT>::value_type>; |
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
import Data.List.Split (splitOn) | |
import Control.Monad ((>=>)) | |
newtype Circle = Circle { circleRadius :: Double } deriving (Eq, Show) | |
newtype Paint = Paint { remainingMl :: Double } deriving (Eq, Show) | |
data Ring = Ring { ringRadius :: Double | |
, ringThickness :: Double | |
} deriving (Eq, Show) |
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
import Control.Monad.State | |
data Sequence = Sequence { sequenceChar :: Char | |
, sequenceCount :: Integer } deriving (Eq, Show) | |
-- Without State monad. | |
-- Unused. | |
getNextSequence :: String -> (Sequence, String) | |
getNextSequence (h : []) = (Sequence h 1, []) | |
getNextSequence (h : ss) = |
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
import qualified Data.Set as Set | |
import System.Random (randomRIO) | |
import Control.Monad (return) | |
type Numbers = Set.Set Int | |
draw :: Int -> Numbers -> IO Numbers | |
draw i s = | |
if ((Set.size s) == i) then return s | |
else do |
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 <utility> | |
template<class Func, class... Args> | |
auto apply(Func fn, Args&&... args) { | |
return [&](auto&&... sargs) { | |
return fn | |
( std::forward<decltype(args)>(args)... | |
, std::forward<decltype(sargs)>(sargs)... ); | |
}; | |
} |
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 FlexibleInstances #-} | |
{-# LANGUAGE OverlappingInstances #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
import Data.Map (Map) | |
import Data.List (intersperse) | |
import qualified Data.Map as Map | |
class Renderable a where | |
render :: a -> String |
OlderNewer