New order #4: WorldNew Order #2: Turn My WayNew Order #1: How does this feel?New Order #3: 5 8 6Return the...
Why is "Reports" in sentence down without "The"
How to type dʒ symbol (IPA) on Mac?
How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?
Motorized valve interfering with button?
What exactly is the parasitic white layer that forms after iron parts are treated with ammonia?
Can I make popcorn with any corn?
A Journey Through Space and Time
Theorems that impeded progress
How long does it take to type this?
How to get the available space of $HOME as a variable in shell scripting?
How can I hide my bitcoin transactions to protect anonymity from others?
I probably found a bug with the sudo apt install function
Is there really no realistic way for a skeleton monster to move around without magic?
Why has Russell's definition of numbers using equivalence classes been finally abandoned? ( If it has actually been abandoned).
Is it possible to make sharp wind that can cut stuff from afar?
Why is an old chain unsafe?
What do you call a Matrix-like slowdown and camera movement effect?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
Patience, young "Padovan"
Why don't electromagnetic waves interact with each other?
Is there a familial term for apples and pears?
GPS Rollover on Android Smartphones
Prevent a directory in /tmp from being deleted
What is the command to reset a PC without deleting any files
New order #4: World
New Order #2: Turn My WayNew Order #1: How does this feel?New Order #3: 5 8 6Return the nth digit of the sequence of aliquot seriesRepeated reciprocalRecamán's duplicatesCompute the minimum $a(n)>a(n-1)$ such that $a(1)+a(2)+dots+a(n)$ is prime (OEIS A051935)Half, Half Half, and, HalfHyperoperation GolfingRepeat this GCD operationNew Order #1: How does this feel?New Order #2: Turn My WayNew Order #3: 5 8 6
$begingroup$
Introduction (may be ignored)
Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. This is the fourth challenge in this series (links to the first, second and third challenge).
In this challenge, we will explore not one permutation of the natural numbers, but an entire world of permutations!
In 2000, Clark Kimberling posed a problem in the 26th issue of Crux Mathematicorum, a scientific journal of mathematics published by the Canadian Mathematical Society. The problem was:
$text{Sequence }a = begin{cases}
a_1 = 1\
a_n = lfloor frac{a_{n-1}}{2} rfloortext{ if }lfloor frac{a_{n-1}}{2} rfloor notin {0, a_1, ... , a_{n-1}}\
a_n = 3 a_{n-1}text{ otherwise}
end{cases}$
Does every positive integer occur exactly once in this sequence?
In 2004, Mateusz Kwasnicki provided positive proof in the same journal and in 2008, he published a more formal and (compared to the original question) a more general proof. He formulated the sequence with parameters $p$ and $q$:
$begin{cases}
a_1 = 1\
a_n = lfloor frac{a_{n-1}}{q} rfloortext{ if }lfloor frac{a_{n-1}}{q} rfloor notin {0, a_1, ... , a_{n-1}}\
a_n = p a_{n-1}text{ otherwise}
end{cases}$
He proved that for any $p, q>1$ such that $log_p(q)$ is irrational, the sequence is a permutation of the natural numbers. Since there are an infinite number of $p$ and $q$ values for which this is true, this is truly an entire world of permutations of the natural numbers. We will stick with the original $(p, q)=(3, 2)$, and for these paramters, the sequence can be found as A050000 in the OEIS. Its first 20 elements are:
1, 3, 9, 4, 2, 6, 18, 54, 27, 13, 39, 19, 57, 28, 14, 7, 21, 10, 5, 15
Since this is a "pure sequence" challenge, the task is to output $a(n)$ for a given $n$ as input, where $a(n)$ is A050000.
Task
Given an integer input $n$, output $a(n)$ in integer format, where:
$begin{cases}
a(1) = 1\
a(n) = lfloor frac{a(n-1)}{2} rfloortext{ if }lfloor frac{a(n-1)}{2} rfloor notin {0, a_1, ... , a(n-1)}\
a(n) = 3 a(n-1)text{ otherwise}
end{cases}$
Note: 1-based indexing is assumed here; you may use 0-based indexing, so $a(0) = 1; a(1) = 3$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
---------------
1 | 1
5 | 2
20 | 15
50 | 165
78 | 207
123 | 94
1234 | 3537
3000 | 2245
9999 | 4065
29890 | 149853
Rules
- Input and output are integers (your program should at least support input and output in the range of 1 up to 32767)
- Invalid input (0, floats, strings, negative values, etc.) may lead to unpredicted output, errors or (un)defined behaviour.
- Default I/O rules apply.
Default loopholes are forbidden.- This is code-golf, so the shortest answers in bytes wins
code-golf sequence
$endgroup$
add a comment |
$begingroup$
Introduction (may be ignored)
Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. This is the fourth challenge in this series (links to the first, second and third challenge).
In this challenge, we will explore not one permutation of the natural numbers, but an entire world of permutations!
In 2000, Clark Kimberling posed a problem in the 26th issue of Crux Mathematicorum, a scientific journal of mathematics published by the Canadian Mathematical Society. The problem was:
$text{Sequence }a = begin{cases}
a_1 = 1\
a_n = lfloor frac{a_{n-1}}{2} rfloortext{ if }lfloor frac{a_{n-1}}{2} rfloor notin {0, a_1, ... , a_{n-1}}\
a_n = 3 a_{n-1}text{ otherwise}
end{cases}$
Does every positive integer occur exactly once in this sequence?
In 2004, Mateusz Kwasnicki provided positive proof in the same journal and in 2008, he published a more formal and (compared to the original question) a more general proof. He formulated the sequence with parameters $p$ and $q$:
$begin{cases}
a_1 = 1\
a_n = lfloor frac{a_{n-1}}{q} rfloortext{ if }lfloor frac{a_{n-1}}{q} rfloor notin {0, a_1, ... , a_{n-1}}\
a_n = p a_{n-1}text{ otherwise}
end{cases}$
He proved that for any $p, q>1$ such that $log_p(q)$ is irrational, the sequence is a permutation of the natural numbers. Since there are an infinite number of $p$ and $q$ values for which this is true, this is truly an entire world of permutations of the natural numbers. We will stick with the original $(p, q)=(3, 2)$, and for these paramters, the sequence can be found as A050000 in the OEIS. Its first 20 elements are:
1, 3, 9, 4, 2, 6, 18, 54, 27, 13, 39, 19, 57, 28, 14, 7, 21, 10, 5, 15
Since this is a "pure sequence" challenge, the task is to output $a(n)$ for a given $n$ as input, where $a(n)$ is A050000.
Task
Given an integer input $n$, output $a(n)$ in integer format, where:
$begin{cases}
a(1) = 1\
a(n) = lfloor frac{a(n-1)}{2} rfloortext{ if }lfloor frac{a(n-1)}{2} rfloor notin {0, a_1, ... , a(n-1)}\
a(n) = 3 a(n-1)text{ otherwise}
end{cases}$
Note: 1-based indexing is assumed here; you may use 0-based indexing, so $a(0) = 1; a(1) = 3$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
---------------
1 | 1
5 | 2
20 | 15
50 | 165
78 | 207
123 | 94
1234 | 3537
3000 | 2245
9999 | 4065
29890 | 149853
Rules
- Input and output are integers (your program should at least support input and output in the range of 1 up to 32767)
- Invalid input (0, floats, strings, negative values, etc.) may lead to unpredicted output, errors or (un)defined behaviour.
- Default I/O rules apply.
Default loopholes are forbidden.- This is code-golf, so the shortest answers in bytes wins
code-golf sequence
$endgroup$
5
$begingroup$
In the second case of your formula, should it be not an element of?
$endgroup$
– xnor
1 hour ago
$begingroup$
Sharp! My mistake. Corrected it. Sorry if this caused any trouble or confusion.
$endgroup$
– agtoever
1 hour ago
add a comment |
$begingroup$
Introduction (may be ignored)
Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. This is the fourth challenge in this series (links to the first, second and third challenge).
In this challenge, we will explore not one permutation of the natural numbers, but an entire world of permutations!
In 2000, Clark Kimberling posed a problem in the 26th issue of Crux Mathematicorum, a scientific journal of mathematics published by the Canadian Mathematical Society. The problem was:
$text{Sequence }a = begin{cases}
a_1 = 1\
a_n = lfloor frac{a_{n-1}}{2} rfloortext{ if }lfloor frac{a_{n-1}}{2} rfloor notin {0, a_1, ... , a_{n-1}}\
a_n = 3 a_{n-1}text{ otherwise}
end{cases}$
Does every positive integer occur exactly once in this sequence?
In 2004, Mateusz Kwasnicki provided positive proof in the same journal and in 2008, he published a more formal and (compared to the original question) a more general proof. He formulated the sequence with parameters $p$ and $q$:
$begin{cases}
a_1 = 1\
a_n = lfloor frac{a_{n-1}}{q} rfloortext{ if }lfloor frac{a_{n-1}}{q} rfloor notin {0, a_1, ... , a_{n-1}}\
a_n = p a_{n-1}text{ otherwise}
end{cases}$
He proved that for any $p, q>1$ such that $log_p(q)$ is irrational, the sequence is a permutation of the natural numbers. Since there are an infinite number of $p$ and $q$ values for which this is true, this is truly an entire world of permutations of the natural numbers. We will stick with the original $(p, q)=(3, 2)$, and for these paramters, the sequence can be found as A050000 in the OEIS. Its first 20 elements are:
1, 3, 9, 4, 2, 6, 18, 54, 27, 13, 39, 19, 57, 28, 14, 7, 21, 10, 5, 15
Since this is a "pure sequence" challenge, the task is to output $a(n)$ for a given $n$ as input, where $a(n)$ is A050000.
Task
Given an integer input $n$, output $a(n)$ in integer format, where:
$begin{cases}
a(1) = 1\
a(n) = lfloor frac{a(n-1)}{2} rfloortext{ if }lfloor frac{a(n-1)}{2} rfloor notin {0, a_1, ... , a(n-1)}\
a(n) = 3 a(n-1)text{ otherwise}
end{cases}$
Note: 1-based indexing is assumed here; you may use 0-based indexing, so $a(0) = 1; a(1) = 3$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
---------------
1 | 1
5 | 2
20 | 15
50 | 165
78 | 207
123 | 94
1234 | 3537
3000 | 2245
9999 | 4065
29890 | 149853
Rules
- Input and output are integers (your program should at least support input and output in the range of 1 up to 32767)
- Invalid input (0, floats, strings, negative values, etc.) may lead to unpredicted output, errors or (un)defined behaviour.
- Default I/O rules apply.
Default loopholes are forbidden.- This is code-golf, so the shortest answers in bytes wins
code-golf sequence
$endgroup$
Introduction (may be ignored)
Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. This is the fourth challenge in this series (links to the first, second and third challenge).
In this challenge, we will explore not one permutation of the natural numbers, but an entire world of permutations!
In 2000, Clark Kimberling posed a problem in the 26th issue of Crux Mathematicorum, a scientific journal of mathematics published by the Canadian Mathematical Society. The problem was:
$text{Sequence }a = begin{cases}
a_1 = 1\
a_n = lfloor frac{a_{n-1}}{2} rfloortext{ if }lfloor frac{a_{n-1}}{2} rfloor notin {0, a_1, ... , a_{n-1}}\
a_n = 3 a_{n-1}text{ otherwise}
end{cases}$
Does every positive integer occur exactly once in this sequence?
In 2004, Mateusz Kwasnicki provided positive proof in the same journal and in 2008, he published a more formal and (compared to the original question) a more general proof. He formulated the sequence with parameters $p$ and $q$:
$begin{cases}
a_1 = 1\
a_n = lfloor frac{a_{n-1}}{q} rfloortext{ if }lfloor frac{a_{n-1}}{q} rfloor notin {0, a_1, ... , a_{n-1}}\
a_n = p a_{n-1}text{ otherwise}
end{cases}$
He proved that for any $p, q>1$ such that $log_p(q)$ is irrational, the sequence is a permutation of the natural numbers. Since there are an infinite number of $p$ and $q$ values for which this is true, this is truly an entire world of permutations of the natural numbers. We will stick with the original $(p, q)=(3, 2)$, and for these paramters, the sequence can be found as A050000 in the OEIS. Its first 20 elements are:
1, 3, 9, 4, 2, 6, 18, 54, 27, 13, 39, 19, 57, 28, 14, 7, 21, 10, 5, 15
Since this is a "pure sequence" challenge, the task is to output $a(n)$ for a given $n$ as input, where $a(n)$ is A050000.
Task
Given an integer input $n$, output $a(n)$ in integer format, where:
$begin{cases}
a(1) = 1\
a(n) = lfloor frac{a(n-1)}{2} rfloortext{ if }lfloor frac{a(n-1)}{2} rfloor notin {0, a_1, ... , a(n-1)}\
a(n) = 3 a(n-1)text{ otherwise}
end{cases}$
Note: 1-based indexing is assumed here; you may use 0-based indexing, so $a(0) = 1; a(1) = 3$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
---------------
1 | 1
5 | 2
20 | 15
50 | 165
78 | 207
123 | 94
1234 | 3537
3000 | 2245
9999 | 4065
29890 | 149853
Rules
- Input and output are integers (your program should at least support input and output in the range of 1 up to 32767)
- Invalid input (0, floats, strings, negative values, etc.) may lead to unpredicted output, errors or (un)defined behaviour.
- Default I/O rules apply.
Default loopholes are forbidden.- This is code-golf, so the shortest answers in bytes wins
code-golf sequence
code-golf sequence
edited 1 hour ago
agtoever
asked 1 hour ago
agtoeveragtoever
1,267422
1,267422
5
$begingroup$
In the second case of your formula, should it be not an element of?
$endgroup$
– xnor
1 hour ago
$begingroup$
Sharp! My mistake. Corrected it. Sorry if this caused any trouble or confusion.
$endgroup$
– agtoever
1 hour ago
add a comment |
5
$begingroup$
In the second case of your formula, should it be not an element of?
$endgroup$
– xnor
1 hour ago
$begingroup$
Sharp! My mistake. Corrected it. Sorry if this caused any trouble or confusion.
$endgroup$
– agtoever
1 hour ago
5
5
$begingroup$
In the second case of your formula, should it be not an element of?
$endgroup$
– xnor
1 hour ago
$begingroup$
In the second case of your formula, should it be not an element of?
$endgroup$
– xnor
1 hour ago
$begingroup$
Sharp! My mistake. Corrected it. Sorry if this caused any trouble or confusion.
$endgroup$
– agtoever
1 hour ago
$begingroup$
Sharp! My mistake. Corrected it. Sorry if this caused any trouble or confusion.
$endgroup$
– agtoever
1 hour ago
add a comment |
5 Answers
5
active
oldest
votes
$begingroup$
Jelly, 21 bytes
Ø.;0ị×3$:2$:2eɗ?Ɗ$⁸¡Ṫ
Try it online!
A monadic link that takes zero-indexed $n$ as the argument and returns $a(n)$.
$endgroup$
add a comment |
$begingroup$
J, 47 bytes
[:{:0 1((],<.@-:@{:@](3*{:@])`[@.(1-e.)])^:[)~]
Try it online!
standard formatting
[: {: 0 1 (] , <.@-:@{:@] (3 * {:@])`[@.(1 - e.) ])^:[~ ]
This is just a direct translation of the definition into J. It builds bottom up by using ^: to iterate from the starting value the required number of times.
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 67 bytes
(L=Last)@Nest[#~Join~{If[FreeQ[#,x=⌊L@#/2⌋],x,3L@#]}&,{0,1},#]&
Try it online!
This is 0-indexed
(In TIO I added -1 in every test case)
$endgroup$
add a comment |
$begingroup$
Jelly, 15 bytes
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ
A full program accepting the integer, n (1-based), from STDIN which prints the result.
Try it online!
How?
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ - Main Link: no arguments (implicit left argument = 0)
µ µ¡ - repeat this monadic chain STDIN times (starting with x=0)
- e.g. x = ... 0 [1,0] [9,3,1,0]
×3 - multiply by 3 0 [3,0] [27,9,3,0]
H - halve 0 [1.5,0] [4.5,1.5,0.5,0]
ż - zip together [0,0] [[3,1.5],[0,0]] [[27,4.5],[9,1.5],[3,0.5],[0,0]]
Ḟ - floor [0,0] [[3,1],[0,0]] [[27,4],[9,1],[3,0],[0,0]]
Ḣ - head 0 [3,1] [27,4]
ḟ - filter discard if in x [] [3] [27,4]
ȯ1 - logical OR with 1 1 [3] [27,4]
Ṫ - tail 1 3 4
; - concatenate with x [1,0] [3,1,0] [4,9,3,1,0]
Ḣ - head 1 3 4
- implicit print
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 55 51 bytes
Saved 1 byte thanks to @EmbodimentofIgnorance
n=>eval("for(o=[p=2];n--;o[p]=1)p=o[q=p>>1]?3*p:q")
Try it online!
$endgroup$
$begingroup$
55 bytes
$endgroup$
– Embodiment of Ignorance
53 mins ago
$begingroup$
@EmbodimentofIgnorance I usually avoid that trick, as the eval'ed code is much slower. But the difference is barely noticeable for that one, so I guess that's fine.
$endgroup$
– Arnauld
45 mins ago
$begingroup$
But this is code-golf, we don't care about speed, as long as it gets the job done
$endgroup$
– Embodiment of Ignorance
39 mins ago
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');
});
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%2f182810%2fnew-order-4-world%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Jelly, 21 bytes
Ø.;0ị×3$:2$:2eɗ?Ɗ$⁸¡Ṫ
Try it online!
A monadic link that takes zero-indexed $n$ as the argument and returns $a(n)$.
$endgroup$
add a comment |
$begingroup$
Jelly, 21 bytes
Ø.;0ị×3$:2$:2eɗ?Ɗ$⁸¡Ṫ
Try it online!
A monadic link that takes zero-indexed $n$ as the argument and returns $a(n)$.
$endgroup$
add a comment |
$begingroup$
Jelly, 21 bytes
Ø.;0ị×3$:2$:2eɗ?Ɗ$⁸¡Ṫ
Try it online!
A monadic link that takes zero-indexed $n$ as the argument and returns $a(n)$.
$endgroup$
Jelly, 21 bytes
Ø.;0ị×3$:2$:2eɗ?Ɗ$⁸¡Ṫ
Try it online!
A monadic link that takes zero-indexed $n$ as the argument and returns $a(n)$.
answered 53 mins ago
Nick KennedyNick Kennedy
1,32649
1,32649
add a comment |
add a comment |
$begingroup$
J, 47 bytes
[:{:0 1((],<.@-:@{:@](3*{:@])`[@.(1-e.)])^:[)~]
Try it online!
standard formatting
[: {: 0 1 (] , <.@-:@{:@] (3 * {:@])`[@.(1 - e.) ])^:[~ ]
This is just a direct translation of the definition into J. It builds bottom up by using ^: to iterate from the starting value the required number of times.
$endgroup$
add a comment |
$begingroup$
J, 47 bytes
[:{:0 1((],<.@-:@{:@](3*{:@])`[@.(1-e.)])^:[)~]
Try it online!
standard formatting
[: {: 0 1 (] , <.@-:@{:@] (3 * {:@])`[@.(1 - e.) ])^:[~ ]
This is just a direct translation of the definition into J. It builds bottom up by using ^: to iterate from the starting value the required number of times.
$endgroup$
add a comment |
$begingroup$
J, 47 bytes
[:{:0 1((],<.@-:@{:@](3*{:@])`[@.(1-e.)])^:[)~]
Try it online!
standard formatting
[: {: 0 1 (] , <.@-:@{:@] (3 * {:@])`[@.(1 - e.) ])^:[~ ]
This is just a direct translation of the definition into J. It builds bottom up by using ^: to iterate from the starting value the required number of times.
$endgroup$
J, 47 bytes
[:{:0 1((],<.@-:@{:@](3*{:@])`[@.(1-e.)])^:[)~]
Try it online!
standard formatting
[: {: 0 1 (] , <.@-:@{:@] (3 * {:@])`[@.(1 - e.) ])^:[~ ]
This is just a direct translation of the definition into J. It builds bottom up by using ^: to iterate from the starting value the required number of times.
edited 26 mins ago
answered 44 mins ago
JonahJonah
2,5911017
2,5911017
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 67 bytes
(L=Last)@Nest[#~Join~{If[FreeQ[#,x=⌊L@#/2⌋],x,3L@#]}&,{0,1},#]&
Try it online!
This is 0-indexed
(In TIO I added -1 in every test case)
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 67 bytes
(L=Last)@Nest[#~Join~{If[FreeQ[#,x=⌊L@#/2⌋],x,3L@#]}&,{0,1},#]&
Try it online!
This is 0-indexed
(In TIO I added -1 in every test case)
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 67 bytes
(L=Last)@Nest[#~Join~{If[FreeQ[#,x=⌊L@#/2⌋],x,3L@#]}&,{0,1},#]&
Try it online!
This is 0-indexed
(In TIO I added -1 in every test case)
$endgroup$
Wolfram Language (Mathematica), 67 bytes
(L=Last)@Nest[#~Join~{If[FreeQ[#,x=⌊L@#/2⌋],x,3L@#]}&,{0,1},#]&
Try it online!
This is 0-indexed
(In TIO I added -1 in every test case)
edited 16 mins ago
answered 56 mins ago
J42161217J42161217
13.8k21253
13.8k21253
add a comment |
add a comment |
$begingroup$
Jelly, 15 bytes
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ
A full program accepting the integer, n (1-based), from STDIN which prints the result.
Try it online!
How?
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ - Main Link: no arguments (implicit left argument = 0)
µ µ¡ - repeat this monadic chain STDIN times (starting with x=0)
- e.g. x = ... 0 [1,0] [9,3,1,0]
×3 - multiply by 3 0 [3,0] [27,9,3,0]
H - halve 0 [1.5,0] [4.5,1.5,0.5,0]
ż - zip together [0,0] [[3,1.5],[0,0]] [[27,4.5],[9,1.5],[3,0.5],[0,0]]
Ḟ - floor [0,0] [[3,1],[0,0]] [[27,4],[9,1],[3,0],[0,0]]
Ḣ - head 0 [3,1] [27,4]
ḟ - filter discard if in x [] [3] [27,4]
ȯ1 - logical OR with 1 1 [3] [27,4]
Ṫ - tail 1 3 4
; - concatenate with x [1,0] [3,1,0] [4,9,3,1,0]
Ḣ - head 1 3 4
- implicit print
$endgroup$
add a comment |
$begingroup$
Jelly, 15 bytes
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ
A full program accepting the integer, n (1-based), from STDIN which prints the result.
Try it online!
How?
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ - Main Link: no arguments (implicit left argument = 0)
µ µ¡ - repeat this monadic chain STDIN times (starting with x=0)
- e.g. x = ... 0 [1,0] [9,3,1,0]
×3 - multiply by 3 0 [3,0] [27,9,3,0]
H - halve 0 [1.5,0] [4.5,1.5,0.5,0]
ż - zip together [0,0] [[3,1.5],[0,0]] [[27,4.5],[9,1.5],[3,0.5],[0,0]]
Ḟ - floor [0,0] [[3,1],[0,0]] [[27,4],[9,1],[3,0],[0,0]]
Ḣ - head 0 [3,1] [27,4]
ḟ - filter discard if in x [] [3] [27,4]
ȯ1 - logical OR with 1 1 [3] [27,4]
Ṫ - tail 1 3 4
; - concatenate with x [1,0] [3,1,0] [4,9,3,1,0]
Ḣ - head 1 3 4
- implicit print
$endgroup$
add a comment |
$begingroup$
Jelly, 15 bytes
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ
A full program accepting the integer, n (1-based), from STDIN which prints the result.
Try it online!
How?
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ - Main Link: no arguments (implicit left argument = 0)
µ µ¡ - repeat this monadic chain STDIN times (starting with x=0)
- e.g. x = ... 0 [1,0] [9,3,1,0]
×3 - multiply by 3 0 [3,0] [27,9,3,0]
H - halve 0 [1.5,0] [4.5,1.5,0.5,0]
ż - zip together [0,0] [[3,1.5],[0,0]] [[27,4.5],[9,1.5],[3,0.5],[0,0]]
Ḟ - floor [0,0] [[3,1],[0,0]] [[27,4],[9,1],[3,0],[0,0]]
Ḣ - head 0 [3,1] [27,4]
ḟ - filter discard if in x [] [3] [27,4]
ȯ1 - logical OR with 1 1 [3] [27,4]
Ṫ - tail 1 3 4
; - concatenate with x [1,0] [3,1,0] [4,9,3,1,0]
Ḣ - head 1 3 4
- implicit print
$endgroup$
Jelly, 15 bytes
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ
A full program accepting the integer, n (1-based), from STDIN which prints the result.
Try it online!
How?
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ - Main Link: no arguments (implicit left argument = 0)
µ µ¡ - repeat this monadic chain STDIN times (starting with x=0)
- e.g. x = ... 0 [1,0] [9,3,1,0]
×3 - multiply by 3 0 [3,0] [27,9,3,0]
H - halve 0 [1.5,0] [4.5,1.5,0.5,0]
ż - zip together [0,0] [[3,1.5],[0,0]] [[27,4.5],[9,1.5],[3,0.5],[0,0]]
Ḟ - floor [0,0] [[3,1],[0,0]] [[27,4],[9,1],[3,0],[0,0]]
Ḣ - head 0 [3,1] [27,4]
ḟ - filter discard if in x [] [3] [27,4]
ȯ1 - logical OR with 1 1 [3] [27,4]
Ṫ - tail 1 3 4
; - concatenate with x [1,0] [3,1,0] [4,9,3,1,0]
Ḣ - head 1 3 4
- implicit print
answered 15 mins ago
Jonathan AllanJonathan Allan
53.7k535173
53.7k535173
add a comment |
add a comment |
$begingroup$
JavaScript (ES6), 55 51 bytes
Saved 1 byte thanks to @EmbodimentofIgnorance
n=>eval("for(o=[p=2];n--;o[p]=1)p=o[q=p>>1]?3*p:q")
Try it online!
$endgroup$
$begingroup$
55 bytes
$endgroup$
– Embodiment of Ignorance
53 mins ago
$begingroup$
@EmbodimentofIgnorance I usually avoid that trick, as the eval'ed code is much slower. But the difference is barely noticeable for that one, so I guess that's fine.
$endgroup$
– Arnauld
45 mins ago
$begingroup$
But this is code-golf, we don't care about speed, as long as it gets the job done
$endgroup$
– Embodiment of Ignorance
39 mins ago
add a comment |
$begingroup$
JavaScript (ES6), 55 51 bytes
Saved 1 byte thanks to @EmbodimentofIgnorance
n=>eval("for(o=[p=2];n--;o[p]=1)p=o[q=p>>1]?3*p:q")
Try it online!
$endgroup$
$begingroup$
55 bytes
$endgroup$
– Embodiment of Ignorance
53 mins ago
$begingroup$
@EmbodimentofIgnorance I usually avoid that trick, as the eval'ed code is much slower. But the difference is barely noticeable for that one, so I guess that's fine.
$endgroup$
– Arnauld
45 mins ago
$begingroup$
But this is code-golf, we don't care about speed, as long as it gets the job done
$endgroup$
– Embodiment of Ignorance
39 mins ago
add a comment |
$begingroup$
JavaScript (ES6), 55 51 bytes
Saved 1 byte thanks to @EmbodimentofIgnorance
n=>eval("for(o=[p=2];n--;o[p]=1)p=o[q=p>>1]?3*p:q")
Try it online!
$endgroup$
JavaScript (ES6), 55 51 bytes
Saved 1 byte thanks to @EmbodimentofIgnorance
n=>eval("for(o=[p=2];n--;o[p]=1)p=o[q=p>>1]?3*p:q")
Try it online!
edited 13 mins ago
answered 1 hour ago
ArnauldArnauld
80.5k797333
80.5k797333
$begingroup$
55 bytes
$endgroup$
– Embodiment of Ignorance
53 mins ago
$begingroup$
@EmbodimentofIgnorance I usually avoid that trick, as the eval'ed code is much slower. But the difference is barely noticeable for that one, so I guess that's fine.
$endgroup$
– Arnauld
45 mins ago
$begingroup$
But this is code-golf, we don't care about speed, as long as it gets the job done
$endgroup$
– Embodiment of Ignorance
39 mins ago
add a comment |
$begingroup$
55 bytes
$endgroup$
– Embodiment of Ignorance
53 mins ago
$begingroup$
@EmbodimentofIgnorance I usually avoid that trick, as the eval'ed code is much slower. But the difference is barely noticeable for that one, so I guess that's fine.
$endgroup$
– Arnauld
45 mins ago
$begingroup$
But this is code-golf, we don't care about speed, as long as it gets the job done
$endgroup$
– Embodiment of Ignorance
39 mins ago
$begingroup$
55 bytes
$endgroup$
– Embodiment of Ignorance
53 mins ago
$begingroup$
55 bytes
$endgroup$
– Embodiment of Ignorance
53 mins ago
$begingroup$
@EmbodimentofIgnorance I usually avoid that trick, as the eval'ed code is much slower. But the difference is barely noticeable for that one, so I guess that's fine.
$endgroup$
– Arnauld
45 mins ago
$begingroup$
@EmbodimentofIgnorance I usually avoid that trick, as the eval'ed code is much slower. But the difference is barely noticeable for that one, so I guess that's fine.
$endgroup$
– Arnauld
45 mins ago
$begingroup$
But this is code-golf, we don't care about speed, as long as it gets the job done
$endgroup$
– Embodiment of Ignorance
39 mins ago
$begingroup$
But this is code-golf, we don't care about speed, as long as it gets the job done
$endgroup$
– Embodiment of Ignorance
39 mins ago
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');
});
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%2f182810%2fnew-order-4-world%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');
});
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');
});
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');
});
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
5
$begingroup$
In the second case of your formula, should it be not an element of?
$endgroup$
– xnor
1 hour ago
$begingroup$
Sharp! My mistake. Corrected it. Sorry if this caused any trouble or confusion.
$endgroup$
– agtoever
1 hour ago