Sunday, December 13, 2009

Some algo fun

Well, I was trying to figure if a user could be given a pass code of length 40, and split in pieces for ease, I ended up dealing with numbers and so many calculations, that I finally made an algorithm and wrote it down in JS. The code is as follows:
//uses Firefox Firebug
console.clear();

var n = 1;

var s = 1202;

var m = 1;

while((s-n)/(n+1) >= 1 && n <= m) {

m = (s-n)/(n+1);

console.log('dashes = '+n);

console.log('chunksize = '+m);

console.log('----');

n++;

}

Some results to consider:

String Length

Number of dashes

Split length

3

1

1

40

0

0

41

5

6

No comments: