You work for the police force as a programmer.

A villain has planted a bomb in the city, luckily the police force has captured both him and the bomb. The bomb is really complicated to disarm, however it has a password input to disarm it.

The villain, being cocky, has told you that there was no way you'd find the password as you'd take X time to brute force it. You notice that the keyboard can only input english letters (lower and upper case) and digits.


Assuming you can try Y passwords per second, and that the brute force character order would be a-z A-Z 0-9, you are to create either a full program or a function that takes as input both X (in seconds) and Y (passwords/second) and outputs the villain's password.

X can be a float but Y will always be an integer.
(X*Y should always be an integer)

Your code has to solve the problem using math instead of relying on trying several options or creating huge arrays and simply indexing them with X*Y.

Example in JS

var c="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var b=62;
function num(x){
    var n=0;
    return n;
function reduce(x, n){
    return x;
function pass(x, y){
    var p=[];
    var n=num(x);
    x = reduce(x, n);
        var t=x%b;
    return ("a".repeat(n)+p.map(f=>c[f]).join``).substr(-n);

Assuming my code is correct here are some example outputs.
(If there are any errors please tell me so that I can correct them)

pass(0.000, 1000); // "" or anything that won't be mistaken for a password
pass(0.001, 1000); // "a"
pass(0.002, 1000); // "b"
pass(0.027, 1000); // "A"

//A password that would take a year to brute force at 1000 passwords/second
pass(3600*24*365, 1000) // "HzmZmr"

My code is awful and ungolfed but it's only to serve as an example. Since this is code-golf shortest answer in bytes wins.

  • 1
    \$\begingroup\$ "You cannot brute force" I'm not quite sure what that implies... does it mean we can't simply generate the next Y passwords each second and then output after X seconds? \$\endgroup\$ Feb 1 '17 at 13:51
  • 1
    \$\begingroup\$ Oh I think I get it... we know that X is the upper bound on time so we take the Y passwords/second and generate Z passwords where Z = XY? Then the Z'th password would be correct? If this is the case, what's the minimum length password that the bomb accepts? \$\endgroup\$
    – Poke
    Feb 1 '17 at 14:20
  • 3
    \$\begingroup\$ @Poke I think we are supposed to output the (X*Y)th string from a, b, c,..., y, z, A, B,...,Y, Z, 0, 1, ..., 8, 9, aa, ab, ac, ad,.... I'm voting to close as unclear until that gets cleared up though. \$\endgroup\$
    – Riley
    Feb 1 '17 at 14:24
  • 2
    \$\begingroup\$ Before posting your challenges, you could post on Sandbox first, there you can receive some feedback to improve your challenge. \$\endgroup\$
    – Rod
    Feb 1 '17 at 17:09
  • 1
    \$\begingroup\$ This still needs an actual specification (making us reverse engineer it from a reference implementation doesn't count), but judging by the answers it would likely be close enough to codegolf.stackexchange.com/q/54105/194 to be closed as a dupe anyway. \$\endgroup\$ Feb 2 '17 at 6:56

Jelly, 9 bytes


Try it online!


×ḃ62ịØWŒs - Main link: X, Y
×         - multiply X by Y
 ḃ62      - convert to bijective base 62 (uses modulo arithmetic under the hood)
    ị     - index into (1-based)
     ØW   - word yield -> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"
       Œs - swap case

Python 2, 121 bytes

while i/62>0:i=i/62-1;p=b[i%62]+p
print p

Try it online!

This basically calculate the x*y in base 62
For a recursive solution at 125 bytes

f=lambda i:(f(i/62)if~-i/62>0else'')+b[i%62-1]
print f(int(x*y)+1)

Try it online!