-
-
Save quant61/615e7f5648a36e68a41d3f91602ef424 to your computer and use it in GitHub Desktop.
PublicGist0
This file contains hidden or 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
some esoteric ES6 functions | |
var getDiagonalMatrix = N=>Array(N).fill(0).map((x,i)=>Array(N).fill(i).map((x,j)=>i==j?1:0)); | |
var getNDArray = (N, x)=>N.length?(Array(N[0]).fill(0).map(()=>arr(N.slice(1),x))):x; | |
var toBase = (x,n,r=[])=>x ? toBase(Math.trunc(x/n), n, [ x%n, ...r]):r; | |
........... | |
check performance of any language/algo/something else | |
begin = getTime() | |
data = initData() | |
for i = 0..(2**30) | |
data = doTheWork(data); // optional, looping itself takes some time too | |
if(!(i & (i-1) )) // i is power of 2 | |
dump(i, data, getTime() - begin) | |
[i,x, pi, parts] = [1,1, Math.PI, []]; | |
while(i<100){ | |
let n = Math.floor(x / pi**(-i)); | |
x -= n / pi**i; | |
if(n > 3) break; | |
if(n) parts.push(`${n}\\cdot\\pi^{-${i}}`); | |
i++; | |
} | |
console.log(`1=${parts.join('+')}`) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment