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
capitalize = (s) -> s.replace /(?:_|^)([a-z])/g, (_, c) -> c.toUpperCase() # 'hello_world' to 'HelloWorld' | |
uncapitalize = (s) -> s.replace /([A-Z])/g, (_, c) -> '_' + c.toLowerCase() # 'HelloWorld' to 'hello_world' | |
is_chinese_char = (c) -> /[\u4E00-\u9FA5\uF900-\uFA2D]/.test c |
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
//c++11 | |
#include <cmath> | |
#include <iostream> | |
#include <map> | |
#include <vector> | |
#include <assert.h> | |
#include <ctime> | |
#include <cstdio> | |
#include <functional> |
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 | |
import Data.Function | |
import Control.Monad | |
groupOn f = groupBy ((==) `on` f) . sortBy (compare `on` f) | |
uniq = map (!! 0) . groupOn id | |
-- 场景:假设a得到了数字x,b得到了数字y | |
-- 可看做二分图,其中possibleX,possibleY是顶点,possible是边,(aGuessY x)和(bGuessX y)分别表达x点和y点的邻接点集 | |
possibleX = [4..198] |
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 | |
import Data.Function | |
import Control.Monad | |
groupOn f = groupBy ((==) `on` f) . sortBy (compare `on` f) | |
uniq = map (!! 0) . groupOn id | |
-- 场景:假设a得到了数字x,b得到了数字y | |
-- 可看做二分图,其中possibleX,possibleY是顶点,possible是边,(aGuessY x)和(bGuessX y)分别表达x点和y点的邻接点集 | |
possible = [(5, 15), (5, 16), (5, 19), (6, 17), (6, 18), (7, 14), (7, 16), (8, 14), (8, 15), (8, 17)] |
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
require 'coffee-mate/global' | |
compareDictOn = (f) -> | |
(da, db) -> | |
[da, db] = [f(da), f(db)] | |
for k, va of da | |
vb = db[k] | |
if (not vb?) or (va < vb) | |
return -1 | |
else if (not va?) or (va > vb) |
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 ForeignFunctionInterface #-} | |
import System.Console.ANSI (clearScreen) | |
import Data.Char | |
import Foreign.C.Types | |
import Prelude hiding (Left, Right) | |
import GHC.Exts (groupWith, sortWith) | |
import Control.Arrow | |
import System.Random | |
import System.IO | |
import Data.Hashable |
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
isPrime x = all (\p -> x `mod` p /= 0) . takeWhile ((<= x) . (^ 2)) $ primes | |
primes = 2 : 3 : filter isPrime [5..] |
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 BinarySearch(binarySearch, discreteBinarySearch, continuousBinarySearch) where | |
binarySearch :: ((a -> a -> Bool), (a -> a -> a)) -> (a, a) -> (a -> Bool) -> Maybe a | |
binarySearch (closeEnough, mid) (x0, x1) f = if y0 == y1 then Nothing else Just (iter x0 x1 y0 y1) where | |
(y0, y1) = (f x0, f x1) | |
iter x0 x1 y0 y1 = if closeEnough x0 x1 | |
then (if y0 then x0 else x1) | |
else | |
let | |
xm = mid x0 x1 |
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 NoMonomorphismRestriction #-} | |
import Control.Monad | |
import Test.QuickCheck hiding (scale) | |
import Codec.BMP | |
import qualified Data.ByteString | |
import Data.Word | |
--------------------- Point & Vec etc ---------------------- | |
type Scalar = Double |
OlderNewer