ILP Part 87 — Sequence of squares

This is the eightieth seventh part of the ILP series. For your convenience you can find other parts in the table of contents in Part 1 – Boolean algebra

We want to create a sequence of numbers of increasing length where each number is a square of some integer and has same digits as previous number in the sequence (plus one additional digit, obviously). Example sequence is:

25,256,5625,65025,105625,9150625

Let’s solve it with ILP:

We define sequence parameters and the iterate through numbers (line 6).
For each number we first create digits (line 8) and then construct the full number (line 13).

Next, we make the number a root of some integer (line 21).

Next, we count digits (lines 24-32). If it’s another element of the sequence then we compare digits with previous number and make sure only one digit differs (lines 34-40).

Finally, we print the solution. Output: