Skip to content

Commit

Permalink
refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
josd committed Mar 2, 2025
1 parent 63e4d16 commit 037e86a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
3 changes: 2 additions & 1 deletion reasoning/kaprekar-constant/kaprekar-constant-query.n3
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
@prefix : <https://eyereasoner.github.io/ns#>.

{
10000 log:repeat ?I.
("consult" "./kaprekar-constant.pl") log:program true.
("between" 0 9999 ?I) log:program true.
?I :recursionCount ?N.
} => {
?I :recursionCount ?N.
Expand Down
37 changes: 0 additions & 37 deletions reasoning/kaprekar-constant/kaprekar-constant.n3

This file was deleted.

33 changes: 33 additions & 0 deletions reasoning/kaprekar-constant/kaprekar-constant.pl
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).
2 changes: 1 addition & 1 deletion reasoning/kaprekar-constant/test
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

0 comments on commit 037e86a

Please sign in to comment.