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

Return to Answer

added 128 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 53 bytes

Nθ≔0ζFN«≔⟦⟧υW−θ⊕⌕υζ«≦⊕ζ≔ζη≔⟦⟧υFθ«≔↨Φη∧μ¬%ημ1η⊞υη»»»IζNθ≔0ζFN«≔⟦⟧υW−θ⊕⌕υζ«≦⊕ζ≔ζη≔⟦⟧υFθ«≔↨Φη∧μ¬%ημ1η⊞υη»»»Iυ

Try it online! Try it online! Link is to verbose version of code. Takes n and m as inputs and outputs the mth numbersequence, in order of last element of the cycle, including duplicate sequences. Very slow so in practice you need n<3. Explanation:

Input n.

≔0ζ

Start at zero.

FN«

Repeat m times.

≔⟦⟧υ

Clear any previous calculation.

W−θ⊕⌕υζ«

Repeat until a perfect n-cycle is found.

≦⊕ζ

Increment the test number.

≔ζη

Make a copy of the number.

≔⟦⟧υ

Start building a list of divisor sums.

Fθ«

Repeat n times.

≔↨Φη∧μ¬%ημ1η

Calculate the next divisor sum.

⊞υη

Save it to the list.

»»»Iζ»»»Iυ

Output the final resultcollected divisor sums, including the copy of the original counter as the last element of this list.

Charcoal, 53 bytes

Nθ≔0ζFN«≔⟦⟧υW−θ⊕⌕υζ«≦⊕ζ≔ζη≔⟦⟧υFθ«≔↨Φη∧μ¬%ημ1η⊞υη»»»Iζ

Try it online! Link is to verbose version of code. Takes n and m as inputs and outputs the mth number, including duplicate sequences. Very slow so in practice you need n<3. Explanation:

Input n.

≔0ζ

Start at zero.

FN«

Repeat m times.

≔⟦⟧υ

Clear any previous calculation.

W−θ⊕⌕υζ«

Repeat until a perfect n-cycle is found.

≦⊕ζ

Increment the test number.

≔ζη

Make a copy of the number.

≔⟦⟧υ

Start building a list of divisor sums.

Fθ«

Repeat n times.

≔↨Φη∧μ¬%ημ1η

Calculate the next divisor sum.

⊞υη

Save it to the list.

»»»Iζ

Output the final result.

Charcoal, 53 bytes

Nθ≔0ζFN«≔⟦⟧υW−θ⊕⌕υζ«≦⊕ζ≔ζη≔⟦⟧υFθ«≔↨Φη∧μ¬%ημ1η⊞υη»»»Iυ

Try it online! Link is to verbose version of code. Takes n and m as inputs and outputs the mth sequence, in order of last element of the cycle, including duplicate sequences. Very slow so in practice you need n<3. Explanation:

Input n.

≔0ζ

Start at zero.

FN«

Repeat m times.

≔⟦⟧υ

Clear any previous calculation.

W−θ⊕⌕υζ«

Repeat until a perfect n-cycle is found.

≦⊕ζ

Increment the test number.

≔ζη

Make a copy of the number.

≔⟦⟧υ

Start building a list of divisor sums.

Fθ«

Repeat n times.

≔↨Φη∧μ¬%ημ1η

Calculate the next divisor sum.

⊞υη

Save it to the list.

»»»Iυ

Output the collected divisor sums, including the copy of the original counter as the last element of this list.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 53 bytes

Nθ≔0ζFN«≔⟦⟧υW−θ⊕⌕υζ«≦⊕ζ≔ζη≔⟦⟧υFθ«≔↨Φη∧μ¬%ημ1η⊞υη»»»Iζ

Try it online! Link is to verbose version of code. Takes n and m as inputs and outputs the mth number, including duplicate sequences. Very slow so in practice you need n<3. Explanation:

Input n.

≔0ζ

Start at zero.

FN«

Repeat m times.

≔⟦⟧υ

Clear any previous calculation.

W−θ⊕⌕υζ«

Repeat until a perfect n-cycle is found.

≦⊕ζ

Increment the test number.

≔ζη

Make a copy of the number.

≔⟦⟧υ

Start building a list of divisor sums.

Fθ«

Repeat n times.

≔↨Φη∧μ¬%ημ1η

Calculate the next divisor sum.

⊞υη

Save it to the list.

»»»Iζ

Output the final result.

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