Skip to main content
3 of 11
improve the 6 byter - works for 1 now
Deadcode
  • 11.9k
  • 1
  • 66
  • 52

Vyxal s, 6 bytes

≬K¯tẋ±

Try it Online!

This is the same as the 7 byte answer below (so please see below for its explanation), but it's final operation is ċ instead of L‹:

±     # Get the sign of a number

Then the s flag sums the resulting list, which contains all 1s except for one 0, thus yielding the length of the list minus 1.

Vyxal, 7 bytes

≬K÷εẋL‹

Try it Online!

Ties with Steffan's answer, but uses the algorithm defined by the challenge:

≬     # 3-element lambda:
  K   # Push a list of the divisors, from 1 to the number itself in increasing order
  ÷   # Unwrap the list onto the stack
  ε   # Absolute difference of the last two items (this will be the largest two)
ẋ     # Repeat the lambda on the number at the top of the stack (which is initially the
      # input) until the result no longer changes, returning a list of the results. The
      # last result will be zero, because the list of divisors of the penultimate result,
      # 1, is just ⟨1⟩, but ε will subtract that 1 from itself.
L     # Length
‹     # Decrement - subtract 1

- also works in place of ε, i.e. ≬K÷-ẋL‹. The sign of the intermediate result keeps flipping, since the subtraction is done in the "wrong" direction, but the number of steps to get to zero is the same.

Alternative 7 byter:

≬K¯tẋL‹

Try it Online!

Only the lambda is different in this:

  K   # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯   # Deltas (consecutive differences)
  t   # Tail - get the last item of the list

This still takes one more step than we want, requiring the decrement, because t tail returns zero for an empty list. And even if it returned something else (such as empty list), the fixed point would still be that result, and not 1, thus still requiring the decrement.

Deadcode
  • 11.9k
  • 1
  • 66
  • 52