Hey Y'all!! This time, I actually brought the input.txt file in as it was, and again, made a ruby solution that im sure could be a bit more refactored, but i got to play with regex! so that was fun... Here's my full code, and here's a snippet of what i did to solve it:
classPasswordCheckerattr_reader:parse_passwords,:check_passwordsdefinitialize(passwords)@passwords=passwords@parsed_passwords=parse_passwordsenddefparse_passwordsparsed=@passwords.mapdo|item|item_split=item.match(/(^\d*)-(\d*) (\w): (\w*)/){min: item_split[1].to_i,max: item_split[2].to_i,letter: item_split[3],password: item_split[4]}endparsedenddefvalidate_password_frequency(log)# puts "rules are minimum #{log[:min]} and max #{log[:max]}"# puts "there are #{log[:password].count(log[:letter])} letter #{log[:letter]}'s"log[:password].count(log[:letter]).to_i.between?(log[:min],log[:max])enddefvalidate_password_accuracy(log)returnfalseunlesslog[:password].include?(log[:letter])returnfalseiflog[:password][log[:min]-1]==log[:letter]&&log[:password][log[:max]-1]==log[:letter]# puts "rules are letter #{log[:letter]} must be at position #{log[:min]} and then at position #{log[:max]}"# puts "there's a #{log[:password][log[:min] - 1]} at position #{log[:min]} and a #{log[:password][log[:max] - 1]} at position #{log[:max]}"log[:password][log[:min]-1]==log[:letter]||log[:password][log[:max]-1]==log[:letter]enddefcheck_passwords(way="frequency")@parsed_passwords.mapdo|log|ifway=="accuracy"validate_password_accuracy(log)elsevalidate_password_frequency(log)endend.count(true)endend
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey Y'all!! This time, I actually brought the input.txt file in as it was, and again, made a ruby solution that im sure could be a bit more refactored, but i got to play with regex! so that was fun...
Here's my full code, and here's a snippet of what i did to solve it: