Sum digits till Square Given is any integer x > 0 and any base y > 3.


Sum all digits of x (if written in the set base).
Multiply this by the highest possible digit (is always base -1).
Repeat until this value is (y - 1) ^ 2


Searched is the count of iterations and the steps.

Example 1:

x= 739
y= 7
searched: (7 - 1) ^ 2 = 36

based: (b7)2104
sum: (dec)7
mul: (dec)42

based: (b7)60
sum: (dec)6
mul: (dec)36

2 steps needed -&gt; answer is [2, 739, 42, 36] or [739, 42, 36, 2]


Example 2:

x = 1712
y = 19
s: 324

step1: 1712 -&gt; 360
step2:  360 -&gt; 648
step3:  648 -&gt; 324

3 steps needed -&gt; answer is [3, 1712, 360, 648, 324] or [1712, 360, 648, 324, 3]


Special:
In some cases (some combinations with a base of 3) you will not be able to get to (y - 1) ^ 2 like for x = 53 and y = 3. For this reason y needs to be bigger than 3 and you can ignore this.

The count of iterations need to be the first or the last value

This is code-golf lowest byte-count wins.
Perl 6, 60 bytes



{$/=[$^x,*.polymod($^y xx*).sum*($y-1)...($y-1)²];$/-1,|$/}


Expanded:

{    # bare block lambda with placeholder parameters ｢$x｣ ｢$y｣

  $/ = [          # store in ｢$/｣ ( so that we don't have to declare it )

    # generate a sequence

    $^x,          # declare first parameter, and seed sequence generator

    # Whatever lambda

    *\            # the parameter to this lambda

    .polymod(     # broken down with a list of moduli

      $^y         # declare second parameter of the outer block lambda
      xx *        # an infinite list of copies of it

    )
    .sum
    *
    ( $y - 1 )

    # end of Whatever lambda

    ...           # repeat until it reaches

    ( $y - 1 )²
  ];

  # returns
  $/ - 1,         # count of values minus one
  |$/             # Slip ｢|｣ the list into the result
}


Usage:

# store it in the lexical namespace so that it is easier to understand
my &amp;code = {$/=[$^x,*.polymod($^y xx*).sum*($y-1)...($y-1)²];$/-1,|$/}

say code  739,  7; # (2 739 42 36)
say code 1712, 19; # (3 1712 360 648 324)