Skip to content

Instantly share code, notes, and snippets.

View mingyang91's full-sized avatar
🎯
Go for broke

Ming Yang mingyang91

🎯
Go for broke
View GitHub Profile
@mingyang91
mingyang91 / miller-rabin.scm
Last active November 28, 2015 17:49
米勒-拉宾素性检验
#lang scheme
(define (square x) (* x x))
(define (gcd a b)
(if (= 0 b)
a
(gcd b (remainder a b))))
(define (expmod base exp m)
(cond ((= exp 0) 1)
@mingyang91
mingyang91 / Polynomial expansion.js
Created October 8, 2015 08:07
多项式展开(计算母函数系数)
/**
* 多项式相乘 [多项式1, 多项式2, 多项式3...]
* 多项式 {次数1: 系数1, 次数2: 系数2, ...}
*/
var simplePolynomials = [
{
0: 1,
1: 1,
2: 1,
3: 1,
@mingyang91
mingyang91 / Lexicographic order.js
Last active September 30, 2015 07:51
next函数为求str字典序的下一项,lexicographic函数为求str字典序的第n项
"use strict";
function next (str) {
const charArr = str.split('');
const charReverseArr = charArr.reverse();
const inflectionIndex = charReverseArr.findIndex((element, index, array) => element < array[index - 1]);
const right = charReverseArr.slice(0, inflectionIndex);
function testClosures() {
"use strict";
var result = [];
for (var var_index = 0; var_index < 2; var_index++) {
result.push(() => { return var_index; });
}
for (let let_index = 0; let_index < 2; let_index++) {
result.push(() => { return let_index; });
}