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
from itertools import product | |
from functools import reduce | |
class Number(): | |
def __init__(self): | |
self.num = 0 | |
def succ(self): | |
self.num += 1 | |
return self |
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
const Promise = require('bluebird') | |
const bcrypt = require('bcrypt') | |
const jwt = require('jsonwebtoken') | |
const passport = require('passport') | |
const passportJWT = require('passport-jwt') | |
const LocalStrategy = require('passport-local').Strategy | |
const JWTStrategy = passportJWT.Strategy | |
const extractJWT = passportJWT.ExtractJwt |
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
const _ = require('lodash') | |
const fs = require('fs') | |
fs.readFile('./sbgy.xml', 'utf-8', (err, data) => { | |
const info = data.match(/(onyomi=\u0022([^\u0022]+)\u0022|\u003Cword_head id=\u0022[^\u0022]+\u0022\u003E[^\u003C]+\u003Cnote\u003E)/ug); | |
const slice_point = _.concat([0], _.chain(info).map( (r, i) => (/onyomi/u.test(r)) ? i : undefined ).compact().value(), info.length); | |
const chunks = _.map(_.zip(_.initial(slice_point), _.tail(slice_point)), ([L, R]) => _.slice(info, L, R)); | |
const result = _.chain(chunks).map(c => { | |
const onyomi = _.head(c).match(/onyomi=\u0022([^\u0022]+)\u0022/u)[1] | |
const rhymes = _.chain(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
import Data.Hashable | |
import Data.HashSet | |
-- Amortised linear-time by hashing | |
uniqhs :: (Hashable a, Eq a) => HashSet a -> [a] -> [a] | |
uniqhs _ [] = [] | |
uniqhs h (x:xs) = if member x h then uniqhs h xs else x:uniqhs (insert x h) xs | |
nub :: [Int] -> [Int] | |
nub = uniqhs empty |
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 | |
import Data.Char | |
lst2Tup :: [a] -> (a, a) | |
lst2Tup [x, y] = (x, y) | |
judge :: Char -> Bool | |
judge x = if x == '+' then True else False | |
-- O(n) time, O(n) space |
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 GenFunc = [Double] |
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
solve :: (Int, [String]) -> Double | |
solve (h, ss) = foldr1 max $ map (possible . pattern) ss | |
where possible [x, y, z] = sum $ drop (h - z) (gfTable !! x !! y) |
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
table :: [Int] | |
table = [0 .. 20] | |
gfTable :: [[GenFunc]] | |
gfTable = map (\f -> f <$> gfDice <$> table) (gfExp <$> table) |
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
gfProd :: [GenFunc] -> GenFunc | |
gfProd = foldr1 gfMul | |
gfExp :: Int -> GenFunc -> GenFunc | |
gfExp n = gfProd . replicate n |
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
gfMul :: GenFunc -> GenFunc -> GenFunc | |
gfMul xs ys = foldr1 (zipWith (+)) . map f . zip [0..] $ ys | |
where | |
len = sum (minus 1 . length <$> [xs, ys]) + 1 | |
f (x, d) = gfPad x len (map (* d) xs) |
NewerOlder