Hacker News new | past | comments | ask | show | jobs | submit login

Nice. As a hint, you can unify free variables, i.e., variables not bound to anything. Future bindings of those variables will respect the equality.

This means that you could write your password/1 predicate as something more like:

    password(X) :-
      length(X, 6),
      has_2_equal_consecutive_digits(X),
      has_6_digits(X),
      is_value_in_range(X),
      digits_are_increasing(X).
That is, even before filling the list with digits, you would already have captured the constraint that two digits will have to be consecutive. Then, while instantiating the list inside has_6_digits/1, something like 134567 would never even be generated, and you wouldn't need to test it for being in range and having increasing digits.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: