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<std::size_t Cols, std::size_t Rows> | |
class bitboard { | |
private: | |
std::bitset<Cols * Rows> _bitset; | |
public: | |
using reference = std::bitboard<Cols, Rows><Cols * Rows>::reference; | |
reference operator()(std::size_t, std::size_t); | |
bitboard<Cols, Rows>& operator&=(const bitboard<Cols, Rows>&); | |
bitboard<Cols, Rows>& operator|=(const bitboard<Cols, Rows>&); |
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 <numeric> | |
namespace std { | |
template<class T, std::size_t N, std::size_t M> | |
T* begin(T (&array)[N][M]) { | |
return &array[0][0]; | |
} | |
template<class T, std::size_t N, std::size_t M> |
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.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 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
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 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
#pragma once | |
#include <exception> | |
#include <memory> | |
#include <typeinfo> | |
#include <type_traits> | |
class any; | |
template<class Type> Type any_cast(any&); |
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
#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 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
#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 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
#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 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.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 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 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) = |
OlderNewer