Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Digit Sum Integer Sequence (working title)

Parent

Digit Sum Integer Sequence (working title)

+6
−0

Inspired by this challenge. If anyone has any suggestions for a song title I could use for the challenge title then please leave a comment.

Definition

We define f(x) for a given integer as the sum of:

  • x itself,
  • s, the smallest digit in the decimal representation of x, and,
  • l, the largest digit in the decimal representation of x

Examples

x s m f(x)
2 2 2 6
53 3 5 61
77 7 7 91
123 1 3 127
8022 0 8 8030

Challenge

You will be building a sequence by repeatedly applying f(x) to a starting value n>0 taken as input, with the first term in the sequence being n itself.

For example, given a starting value of n=1, the first few terms go as follows:

1, 3, 9, 27, 36, 45, 54, 63, ...

You will also take an integer i as input and then either:

  • Output the ith term (0-indexed or 1-indexed, but please specify) of the n-based sequence,
  • Output the the first i terms of that sequence, or,
  • Forego taking i as input and output the n-based sequence infinitely.

Rules

  • I/O can be by any reasonable, convenient means.
  • This is code-golf so lowest byte count in each language wins.

Test Cases

Here are the first 25 terms of each sequence from n=1 to n=10:

  1,   3,   9,  27,  36,  45,  54,  63,  72,  81,  90,  99, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179, 189, 199, 209
  2,   6,  18,  27,  36,  45,  54,  63,  72,  81,  90,  99, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179, 189, 199, 209
  3,   9,  27,  36,  45,  54,  63,  72,  81,  90,  99, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179, 189, 199, 209, 218
  4,  12,  15,  21,  24,  30,  33,  39,  51,  57,  69,  84,  96, 111, 113, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179
  5,  15,  21,  24,  30,  33,  39,  51,  57,  69,  84,  96, 111, 113, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179, 189
  6,  18,  27,  36,  45,  54,  63,  72,  81,  90,  99, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179, 189, 199, 209, 218
  7,  21,  24,  30,  33,  39,  51,  57,  69,  84,  96, 111, 113, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179, 189, 199
  8,  24,  30,  33,  39,  51,  57,  69,  84,  96, 111, 113, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179, 189, 199, 209
  9,  27,  36,  45,  54,  63,  72,  81,  90,  99, 117, 125, 131, 135, 141, 146, 153, 159, 169, 179, 189, 199, 209, 218, 227
 10,  11,  13,  17,  25,  32,  37,  47,  58,  71,  79,  95, 109, 118, 127, 135, 141, 146, 153, 159, 169, 179, 189, 199, 209

More test cases can be generated using this ungolfed Japt implementation, where the first integer in the header is n and the second is i.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Regarding title (1 comment)
Post
+0
−0

Dyalog APL, 23 bytes

{⍵+(⌈/+⌊/)10⊥⍣¯1⊢⍵}⍣⎕⊢1­⁡​‎‎⁡⁠⁢⁢⁢‏⁠‎⁡⁠⁢⁢⁣‏‏​⁡⁠⁡‌⁢​‎⁠⁠‎⁡⁠⁢⁡⁤‏⁠‎⁡⁠⁢⁢⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏‏​⁡⁠⁡‌⁤​‎⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏⁠‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁡⁡‏⁠‎⁡⁠⁢⁡⁢‏‏​⁡⁠⁡‌⎕

Takes an input n and outputs the 0-indexed nth item of the sequence.

{⍵+(⌈/+⌊/)10⊥⍣¯1⊢⍵}⍣⎕⊢⎕­⁡​‎‎⁡⁠⁢⁢⁢‏⁠‎⁡⁠⁢⁢⁣‏‏​⁡⁠⁡‌⁢​‎⁠⁠‎⁡⁠⁢⁡⁤‏⁠‎⁡⁠⁢⁢⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏‏​⁡⁠⁡‌⁤​‎⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏⁠‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁡⁡‏⁠‎⁡⁠⁢⁡⁢‏‏​⁡⁠⁡‌­
                     ⊢⎕  ⍝ ‎⁡Starting from <input>,
                   ⍣⎕    ⍝ ‎⁢repeat <input> times
 ⍵+                      ⍝ ‎⁣the number plus
   (⌈/+⌊/)               ⍝ ‎⁤the minimum plus the maximum of
          10⊥⍣¯1         ⍝ ‎⁢⁡the base-10 representation
                ⊢⍵       ⍝ ‎⁢⁢of the number.
💎

Created with the help of Luminespire.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Requires a second input, or a non-terminating output (4 comments)
Requires a second input, or a non-terminating output
trichoplax‭ wrote about 1 year ago

From the challenge wording:

You will also take an integer i as input and then either:

  • Output the ith term (0-indexed or 1-indexed, but please specify) of the n-based sequence,
  • Output the the first i terms of that sequence, or,
  • Forego taking i as input and output the n-based sequence infinitely.

None of these options seems compatible with taking 1 input and treating it as both n and i.

RubenVerg‭ wrote 6 months ago

@trichoplax hmm, just saw this reply nine months late (: i don't recall what the code is doing but i can see by looking at it that it takes two inputs because appears twice. presumably one of the two ns is meant to be an i.

trichoplax‭ wrote 6 months ago

I have no APL knowledge so I can't guess. It was just to let you know in case either the code or the explanation needed to change.

RubenVerg‭ wrote 6 months ago

yeah, thanks for pointing it out! as soon as I have time I'll figure out what the challenge asks and what my code does and fix the explanation.