Today's problem comes from a thread over on /r/theydidthemath.
The problem goes like this. A user is asked to create a password that is 7 digits where none of the numbers can repeat. In addition to this requirement none of the numbers can be in a direct sequence (6 and 7, 7 and 6, or 9 and 0). Create a program to generate a random password for this bank that fits their rule set.
Comments:
Emre Ozdemir - 10 years, 7 months ago
I'm guessing 7 and 7 or 5 and 5 is allowed. This is my solution in C++.
reply permalink
Opetion - 10 years, 7 months ago
Not that I have solved it. but I don't think your solution will work. you are using only once the random so it might get exactly the same number. and it wont satisfy the " a password that is 7 digits where none of the numbers can repeat. " :)
reply permalink
Emre Ozdemir - 10 years, 7 months ago
Yes, I must have missed that. I also realized I didn't include 0. So this is updated version.
reply permalink
Andreas - 10 years, 7 months ago
first time commenting, hope the formatting works out alright. this is written in scala
reply permalink
Max Burstein - 10 years, 7 months ago
Awesome! Thanks for commenting
reply permalink
duddles - 10 years, 7 months ago
It gives me an error when I try to login... here is my python attempt:
reply permalink
Max Burstein - 10 years, 7 months ago
I think I know what the issue is. I will look in to getting this fixed when I get home later tonight. Sorry for the inconvenience.
reply permalink
Max Burstein - 10 years, 7 months ago
Should be good to go
reply permalink
Ethan Glover - 10 years, 7 months ago
I'm not sure why I'm not getting consistent passwords. I'll run the program 10 times and there's always a couple with either two of the same number or a sequence. Help is appreciated. :) (Java)
reply permalink
Max Burstein - 10 years, 7 months ago
In the first if of the compare function you don't check if the newly generated number has already been used or not. I think one approach that may be helpful is to have a list 0-9 and then randomly select from there. Once you use a number remove it from the list.
reply permalink
Ethan - 10 years, 7 months ago
Sounds like a good idea. :) Thanks!
reply permalink
Pearce Keesling - 10 years, 7 months ago
Normally I do these in C, but I felt like doing this one in ruby. If I feel inspired I'll probably rewrite in C.
reply permalink
Pearce Keesling - 10 years, 7 months ago
I guess I was able to find the motivation :)
reply permalink
Nick Krichevsky - 10 years, 7 months ago
A bit late ... but meh.
reply permalink
Anonymous - 10 years, 7 months ago
A complete solution in Clojure.
reply permalink
Anonymous - 10 years, 6 months ago
reply permalink