Created
November 7, 2019 23:06
-
-
Save tomasdev/58326fbfc58a1554d04bee8797be5c08 to your computer and use it in GitHub Desktop.
poorly performance pandigital fractions
This file contains 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
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