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

Post History

50%
+0 −0
Challenges Digit Sum Integer Sequence (working title)

Python 3, 183 181 175 bytes def f(a,b): c=a;a=str(a) for i in range(b): y=0;z=9 for j in range(len(a)): if y<int(a[j]):y=int(a[j]) if z>int(a[j]):z=int(a[j]) c=int(a)+...

posted 2y ago by General Sebast1an‭  ·  edited 2y ago by General Sebast1an‭

Answer
#3: Post edited by user avatar General Sebast1an‭ · 2021-09-09T06:45:11Z (over 2 years ago)
  • # [Python 3], <s>183</s> 181 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(a,b):
  • &#9;c=a;a=str(a);y,z=0,9
  • &#9;for i in range(b):
  • &#9;&#9;for j in range(len(a)):
  • &#9;&#9;&#9;if y&lt;int(a[j]):y=int(a[j])
  • &#9;&#9;&#9;if z&gt;int(a[j]):z=int(a[j])
  • &#9;&#9;c=int(a)+y+z;a=str(c);y=0;z=9
  • &#9;print(c)
  • </code></pre>
  • [Try it online!][TIO-ktc8iz68]
  • I decided to go for outputting the `i`th value of the sequence, 0-indexed. `a` is the number to be sequenced and `b` is the index of the value to be printed.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ktc8iz68]: https://tio.run/##VY5BDsIgEEXX5RQsmZRFrXFhKV7EuBgRlMbQBtnA5RGxsXH357/5yVtieMxun/NNG2oY8isMpFESBcpX8AxBRJ5kx4@kMbOnllpHPbq7ZvWzltNWPrUrm0oaa2gcrQsMz9MFhih/eaXptNH0R9X3gja2aTVRxUR2IslisvgPVpAN2/ED5J70bw "Python 3 – Try It Online"
  • # [Python 3], <s>183</s> <s>181</s> 175 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(a,b):
  • &#9;c=a;a=str(a)
  • &#9;for i in range(b):
  • &#9;&#9;y=0;z=9
  • &#9;&#9;for j in range(len(a)):
  • &#9;&#9;&#9;if y&lt;int(a[j]):y=int(a[j])
  • &#9;&#9;&#9;if z&gt;int(a[j]):z=int(a[j])
  • &#9;&#9;c=int(a)+y+z;a=str(c)
  • &#9;print(c)
  • </code></pre>
  • [Try it online!][TIO-ktckeoo7]
  • I decided to go for outputting the `i`th value of the sequence, 0-indexed. `a` is the number to be sequenced and `b` is the index of the non-existent list--since no list exists--to be printed.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ktckeoo7]: https://tio.run/##VY69DsIwEIPn9Cky3qkd@JloOV4EMRwhgVQordIsycuHtFRUbLY/W/IYw2twx5wf2kgD3NyxrYQi7pim4IGxEmbw0krrpGf31LA0RKRdl@hU1Iz7Db@1K6ulI6yR8WxdAL72N2wj/fRK02Wj6Y@qr8M61mn9oko@@jlWmA3smwPmDw "Python 3 – Try It Online"
#2: Post edited by user avatar General Sebast1an‭ · 2021-09-09T01:12:11Z (over 2 years ago)
  • # [Python 3], 183 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>a,b=input(),int(input());c=int(a);y,z=0,9
  • for i in range(b):
  • &#9;for j in range(len(a)):
  • &#9;&#9;if y&lt;int(a[j]):y=int(a[j])
  • &#9;&#9;if z&gt;int(a[j]):z=int(a[j])
  • &#9;c=int(a)+y+z;a=str(c);y=0;z=9
  • print(c)
  • </code></pre>
  • [Try it online!][TIO-ktc5stau]
  • I decided to go for outputting the `i`th value of the sequence, 0-indexed. `a` is the number to be sequenced and `b` is the index of the value to be printed. Standard I/O is used only, unless a golfed solution would use a function.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ktc5stau]: https://tio.run/##TY7NDoMgEITP8hQc2cjB2JPS7Ys0PSDRFtOsBOkBXp5K/@xtZr7M7rgYbgsdctZyQEvuEQRIS0F8NCiDxWpQUSZsZMemxXPLLXGv6TqKAXpWlWzes/tIW6OAyk48Hl8XzvMF@og//YbptMP0D79/61gnpXENXphtBDYqYcecL9RAzi1rnw "Python 3 – Try It Online"
  • # [Python 3], <s>183</s> 181 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def f(a,b):
  • &#9;c=a;a=str(a);y,z=0,9
  • &#9;for i in range(b):
  • &#9;&#9;for j in range(len(a)):
  • &#9;&#9;&#9;if y&lt;int(a[j]):y=int(a[j])
  • &#9;&#9;&#9;if z&gt;int(a[j]):z=int(a[j])
  • &#9;&#9;c=int(a)+y+z;a=str(c);y=0;z=9
  • &#9;print(c)
  • </code></pre>
  • [Try it online!][TIO-ktc8iz68]
  • I decided to go for outputting the `i`th value of the sequence, 0-indexed. `a` is the number to be sequenced and `b` is the index of the value to be printed.
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ktc8iz68]: https://tio.run/##VY5BDsIgEEXX5RQsmZRFrXFhKV7EuBgRlMbQBtnA5RGxsXH357/5yVtieMxun/NNG2oY8isMpFESBcpX8AxBRJ5kx4@kMbOnllpHPbq7ZvWzltNWPrUrm0oaa2gcrQsMz9MFhih/eaXptNH0R9X3gja2aTVRxUR2IslisvgPVpAN2/ED5J70bw "Python 3 – Try It Online"
#1: Initial revision by user avatar General Sebast1an‭ · 2021-09-08T23:57:14Z (over 2 years ago)
# [Python 3], 183 bytes

<!-- language-all: lang-python -->

<pre><code>a,b=input(),int(input());c=int(a);y,z=0,9
for i in range(b):
&#9;for j in range(len(a)):
&#9;&#9;if y&lt;int(a[j]):y=int(a[j])
&#9;&#9;if z&gt;int(a[j]):z=int(a[j])
&#9;c=int(a)+y+z;a=str(c);y=0;z=9
print(c)
</code></pre>

[Try it online!][TIO-ktc5stau]

I decided to go for outputting the `i`th value of the sequence, 0-indexed. `a` is the number to be sequenced and `b` is the index of the value to be printed. Standard I/O is used only, unless a golfed solution would use a function.

[Python 3]: https://docs.python.org/3/
[TIO-ktc5stau]: https://tio.run/##TY7NDoMgEITP8hQc2cjB2JPS7Ys0PSDRFtOsBOkBXp5K/@xtZr7M7rgYbgsdctZyQEvuEQRIS0F8NCiDxWpQUSZsZMemxXPLLXGv6TqKAXpWlWzes/tIW6OAyk48Hl8XzvMF@og//YbptMP0D79/61gnpXENXphtBDYqYcecL9RAzi1rnw "Python 3 – Try It Online"