-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
39 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
% Kaprekar's constant | ||
|
||
% recursive case till 6174 is reached | ||
'<https://eyereasoner.github.io/ns#kaprekar-constant>'(A, B, C) :- | ||
A =\= 0, | ||
'<https://eyereasoner.github.io/ns#numberToDigits>'(A, D), | ||
keysort(D, E), | ||
reverse(E, F), | ||
'<https://eyereasoner.github.io/ns#digitsToNumber>'(E, G), | ||
'<https://eyereasoner.github.io/ns#digitsToNumber>'(F, H), | ||
I is H-G, | ||
J is B+1, | ||
( I =:= 6174 | ||
-> C = J | ||
; '<https://eyereasoner.github.io/ns#kaprekar-constant>'(I, J, C) | ||
). | ||
|
||
% convert 4 digit number to digits | ||
'<https://eyereasoner.github.io/ns#numberToDigits>'(A, [B-0, C-0, D-0, E-0]) :- | ||
B is A // 1000, | ||
F is A rem 1000, | ||
C is F // 100, | ||
G is F rem 100, | ||
D is G // 10, | ||
E is G rem 10. | ||
|
||
% convert 4 digits to number | ||
'<https://eyereasoner.github.io/ns#digitsToNumber>'([A-0, B-0, C-0, D-0], E) :- | ||
E is A*1000+B*100+C*10+D. | ||
|
||
% recursion count | ||
'<https://eyereasoner.github.io/ns#recursionCount>'(I, J) :- | ||
'<https://eyereasoner.github.io/ns#kaprekar-constant>'(I, 0, J). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/bin/bash | ||
eye --quiet --skolem-genid 8b98b360-9a70-4845-b52c-c675af60ad01 --wcache https://eyereasoner.github.io/eye/reasoning .. --nope https://eyereasoner.github.io/eye/reasoning/kaprekar-constant/kaprekar-constant.n3 --query https://eyereasoner.github.io/eye/reasoning/kaprekar-constant/kaprekar-constant-query.n3 --output kaprekar-constant-answer.n3 | ||
eye --quiet --skolem-genid 8b98b360-9a70-4845-b52c-c675af60ad01 --wcache https://eyereasoner.github.io/eye/reasoning .. --nope --query https://eyereasoner.github.io/eye/reasoning/kaprekar-constant/kaprekar-constant-query.n3 --output kaprekar-constant-answer.n3 |