Looking through the awesome On-Line Encyclopedia of Integer Sequences (see en.wikipedia.org ), I came across the following whole sequence:
A031877 : Non-trivial spread numbers (numbers that are integer multiples of their spreads), excluding the palindrome of numbers and multiples of 10.
Reusing some code, I wrote for my answer to the corresponding question β Faster implementation of verbal arithmetic in Prolog β I could write down the solution quite easily - thanks to clpfd !
:- use_module(library(clpfd)).
Define the main ratio a031877_ndigits_/3 based on digits_number/2 (previously defined):
a031877_ndigits_(Z_big,N_digits,[K,Z_small,Z_big]) :- K
The main relation is deterministic and ends universally with N_digit - a specific integer. See for yourself for the first 100 N_digit values!
?- time((N in 0..99,indomain(N),a031877_ndigits_(Z,N,Zs),false)). % 3,888,222 inferences, 0.563 CPU in 0.563 seconds (100% CPU, 6903708 Lips) false
Run some queries!
? - a031877_ndigits_ (87912000000087912.17, _).
true% succeeds, as expected
; false
? - a031877_ndigits_ (87912000000 9 87912.17, _).
false % fails, as expected
Next, we find some non-trivial reversal numbers containing exactly four decimal places:
?- a031877_ndigits_(Z,4,Zs), labeling([],Zs). Z = 8712, Zs = [4,2178,8712] ; Z = 9801, Zs = [9,1089,9801] ; false.
OK! Let the runtime necessary to confirm the universal completion of the above request be measured!
?- time((a031877_ndigits_(Z,4,Zs),labeling([],Zs),false)). % 11,611,502 inferences, 3.642 CPU in 3.641 seconds (100% CPU, 3188193 Lips) false. % terminates universally
Now, this way too long!
What can I do to speed up the process? Use different and / or other restrictions? Maybe even redundant? Or perhaps identify and eliminate symmetries that reduce the size of the search space? What about the different clp (*) domains (b, q, r, set)? Or different consistency / spread methods? Or rather, the Prologue companion style?
Any ideas? I want them all! Thanks in advance.