Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Sociable sequences

Sociable numbers are a generalisation of both perfect and amicable numbers. They are numbers whose proper divisor sums form cycles beginning and ending at the same number. A number is \$n\$-sociable if the cycle it forms has \$n\$ unique elements. For example, perfect numbers are \1ドル\$-sociable (\6ドル\to6\to\cdots\$) and amicable numbers are \2ドル\$-sociable (\220ドル\to284\to220\to\cdots\$).

Note that the entire cycle must begin and end with the same number. \25ドル\$ for example is not a \1ドル\$-sociable number as it's cycle is \25ドル \to 6 \to 6 \to \cdots\$, which, despite containing a period \1ドル\$ cycle, does not begin and end with that cycle.

The proper divisor sum of an integer \$x\$ is the sum of the positive integers that divide \$x\$, not including \$x\$ itself. For example, the proper divisor sum of \24ドル\$ is \1ドル + 2 +たす 3 +たす 4 +たす 6 +たす 8 +たす 12 = 36\$

There are currently \51ドル\$ known \1ドル\$-sociable numbers, \1225736919ドル\$ known \2ドル\$-sociable pairs, no known \3ドル\$-sociable sequences, \5398ドル\$ known \4ドル\$-sociable sequences and so on.

You may choose whether to:

  • Take a positive integer \$n\$, and a positive integer \$m\$ and output the \$m\$th \$n\$-sociable sequence
  • Take a positive integer \$n\$, and a positive integer \$m\$ and output the first \$m\$ \$n\$-sociable sequences
  • Take a positive integer \$n\$ and output all \$n\$-sociable sequences

If you choose either of the last 2, each sequence must have internal separators (e.g. 220, 284 for \$n = 2\$) and distinct, external separators between sequences (e.g. [220, 284], [1184, 1210] for \$n = 2\$). For either of the first 2, the sequences should be ordered lexicographically.

You can choose whether to include "duplicate" sequences, i.e. the sequences that are the same as others, just beginning with a different number, such as including both 220, 284 and 284, 220. Please state in your answer if you do this.

The Catalan-Dickson conjecture states that every sequence formed by repeatedly taking the proper divisor sum eventually converges. Your answer may assume this conjecture to be true (meaning that you are allowed to iterate through each integer, testing if it is \$n\$-sociable by calculating if it belongs to an \$n\$-cycle, even though such approaches would fail for e.g. \276ドル\$ if the conjecture is false).

You may also assume that for a given \$n\$, there exists an infinite number of \$n\$-sociable sequences.

This is so the shortest code in bytes wins

Test cases

n -> n-sociable sequences
1 -> 6, 28, 496, 8128, ...
2 -> [220, 284], [284, 220], [1184, 1210], [1210, 1184], [2620, 2924], [2924, 2620], [5020, 5564], [5564, 5020], [6232, 6368], [6368, 6232], ...
4 -> [1264460, 1547860, 1727636, 1305184], ...
5 -> [12496, 14288, 15472, 14536, 14264], [14264, 12496, 14288, 15472, 14536], ...
6 -> [21548919483, 23625285957, 24825443643, 26762383557, 25958284443, 23816997477], ...
8 -> [1095447416, 1259477224, 1156962296, 1330251784, 1221976136, 1127671864, 1245926216, 1213138984], ...
9 -> [805984760, 1268997640, 1803863720, 2308845400, 3059220620, 3367978564, 2525983930, 2301481286, 1611969514], ...

Answer*

Draft saved
Draft discarded
Cancel
4
  • \$\begingroup\$ 78 bytes: tio.run/… \$\endgroup\$ Commented Mar 12, 2021 at 9:19
  • \$\begingroup\$ @GB, nice, thanks! \$\endgroup\$ Commented Mar 12, 2021 at 9:42
  • 1
    \$\begingroup\$ -1 using Ruby 2.7 unnamed arguments - won't work on TIO because it doesn't have 2.7, but here's a link anyway: Try it online! \$\endgroup\$ Commented Mar 12, 2021 at 9:56
  • \$\begingroup\$ @pxeger, yes, I know, but it's so frustrating to keep track of several versions, where one is shorter, but the other works on TIO. Too bad, TIO isn't actively updated anymore... \$\endgroup\$ Commented Mar 12, 2021 at 10:03

AltStyle によって変換されたページ (->オリジナル) /