Created
December 13, 2018 06:32
-
-
Save Announcement/0d7c7049409727d12af9915975b365f2 to your computer and use it in GitHub Desktop.
substr pivot
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
function format_large_number (it) { | |
it = it.toString() | |
while ((/(?<=\d)(\d{3})($|(?=[,\.]))/gim).test(it)) { | |
it = it.replace(/(?<=\d)(\d{3})($|(?=[,\.]))/gim, ',$1') | |
} | |
return it; | |
} | |
function * dd3 (a, b, ax, bx, ay, by, n) { | |
if (ax === null || ax === undefined) ax = 0; | |
if (bx === null || bx === undefined) bx = 0; | |
if (ay === null || ay === undefined) ay = a.length; | |
if (by === null || by === undefined) by = b.length; | |
const as = new Set; | |
const bs = new Set; | |
const cs = new Set; | |
for (let ah = ~~ax; ah <= ay; ah++) | |
for (let ak = -~ah; ak <= ay; ak++) | |
as.add([ ah, ak, a.substring(ah, ak) ]) | |
for (let bh = ~~bx; bh <= by; bh++) | |
for (let bk = -~bh; bk <= by; bk++) | |
bs.add([ bh, bk, b.substring(bh, bk) ]) | |
for (const [ ah, ak, at ] of as) | |
for (const [ bh, bk, bt ] of bs) | |
if (at === bt) cs.add([ bk - bh, ah, bh, at]) | |
const f = x => x > 0 ? 2 ** x + f(x - 1) : 1 | |
const y = f(cs.size); | |
let s = y.toString(); | |
s = format_large_number(s) | |
console.log(cs) | |
console.log(`Array of ${cs.size} has ${s} possibilities.`) | |
let i = 0; | |
let previous = 0; | |
let time = Date.now(); | |
for (const unique_combination of unique_combinations(...cs)) { | |
i++; | |
const percent = Math.floor(i / y * 100) | |
if (percent > previous) { | |
const now = Date.now() | |
const elapsed = now - time; | |
const estimate = elapsed * y / i; | |
const remaining = estimate - elapsed; | |
const remaining_milliseconds = Math.floor(remaining) % 1000; | |
const remaining_seconds = Math.floor(remaining / 1000) % 60; | |
const remaining_minutes = Math.floor(remaining / 1000 / 60) % 60; | |
const remaining_hours = Math.floor(remaining / 1000 / 60 / 60) % 24; | |
const remaining_days = Math.floor(remaining / 1000 / 60 / 60 / 24); | |
const remaining_object = { days: remaining_days, hours: remaining_hours, minutes: remaining_minutes, seconds: remaining_seconds, milliseconds: remaining_milliseconds }; | |
const object = Object.entries(remaining_object).filter(it => it[1] !== 0).reduce((object, [ key, value ]) => { object[key] = value; return object; }, {}) | |
const array = [ | |
object.days > 1 ? `${ object.days.toString().padStart(2) } days` : object.days === 1 ? ' 1 day ' : '', | |
object.hours > 1 ? `${ object.hours.toString().padStart(2) } hours` : object.hours === 1 ? ' 1 hour ' : '', | |
object.minutes > 1 ? `${ object.minutes.toString().padStart(2) } minutes` : object.minutes === 1 ? ' 1 minute ' : '', | |
object.seconds > 1 ? `${ object.seconds.toString().padStart(2, '0') } seconds` : object.seconds === 1 ? ' 1 second ' : '', | |
object.milliseconds > 1 ? `${ object.milliseconds.toString().padStart(3, '0') } milliseconds` : object.milliseconds === 1 ? '001 millisecond ' : ''] | |
previous = percent; | |
console.log(`${percent.toString().padStart(3)}%`, format_large_number(i).toString().padStart(Math.log10(y) + 1 + Math.floor(Math.log10(y) / 3)), ...array); } | |
} | |
} | |
const a = 'cheeseburger'; | |
const b = 'whataburger'; | |
const solutions = new Map; | |
for (const c of dd3(a, b, 0, 0, a.length, b.length, 0)) //console.log(c.map(d => [ a.substr(d[1], d[0]), b.substr(d[2], d[0])])) | |
{ | |
console.log(...c) | |
} | |
function * unique_combinations (...them) { | |
for (let h = 0; h < them.length; h++) { | |
yield [ them[h] ] | |
if (them.length - h > 1) | |
for (const $ of unique_combinations(...them.slice(h + 1))) { | |
yield [ them[h], ...$ ] | |
} | |
} | |
} |
Author
Announcement
commented
Dec 13, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment