Skip to main content
Use improved test harness
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!Try it Online!

≬    # 3-element lambda:
  K  # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯  # Deltas - returns a list of the consecutive differences in the list.
     # The resulting list has a length of 1 less than the one fed to it.
  ÷  # Unwrap the list onto the stack. For a non-empty list, this is effectively
     # equivalent to t (Tail - get the last item). But for an empty list, the
     # result is effectively whatever was already on the stack, i.e. the the
     # number whose list of divisors was taken, i.e., 1, the only one that yields
     # an empty deltas list. This makes 1, instead of 0, the fixed point.
ẋ    # 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 1, our fixed point.
L    # Length

This is very slow for most numbers of more than 60 decimal digits or so, since it has to generate a full list of divisors (even if it only uses the largest two). Prime factorization is still fast enough at that level, but unless the number has only one distinct prime factor, the list of divisors will be orders of magnitude longer.

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!

≬    # 3-element lambda:
  K  # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯  # Deltas - returns a list of the consecutive differences in the list.
     # The resulting list has a length of 1 less than the one fed to it.
  ÷  # Unwrap the list onto the stack. For a non-empty list, this is effectively
     # equivalent to t (Tail - get the last item). But for an empty list, the
     # result is effectively whatever was already on the stack, i.e. the the
     # number whose list of divisors was taken, i.e., 1, the only one that yields
     # an empty deltas list. This makes 1, instead of 0, the fixed point.
ẋ    # 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 1, our fixed point.
L    # Length

This is very slow for most numbers of more than 60 decimal digits or so, since it has to generate a full list of divisors (even if it only uses the largest two). Prime factorization is still fast enough at that level, but unless the number has only one distinct prime factor, the list of divisors will be orders of magnitude longer.

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!

≬    # 3-element lambda:
  K  # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯  # Deltas - returns a list of the consecutive differences in the list.
     # The resulting list has a length of 1 less than the one fed to it.
  ÷  # Unwrap the list onto the stack. For a non-empty list, this is effectively
     # equivalent to t (Tail - get the last item). But for an empty list, the
     # result is effectively whatever was already on the stack, i.e. the the
     # number whose list of divisors was taken, i.e., 1, the only one that yields
     # an empty deltas list. This makes 1, instead of 0, the fixed point.
ẋ    # 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 1, our fixed point.
L    # Length

This is very slow for most numbers of more than 60 decimal digits or so, since it has to generate a full list of divisors (even if it only uses the largest two). Prime factorization is still fast enough at that level, but unless the number has only one distinct prime factor, the list of divisors will be orders of magnitude longer.

add back the note about speed; bring the word "order", in the comments, into full visibility
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!

     # 3-element lambda:
  K   # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯   # Deltas - returns a list of the consecutive differences in the list.
      # The resulting list has a length of 1 less than the one fed to it.
  ÷   # Unwrap the list onto the stack. For a non-empty list, this is effectively
      # equivalent to t (Tail - get the last item). But for an empty list, the
      # result is effectively whatever was already on the stack, i.e. the the
      # number whose list of divisors was taken, i.e., 1, the only one that yields
      # an empty deltas list. This makes 1, instead of 0, the fixed point.
ẋ     # 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 1, our fixed point.
L     # Length

This is very slow for most numbers of more than 60 decimal digits or so, since it has to generate a full list of divisors (even if it only uses the largest two). Prime factorization is still fast enough at that level, but unless the number has only one distinct prime factor, the list of divisors will be orders of magnitude longer.

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!

     # 3-element lambda:
  K   # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯   # Deltas - returns a list of the consecutive differences in the list.
      # The resulting list has a length of 1 less than the one fed to it.
  ÷   # Unwrap the list onto the stack. For a non-empty list, this is effectively
      # equivalent to t (Tail - get the last item). But for an empty list, the
      # result is effectively whatever was already on the stack, i.e. the the
      # number whose list of divisors was taken, i.e., 1, the only one that yields
      # an empty deltas list. This makes 1, instead of 0, the fixed point.
ẋ     # 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 1, our fixed point.
L     # Length

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!

≬    # 3-element lambda:
  K  # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯  # Deltas - returns a list of the consecutive differences in the list.
     # The resulting list has a length of 1 less than the one fed to it.
  ÷  # Unwrap the list onto the stack. For a non-empty list, this is effectively
     # equivalent to t (Tail - get the last item). But for an empty list, the
     # result is effectively whatever was already on the stack, i.e. the the
     # number whose list of divisors was taken, i.e., 1, the only one that yields
     # an empty deltas list. This makes 1, instead of 0, the fixed point.
ẋ    # 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 1, our fixed point.
L    # Length

This is very slow for most numbers of more than 60 decimal digits or so, since it has to generate a full list of divisors (even if it only uses the largest two). Prime factorization is still fast enough at that level, but unless the number has only one distinct prime factor, the list of divisors will be orders of magnitude longer.

improve comment wording
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!

≬     # 3-element lambda:
  K   # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯   # Deltas - returns a list of the consecutive differences in the list.
      # The resulting list has a length of 1 less than the one fed to it.
  ÷   # Unwrap the list onto the stack. For a non-empty list, this is effectively
      # effectively equivalent to t (Tail - get the last item). But for an empty list, the
      # anresult emptyis list,effectively whatever was already on the resultstack, isi.e. the the 
 number whose list of divisors
 # number whose list of #divisors was taken, (i.e., 1), the only one that yields
      # an empty deltas list. This makes 1, instead of 0, the fixed point.
ẋ     # Repeat the lambda on the number at the top of the stack (which is initially the
      # the input) until the result no longer changes, returning a list of the results. The
      # results. The last result will be 1, our fixed point.
L     # Length

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!

≬     # 3-element lambda:
  K   # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯   # Deltas - returns a list of the consecutive differences in the list.
      # The resulting list has a length of 1 less than the one fed to it.
  ÷   # Unwrap the list onto the stack. For a non-empty list, this is
      # effectively equivalent to t (Tail - get the last item). But for
      # an empty list, the result is the the number whose list of divisors
      # was taken (i.e., 1). This makes 1, instead of 0, the fixed point.
ẋ     # 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 1, our fixed point.
L     # Length

Vyxal l, 6 5 bytes

≬K¯÷ẋ

Try it Online!

This is the same as the 6 byte answer below except the length is taken by the l flag rather than a L element.

Vyxal, 7 6 bytes

≬K¯÷ẋL

Try it Online!

≬     # 3-element lambda:
  K   # Push a list of the divisors, from 1 to the number itself in increasing order
  ¯   # Deltas - returns a list of the consecutive differences in the list.
      # The resulting list has a length of 1 less than the one fed to it.
  ÷   # Unwrap the list onto the stack. For a non-empty list, this is effectively
      # equivalent to t (Tail - get the last item). But for an empty list, the
      # result is effectively whatever was already on the stack, i.e. the the 
      # number whose list of divisors was taken, i.e., 1, the only one that yields
      # an empty deltas list. This makes 1, instead of 0, the fixed point.
ẋ     # 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 1, our fixed point.
L     # Length
-1 byte
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
add another 6-byte-with-flag version
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
add another 6-byte-with-flag version, and fix a typo
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Explain why this is much slower than the one using Euler's totient function
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
added 3 characters in body
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
improve the 6 byter - works for 1 now
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
add 6 byter
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading