Created
June 14, 2011 14:34
-
-
Save srih4ri/1025013 to your computer and use it in GitHub Desktop.
CheckPassword.rb
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
#!/usr/bin/env ruby | |
module PasswordChecker | |
def check_valid? | |
if length > 1 | |
(length/2).times { |i| | |
return false if (self[(i+1..length)].start_with? self[(0..i)]) | |
} | |
(self[(1..length)]).check_valid? | |
else | |
return true | |
end | |
end | |
end | |
class String | |
include PasswordChecker | |
end | |
input = ARGV[0].chomp | |
puts input.check_valid? ? "ACCEPTED" : "REJECTED" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment