Skip to content

Instantly share code, notes, and snippets.

@tomasdev
Created November 7, 2019 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomasdev/58326fbfc58a1554d04bee8797be5c08 to your computer and use it in GitHub Desktop.
Save tomasdev/58326fbfc58a1554d04bee8797be5c08 to your computer and use it in GitHub Desktop.
poorly performance pandigital fractions
var unique = n => Array.from(new Set((n+'').split(''))).length === (n+'').length
var possibilities1 = []
var possibilities2 = []
var combos = []
for (var i = 1234; i < 9876; i++) {
if (!(i+'').includes('0') && unique(i)) possibilities1.push(i)
}
for (var i = 12345; i < 98765; i++) {
if (!(i+'').includes('0') && unique(i)) possibilities2.push(i)
}
for (var i = 0; i < possibilities1.length; i++) {
for (var j = 0; j < possibilities2.length; j++) {
if (unique(possibilities1[i]+''+possibilities2[j]))
combos.push([possibilities1[i],possibilities2[j]])
}
}
var results = { "1/2": [], "1/3": [], "1/4": [] }
for (var i = 0; i < combos.length; i++) {
var r = combos[i][0]/combos[i][1];
if (r == 1/2) results["1/2"].push(combos[i][0]+"/"+combos[i][1])
if (r == 1/3) results["1/3"].push(combos[i][0]+"/"+combos[i][1])
if (r == 1/4) results["1/4"].push(combos[i][0]+"/"+combos[i][1])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment