Created
October 17, 2023 19:03
-
-
Save l3gacyb3ta/514084dd24abf6f6910d6a86294492bc to your computer and use it in GitHub Desktop.
Little SWI Prolog thing, for an IMPOSIBLE MATH QUESTION. Jamie you're the worst.
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
even(X) :- 0 is mod(X, 2). | |
odd(X) :- 1 is mod(X, 2). | |
sumofdigits(X, X) :- X<10. | |
sumofdigits(X, Y) :- X>=10, X1 is X // 10, X2 is X mod 10, sumofdigits(X1, Y1), Y is Y1 + X2. | |
digit_sum(N, Base, Sum):- | |
digit_sum(N, Base, Sum, 0). | |
digit_sum(N, Base, Sum, S1):- | |
N < Base, | |
!, | |
Sum is S1 + N. | |
digit_sum(N, Base, Sum, S1):- | |
divmod(N, Base, M, Digit), | |
S2 is S1 + Digit, | |
digit_sum(M, Base, Sum, S2). | |
get_digit(N, Place, Digit) :- | |
Digit is (N // (Place)) mod 10. | |
solve(N) :- N #> 0, N #< 490, indomain(N), | |
even(N), | |
not((get_digit(N, 1, X), X = 2, X = 4)), | |
get_digit(N, 10, Z), get_digit(N, 1, Y), Z is 3 * Y, | |
digit_sum(N, 10, 19). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment