How to use the @mathigon/core.repeat function in @mathigon/core

To help you get started, we’ve selected a few @mathigon/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathigon / boost.js / src / templates.ts View on Github external
      names = ALPHABETH.split('').map(x => repeat('_', n) + x);
    }
github mathigon / fermat.js / src / cryptography.ts View on Github external
export function cipherLetterFreq(cipher: string) {
  let msg = cipher.toLowerCase();
  let freq = repeat(0, 26);

  for (let l of msg) {
    if (l >= 'a' && l <= 'z') freq[LOWER_CASE.indexOf(l)] += 1;
  }

  return freq;
}
github mathigon / textbooks / content / graph-theory / components / geometry.ts View on Github external
export function graphColouring(adjMatrix: number[][]) {
  let colours = repeat(0, adjMatrix.length);
  let result = colourMe(adjMatrix, colours, 0);
  return result ? colours : undefined;
}
github mathigon / fermat.js / src / random.ts View on Github external
export function smart(n: number, id: string) {
    if (!id) id = uid();
    if (!SMART_RANDOM_CACHE.has(id)) SMART_RANDOM_CACHE.set(id, repeat(1, n));

    const cache = SMART_RANDOM_CACHE.get(id)!;
    const x = weighted(cache.map(x => x * x));

    cache[x] -= 1;
    if (cache[x] <= 0) SMART_RANDOM_CACHE.set(id, cache.map(x => x + 1));

    return x;
  }
github mathigon / textbooks / content / probability / functions.ts View on Github external
$step.model.set('probTable', (d: number) => {
    let pmax = probabilities[d][Math.round(7 * d / 2)];
    let keys = list(d, d * 6);

    let row1 = keys.map(i =&gt; `<div class="pBox">
      <div id="dc2${i}" class="diceCount"></div>
      <div style="bottom: ${probabilities[d][i] / pmax * 95}%" class="diceProb">
    </div></div>`);

    let row2 = keys.map(i =&gt; `<span class="dice">${i}</span>`);
    let row3 = keys.map(i =&gt; probabilities[d][i]);
    let row4 = keys.map(i =&gt; `<span id="dc1${i}" class="m-blue">0</span>`);

    scores = repeat(0, 60);
    return table([row1, row2, row3, row4]);
  });