Skip to content

Instantly share code, notes, and snippets.

@Krinkle
Krinkle / 01-parkers-number-of-feb2014.js
Created April 18, 2019 01:18
3435 – The sum of each digit raised to the power of itself.
const MAX = 100 * 1000 * 1000; // 100 million
function powself(number) {
if (number === 0) {
return NaN; // matt does not like zero.
} else {
return Math.pow(number, number);
}
}
/*! Requires Node 12.5+ | License: Public domain. */
const cluster = require('cluster');
const WORK_TOTAL = 10_000_000;
const WORK_MILESTONE = 1_000_000;
const WORK_ASSIGN_CHUNK = 100_000;
const WORK_RESP_CHUNK = 1_000;
const ALGO = 'md5';
@Krinkle
Krinkle / perfect-numbers.js
Last active March 18, 2019 23:16
Distribute exponential task sizes via Node.js cluster workers.
/**
* Requires Node 6.0+
*
* Author: Timo Tijhof (2018).
* License: Public domain.
*/
const cluster = require('cluster');
let pidLabel = cluster.isMaster ? 'master' : 'worker';
@Krinkle
Krinkle / cost.js
Last active September 28, 2018 20:17
/**
* https://tfl.gov.uk/corporate/terms-and-conditions/tfl-call-charges
*
* > The rate is 0.66p per minute.
* > There is also a 40p connection charge.
* > Call charges are rounded up to the nearest 10p, with a minimum charge of 60p.
*
* @param {number} seconds
* @return {string} Cost in GBP
*/