Skip to content

Instantly share code, notes, and snippets.

View butchi's full-sized avatar

IWABUCHI Yu(u)ki (butchi) butchi

View GitHub Profile
@butchi
butchi / prime-daifugo-utility.nb
Created December 5, 2018 08:45
素数大富豪研究のためのMathematicaユーティリティー関数 https://qiita.com/butchi_y/items/ce0fde84495c76197a49
superscript[a_, b_] := If[b == 1, a, Superscript[a, b]]
centerDot[li_] := If[Length[li] == 1, First[li], CenterDot @@ li]
j[n_] := If[PrimeQ[n], ToString[PrimePi[n]] <> "番目の素数",
centerDot[superscript @@@ FactorInteger[n]]]
divisible[check_Integer, OptionsPattern[origin -> True]] :=
Divisible[#, check] && If[OptionValue[origin], True, # != check] &
divisible[checkLi_List, OptionsPattern[origin -> True]] :=
AnyTrue[Table[divisible[check, origin -> OptionValue[origin]][#], {check, checkLi}], TrueQ] &
@butchi
butchi / dot.js
Created September 4, 2017 19:41
Inner product by JavaScript (ES2015)
function dot(a, b) {
const len = Math.max(a.length, a.length);
let zeros = new Array(len).fill(0);
let ret;
ret = zeros.reduce((p, c, i) => {
const itemA = a[i] || 0;
const itemB = b[i] || 0;
@butchi
butchi / fibonacci_word_sequence_definition.js
Created August 24, 2017 22:51
フィボナッチ列の計算
const s = [];
s[0] = '0';
s[1] = '01';
function fibonacci_word(n) {
let ret;
if (n < 2) {
ret = s[n];
@butchi
butchi / file0.txt
Created July 20, 2017 21:40
MarkdownでURLを自動リンクしない(+ RFC 7763を詳しく調べてみた) ref: http://qiita.com/butchi_y/items/1edea5f14f23d5a22911
markdown http リンクにしない
const b = 4;
const p = 1 << b;
const r = new Uint32Array(p);
let i = 0;
let j = 0;
while(i < p){
r[i] = j;
k = - p ^ (-p / ((i ^ (i + 1)) + 1));
j ^= k;
i++;
@butchi
butchi / file0.js
Last active March 23, 2017 09:38
必ず元の場所に戻るランダムウォークのサンプル ref: http://qiita.com/butchi_y/items/b1b2a2cd5d9fc81a746e
const LENGTH = 25; // 25×2の50回ランダムウォークする
const MAGNITUDE = 10; // 振動ピクセル幅
// 入力した正の数を正負両方含む配列(倍のサイズ)として返す
function double(arr) {
let ret = [];
arr.forEach((num) => {
ret.push(num);
ret.push(-num);
@butchi
butchi / common.css
Last active February 21, 2017 01:54
はてブボタンが黒背景でダサい問題を解決する ref: http://qiita.com/butchi_y/items/ee39b4e12f16a8d4f834
.hatena-bookmark-button-frame {
border-radius: 4px;
}
@butchi
butchi / quadratic-formula
Last active February 3, 2017 12:33
MathML簡略化案
# https://ja.wikipedia.org/wiki/Mathematical_Markup_Language
```replace-list--math-ml
replace mrow(/(.+)/) -> ($1)
replace mfrac(/(.+) (.+)/) -> ($1 / $2)
replace msup(/(.+) (.+)/) -> ($1 ^ $2)
replace msqrt(/(.+)/) -> √($1)
replace mi(/([a-z]+)/) -> $1
replace mn(([1-9][0-9]*)) -> $1
replace mo(=) -> =
@butchi
butchi / AnimKanpai.js
Last active December 19, 2016 09:07
実践!Animate CCを使ったWebサイト演出 ref: http://qiita.com/butchi_y/items/fb62522e64812213c2a5
// timeline functions:
this.frame_19 = function() {
$(canvas).trigger('end-anim');
stop();
}
@butchi
butchi / file0.txt
Created December 5, 2016 16:38
Mathematicaで使う記号あれこれ ref: http://qiita.com/butchi_y/items/1d13c18cc195f0e9cf36
In[1]:= Map[f, {a, b, c, d, e}]
Out[1]= {f[a], f[b], f[c], f[d], f[e]}