Expand and ContractExpand tabs (implement expand(1))Decimal concatenation of squaresExpand the numberEvaluate a Dice 10,000 rollExpand ExponentiationExpand that Australian stateExpand a numberExpand Sine and CosineExpand some numberCompound interest with additions
What historical events would have to change in order to make 19th century "steampunk" technology possible?
Is this draw by repetition?
How dangerous is XSS
Knowledge-based authentication using Domain-driven Design in C#
Car headlights in a world without electricity
How to install cross-compiler on Ubuntu 18.04?
Does the Cone of Cold spell freeze water?
OP Amp not amplifying audio signal
What is the fastest integer factorization to break RSA?
Placement of More Information/Help Icon button for Radio Buttons
Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?
Using "tail" to follow a file without displaying the most recent lines
Can a virus destroy the BIOS of a modern computer?
Processor speed limited at 0.4 Ghz
Bullying boss launched a smear campaign and made me unemployable
Why was Sir Cadogan fired?
Is there an online compendium of Rav Moshe teshuvos in English that exists?
"the same as" in a sentence
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
How exploitable/balanced is this homebrew spell: Spell Permanency?
Could the museum Saturn V's be refitted for one more flight?
Can someone clarify Hamming's notion of important problems in relation to modern academia?
How much mains leakage does an Ethernet connection to a PC induce, and what is the operating leakage path?
Forgetting the musical notes while performing in concert
Expand and Contract
Expand tabs (implement expand(1))Decimal concatenation of squaresExpand the numberEvaluate a Dice 10,000 rollExpand ExponentiationExpand that Australian stateExpand a numberExpand Sine and CosineExpand some numberCompound interest with additions
$begingroup$
Take a positive integer $k$ as input. Start with $n := 1$ and repeatedly increase $n$ by the largest integer power of ten $i$ such that $i le n$ and $i + n le k$.
Repeat until $n = k$ and return a list of all intermediate values of $n$, including both the initial $1$ and the final $k$.
During this process, growth will initially be limited by the former inequality, and only afterwards by the latter; the growth will take the form of an initial "expansion" period, during which $n$ is increased by ever-larger powers, followed by a "contract" period, during which $n$ is increased by ever-smaller powers in order to "zoom in" on the correct number.
Test Cases
1 => [1]
10 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
321 => [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 310, 320, 321]
1002 => [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 400, 500, 600, 700, 800, 900,
1000, 1001, 1002]
This is code-golf, so the shortest answer (in bytes) wins.
code-golf number decimal
$endgroup$
add a comment |
$begingroup$
Take a positive integer $k$ as input. Start with $n := 1$ and repeatedly increase $n$ by the largest integer power of ten $i$ such that $i le n$ and $i + n le k$.
Repeat until $n = k$ and return a list of all intermediate values of $n$, including both the initial $1$ and the final $k$.
During this process, growth will initially be limited by the former inequality, and only afterwards by the latter; the growth will take the form of an initial "expansion" period, during which $n$ is increased by ever-larger powers, followed by a "contract" period, during which $n$ is increased by ever-smaller powers in order to "zoom in" on the correct number.
Test Cases
1 => [1]
10 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
321 => [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 310, 320, 321]
1002 => [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 400, 500, 600, 700, 800, 900,
1000, 1001, 1002]
This is code-golf, so the shortest answer (in bytes) wins.
code-golf number decimal
$endgroup$
add a comment |
$begingroup$
Take a positive integer $k$ as input. Start with $n := 1$ and repeatedly increase $n$ by the largest integer power of ten $i$ such that $i le n$ and $i + n le k$.
Repeat until $n = k$ and return a list of all intermediate values of $n$, including both the initial $1$ and the final $k$.
During this process, growth will initially be limited by the former inequality, and only afterwards by the latter; the growth will take the form of an initial "expansion" period, during which $n$ is increased by ever-larger powers, followed by a "contract" period, during which $n$ is increased by ever-smaller powers in order to "zoom in" on the correct number.
Test Cases
1 => [1]
10 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
321 => [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 310, 320, 321]
1002 => [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 400, 500, 600, 700, 800, 900,
1000, 1001, 1002]
This is code-golf, so the shortest answer (in bytes) wins.
code-golf number decimal
$endgroup$
Take a positive integer $k$ as input. Start with $n := 1$ and repeatedly increase $n$ by the largest integer power of ten $i$ such that $i le n$ and $i + n le k$.
Repeat until $n = k$ and return a list of all intermediate values of $n$, including both the initial $1$ and the final $k$.
During this process, growth will initially be limited by the former inequality, and only afterwards by the latter; the growth will take the form of an initial "expansion" period, during which $n$ is increased by ever-larger powers, followed by a "contract" period, during which $n$ is increased by ever-smaller powers in order to "zoom in" on the correct number.
Test Cases
1 => [1]
10 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
321 => [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 310, 320, 321]
1002 => [1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 20, 30, 40, 50, 60, 70, 80, 90,
100, 200, 300, 400, 500, 600, 700, 800, 900,
1000, 1001, 1002]
This is code-golf, so the shortest answer (in bytes) wins.
code-golf number decimal
code-golf number decimal
asked 1 hour ago
Esolanging FruitEsolanging Fruit
8,65932774
8,65932774
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
Python 2, 61 bytes
f=lambda k,n=1:n<k and[n]+f(k,n+10**~-len(`min(n,k-n)`))or[n]
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 6, 48 41 bytes
->k1,$_+10**min($_,k-$_).comb/10...k
Try it online!
Explanation:
->k # Anonymous code block taking k
1, ...k # Start a sequence from 1 to k
# Where each element is
$_+ # The previous element plus
10** # 10 to the power of
.comb # The length of
min($_,k-$_) # The min of the current count and the remainder
/10 # Minus one
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182569%2fexpand-and-contract%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 61 bytes
f=lambda k,n=1:n<k and[n]+f(k,n+10**~-len(`min(n,k-n)`))or[n]
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 61 bytes
f=lambda k,n=1:n<k and[n]+f(k,n+10**~-len(`min(n,k-n)`))or[n]
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 61 bytes
f=lambda k,n=1:n<k and[n]+f(k,n+10**~-len(`min(n,k-n)`))or[n]
Try it online!
$endgroup$
Python 2, 61 bytes
f=lambda k,n=1:n<k and[n]+f(k,n+10**~-len(`min(n,k-n)`))or[n]
Try it online!
edited 43 mins ago
answered 49 mins ago
Chas BrownChas Brown
5,0991523
5,0991523
add a comment |
add a comment |
$begingroup$
Perl 6, 48 41 bytes
->k1,$_+10**min($_,k-$_).comb/10...k
Try it online!
Explanation:
->k # Anonymous code block taking k
1, ...k # Start a sequence from 1 to k
# Where each element is
$_+ # The previous element plus
10** # 10 to the power of
.comb # The length of
min($_,k-$_) # The min of the current count and the remainder
/10 # Minus one
$endgroup$
add a comment |
$begingroup$
Perl 6, 48 41 bytes
->k1,$_+10**min($_,k-$_).comb/10...k
Try it online!
Explanation:
->k # Anonymous code block taking k
1, ...k # Start a sequence from 1 to k
# Where each element is
$_+ # The previous element plus
10** # 10 to the power of
.comb # The length of
min($_,k-$_) # The min of the current count and the remainder
/10 # Minus one
$endgroup$
add a comment |
$begingroup$
Perl 6, 48 41 bytes
->k1,$_+10**min($_,k-$_).comb/10...k
Try it online!
Explanation:
->k # Anonymous code block taking k
1, ...k # Start a sequence from 1 to k
# Where each element is
$_+ # The previous element plus
10** # 10 to the power of
.comb # The length of
min($_,k-$_) # The min of the current count and the remainder
/10 # Minus one
$endgroup$
Perl 6, 48 41 bytes
->k1,$_+10**min($_,k-$_).comb/10...k
Try it online!
Explanation:
->k # Anonymous code block taking k
1, ...k # Start a sequence from 1 to k
# Where each element is
$_+ # The previous element plus
10** # 10 to the power of
.comb # The length of
min($_,k-$_) # The min of the current count and the remainder
/10 # Minus one
edited 38 mins ago
answered 1 hour ago
Jo KingJo King
26.3k364129
26.3k364129
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182569%2fexpand-and-contract%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown