I've got this Prolog program below that examines if a password fulfills certain rules (the password must contain a letter(a-z), a number(0-9),a double letter (aa,ll,ww etc.), must start with a letter (a, aa, c etc.), must be at least 6 characters long).
How can I expand it so that double letters would be counted as one letter? (For example, aa25b1 wouldn't be a correct password as it's only five characters long).
contains_letter(Password) :- wildcard_match('*[a-zA-Z]*', Password).
contains_number(Password) :- wildcard_match('*[0-9]*', Password).
contains_double_letter(Password) :-
(between(65, 90, Letter) ; between(97, 122, Letter)),
append([_, [Letter, Letter], _], Password),
!.
starts_with_letter(Password) :- wildcard_match('[a-zA-Z]*', Password).
long_enough(Password) :-
length(Password, Length),
Length >= 6.
check_everything(Password) :-
contains_letter(Password),
contains_number(Password),
contains_double_letter(Password),
starts_with_letter(Password),
long_enough(Password).
First and as I precised in your first question, note that you can combine that :
Into that :
Now, you can handle double letters and length as follows :
Using that predicate into this main predicate :
PS : please take the time to accept the answers you find the most constructive and upvote the ones that helped you.