Skip to content

Instantly share code, notes, and snippets.

@myfonj
Created August 29, 2024 16:24
Show Gist options
  • Save myfonj/8003c60590cd43da9761a20078200349 to your computer and use it in GitHub Desktop.
Save myfonj/8003c60590cd43da9761a20078200349 to your computer and use it in GitHub Desktop.
(()=>{
const l = 26 // lower
const u = 26 // upper
const d = 10 // digits
const length = 8 // size
const possible = (l + u + d)**length
const invalid =
(l + d)**length // missing upper
+ (u + d)**length // missing lower
+ (u + l)**length // missing digit
+ (l)**length // missing digit and upper
+ (u)**length // missing digit and lower
+ (d)**length // missing upper and lower
const valid = possible - invalid
const f = (new Intl.NumberFormat).format
console.table({
'Possible': f(possible),
'Invalid': f(invalid),
'Valid': f(valid),
'Valid / possible': valid / possible,
'Invalid = possible %': (invalid / possible) * 100 + '%'
})
// https://x.com/BrettLudwig/status/1829071105031852220
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment