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
// Brute force searching algorithm | |
// I rewrite it into a *C code* with some comments for beginners | |
// Originally from https://gist.github.com/autekroy/bc5ea2c82fb74a5bb2b5 | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
long long ans; | |
int visit[101], check[500]; |
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
# Genetics Algorithm's Implementation in Python | |
# How did this algorithm work? | |
# init -> iterate until certain condition -> output every generation | |
# iterate: select parents -> crossover -> mutation -> a new generation | |
# | |
# Core: How to encode your optimization problem into a string, i.e. chromosome? | |
# Which selection method would your apply? Tournament selection or roulette selection? | |
# How to realize the child breeding? Every pair of parent will breed a pair of children, which are the outcome of crossover effect. |
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
Running instance: | |
Population Size: 200 | |
Crossover Threshold Probability: 0.5 | |
Mutation Threshold Probability: 0.2 | |
============= | |
35 | |
[-254, -260, -284, -213, -174, -130, -103, -102, -102, -106, -80, -75, -61, -53, -50, -55, -48, -41, -49, -51, -30, -31, -25, -25, -14, -23, -8, -19, -17, -8, -9, -8, -19, -11, 0] | |
Running instance: |
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
-- autoconf parser | |
module AutoParser where | |
import Data.List.Extra (splitOn) | |
import qualified Data.Map as M | |
isComment ('#':_) = True | |
isComment _ = False | |
isBlank = all (`elem` " \n\t\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
{-# LANGUAGE TemplateHaskell #-} | |
import MultiPlateDerive | |
import Data.Generics.Multiplate | |
import Data.Functor.Constant | |
data Expr = Con Int | |
| Add Expr Expr | |
| Mul Expr Expr | |
| EVar Var |
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
use self::GcCell::*; | |
use self::Action::*; | |
use std::marker; | |
#[derive(Clone)] | |
enum GcCell<T: Trace + ?Sized + Clone> { | |
Data(T), | |
Forward(*mut GcCell<T>), | |
} |
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 | |
import Data.List (partition) | |
-- Definitions | |
data Pattern = PVar Variable | PCon Constructor [Pattern] | |
newtype Constructor = Constructor { unConstructor :: String } deriving (Eq, Show) | |
newtype Variable = Variable { unVariable :: String } 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
data Expr = EApp Expr Expr | |
| EAbs String Expr | |
| EVar String | |
| EInt Int | |
deriving (Show) | |
-- (λx.x x) (λx.x x) | |
unterminating = EApp (EAbs "x" (EApp (EVar "x") (EVar "x"))) (EAbs "x" (EApp (EVar "x") (EVar "x"))) |
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 Bucket k v = [(v, [k])] | |
insert :: k -> v -> Bucket k v -> Bucket k v | |
insert k v bucket@((v0, ks):bucket') | |
| v == v0 = (v0, k:ks) : bucket' | |
| v < v0 = (v, k:[]) : bucket | |
| otherwise = (v0, ks) : insert k v bucket' | |
query :: k -> k -> Int -> Bucket k v -> [v] | |
query k1 k2 n bucket@((v0, ks):bucket') = |
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
trait Hash { | |
fn hash(&self) -> u64; | |
} | |
impl Hash for bool { | |
fn hash(&self) -> u64 { | |
if *self { 0 } else { 1 } | |
} | |
} |
OlderNewer