New Order #6: Easter Egg Announcing the arrival of Valued Associate #679: Cesar Manara ...
retrieve food groups from food item list
How do living politicians protect their readily obtainable signatures from misuse?
Does the Black Tentacles spell do damage twice at the start of turn to an already restrained creature?
Understanding p-Values using an example
How to force a browser when connecting to a specific domain to be https only using only the client machine?
Is it dangerous to install hacking tools on my private linux machine?
What to do with repeated rejections for phd position
Why is a lens darker than other ones when applying the same settings?
Test print coming out spongy
What is the difference between a "ranged attack" and a "ranged weapon attack"?
A proverb that is used to imply that you have unexpectedly faced a big problem
Why does electrolysis of aqueous concentrated sodium bromide produce bromine at the anode?
How does light 'choose' between wave and particle behaviour?
Google .dev domain strangely redirects to https
What initially awakened the Balrog?
Resize vertical bars (absolute-value symbols)
Why are vacuum tubes still used in amateur radios?
Putting class ranking in CV, but against dept guidelines
New Order #6: Easter Egg
Relating to the President and obstruction, were Mueller's conclusions preordained?
What is the "studentd" process?
One-one communication
What does this say in Elvish?
How can a team of shapeshifters communicate?
New Order #6: Easter Egg
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
The PPCG Site design is on its way - help us make it awesome!
Sandbox for Proposed ChallengesNew order #4: WorldNew Order #2: Turn My WayNew Order #1: How does this feel?New Order #5: where Fibonacci and Beatty meet at WythoffNew Order #3: 5 8 6Challenge UlamspiralFind the angle between two pointsTriangular Ulam spiralAsterisk spiralReturn Spiral Indexes!New Order #1: How does this feel?New Order #2: Turn My WayNew Order #3: 5 8 6New order #4: WorldNew Order #5: where Fibonacci and Beatty meet at Wythoff
$begingroup$
Introduction (may be ignored)
Putting all positive integers 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 integers. This is the sixth challenge in this series (links to the first, second, third, fourth and fifth challenge).
This challenge has a mild Easter theme (because it's Easter). I took my inspiration from this highly decorated (and in my personal opinion rather ugly) goose egg.

It reminded me of the Ulam spiral, where all positive integers are placed in a counter-clockwise spiral. This spiral has some interesting features related to prime numbers, but that's not relevant for this challenge.

We get to this challenge's permutation of positive integers if we take the numbers in the Ulam spiral and trace all integers in a clockwise turning spiral, starting at 1. This way, we get:
1, 6, 5, 4, 3, 2, 9, 8, 7, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 25, 24, 23, etc.
If you would draw both of the spirals, you'd get some sort of an infinite mesh of (egg shell) spirals (note the New Order reference there).
This sequence is present in the OEIS under number A090861. Since this is a "pure sequence" challenge, the task is to output $a(n)$ for a given $n$ as input, where $a(n)$ is A090861.
Task
Given an integer input $n$, output $a(n)$ in integer format, where $a(n)$ is A090861.
Note: 1-based indexing is assumed here; you may use 0-based indexing, so $a(0) = 1; a(1) = 6$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
---------------
1 | 1
5 | 3
20 | 10
50 | 72
78 | 76
123 | 155
1234 | 1324
3000 | 2996
9999 | 9903
29890 | 29796
Rules
- Input and output are integers.
- Your program should at least support input 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 integers 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 integers. This is the sixth challenge in this series (links to the first, second, third, fourth and fifth challenge).
This challenge has a mild Easter theme (because it's Easter). I took my inspiration from this highly decorated (and in my personal opinion rather ugly) goose egg.

It reminded me of the Ulam spiral, where all positive integers are placed in a counter-clockwise spiral. This spiral has some interesting features related to prime numbers, but that's not relevant for this challenge.

We get to this challenge's permutation of positive integers if we take the numbers in the Ulam spiral and trace all integers in a clockwise turning spiral, starting at 1. This way, we get:
1, 6, 5, 4, 3, 2, 9, 8, 7, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 25, 24, 23, etc.
If you would draw both of the spirals, you'd get some sort of an infinite mesh of (egg shell) spirals (note the New Order reference there).
This sequence is present in the OEIS under number A090861. Since this is a "pure sequence" challenge, the task is to output $a(n)$ for a given $n$ as input, where $a(n)$ is A090861.
Task
Given an integer input $n$, output $a(n)$ in integer format, where $a(n)$ is A090861.
Note: 1-based indexing is assumed here; you may use 0-based indexing, so $a(0) = 1; a(1) = 6$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
---------------
1 | 1
5 | 3
20 | 10
50 | 72
78 | 76
123 | 155
1234 | 1324
3000 | 2996
9999 | 9903
29890 | 29796
Rules
- Input and output are integers.
- Your program should at least support input 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 integers 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 integers. This is the sixth challenge in this series (links to the first, second, third, fourth and fifth challenge).
This challenge has a mild Easter theme (because it's Easter). I took my inspiration from this highly decorated (and in my personal opinion rather ugly) goose egg.

It reminded me of the Ulam spiral, where all positive integers are placed in a counter-clockwise spiral. This spiral has some interesting features related to prime numbers, but that's not relevant for this challenge.

We get to this challenge's permutation of positive integers if we take the numbers in the Ulam spiral and trace all integers in a clockwise turning spiral, starting at 1. This way, we get:
1, 6, 5, 4, 3, 2, 9, 8, 7, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 25, 24, 23, etc.
If you would draw both of the spirals, you'd get some sort of an infinite mesh of (egg shell) spirals (note the New Order reference there).
This sequence is present in the OEIS under number A090861. Since this is a "pure sequence" challenge, the task is to output $a(n)$ for a given $n$ as input, where $a(n)$ is A090861.
Task
Given an integer input $n$, output $a(n)$ in integer format, where $a(n)$ is A090861.
Note: 1-based indexing is assumed here; you may use 0-based indexing, so $a(0) = 1; a(1) = 6$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
---------------
1 | 1
5 | 3
20 | 10
50 | 72
78 | 76
123 | 155
1234 | 1324
3000 | 2996
9999 | 9903
29890 | 29796
Rules
- Input and output are integers.
- Your program should at least support input 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 integers 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 integers. This is the sixth challenge in this series (links to the first, second, third, fourth and fifth challenge).
This challenge has a mild Easter theme (because it's Easter). I took my inspiration from this highly decorated (and in my personal opinion rather ugly) goose egg.

It reminded me of the Ulam spiral, where all positive integers are placed in a counter-clockwise spiral. This spiral has some interesting features related to prime numbers, but that's not relevant for this challenge.

We get to this challenge's permutation of positive integers if we take the numbers in the Ulam spiral and trace all integers in a clockwise turning spiral, starting at 1. This way, we get:
1, 6, 5, 4, 3, 2, 9, 8, 7, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 25, 24, 23, etc.
If you would draw both of the spirals, you'd get some sort of an infinite mesh of (egg shell) spirals (note the New Order reference there).
This sequence is present in the OEIS under number A090861. Since this is a "pure sequence" challenge, the task is to output $a(n)$ for a given $n$ as input, where $a(n)$ is A090861.
Task
Given an integer input $n$, output $a(n)$ in integer format, where $a(n)$ is A090861.
Note: 1-based indexing is assumed here; you may use 0-based indexing, so $a(0) = 1; a(1) = 6$, etc. Please mention this in your answer if you choose to use this.
Test cases
Input | Output
---------------
1 | 1
5 | 3
20 | 10
50 | 72
78 | 76
123 | 155
1234 | 1324
3000 | 2996
9999 | 9903
29890 | 29796
Rules
- Input and output are integers.
- Your program should at least support input 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
asked 2 hours ago
agtoeveragtoever
1,421425
1,421425
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
$begingroup$
Wolfram Language (Mathematica), 60 bytes
8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 67 bytes
n=>8*(x=(int)Math.Sqrt(--n)+1>>1)*x+(n<4*x*x+2*x?-2:6)*x+1-n;int x;
Try it online!
$endgroup$
add a comment |
$begingroup$
MATL, 12 bytes
Eq1YL!tPwG=)
Try it online!
Very memory-inefficient. Prepending X^k makes it more efficient.
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 46 45 41 bytes
0-indexed.
n=>((x=n**.5+1&~1)*2-(n<x*x+x)*4+3)*x+1-n
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 16 14 bytes
R×’¥Ðe3ÄRUẎQị@
A monadic Link accepting an integer, n, which yields an integer, a(n).
Try it online! (very inefficient)
Much quicker, but still fairly inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@
How?
The permutation is to take the natural numbers in reversed slices of lengths [1,5,3,11,5,17,7,23,9,29,11,35,13,...] - the odd positive integers interspersed with the positive integers congruent to five modulo six. i.e [1, 2*3-1, 3, 4*3-1, 5, 6*3-1, 7, 8*3-1, 9, ...]
The Link constructs the first n of these slice lengths and then slices up as many of the positive integers as necessary, flattens them and yields the one at index n.
$endgroup$
add a comment |
Your Answer
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%2f183528%2fnew-order-6-easter-egg%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$
Wolfram Language (Mathematica), 60 bytes
8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 60 bytes
8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 60 bytes
8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 60 bytes
8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&
Try it online!
answered 1 hour ago
J42161217J42161217
14.3k21354
14.3k21354
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 67 bytes
n=>8*(x=(int)Math.Sqrt(--n)+1>>1)*x+(n<4*x*x+2*x?-2:6)*x+1-n;int x;
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 67 bytes
n=>8*(x=(int)Math.Sqrt(--n)+1>>1)*x+(n<4*x*x+2*x?-2:6)*x+1-n;int x;
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 67 bytes
n=>8*(x=(int)Math.Sqrt(--n)+1>>1)*x+(n<4*x*x+2*x?-2:6)*x+1-n;int x;
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 67 bytes
n=>8*(x=(int)Math.Sqrt(--n)+1>>1)*x+(n<4*x*x+2*x?-2:6)*x+1-n;int x;
Try it online!
edited 1 hour ago
answered 1 hour ago
Embodiment of IgnoranceEmbodiment of Ignorance
3,044127
3,044127
add a comment |
add a comment |
$begingroup$
MATL, 12 bytes
Eq1YL!tPwG=)
Try it online!
Very memory-inefficient. Prepending X^k makes it more efficient.
$endgroup$
add a comment |
$begingroup$
MATL, 12 bytes
Eq1YL!tPwG=)
Try it online!
Very memory-inefficient. Prepending X^k makes it more efficient.
$endgroup$
add a comment |
$begingroup$
MATL, 12 bytes
Eq1YL!tPwG=)
Try it online!
Very memory-inefficient. Prepending X^k makes it more efficient.
$endgroup$
MATL, 12 bytes
Eq1YL!tPwG=)
Try it online!
Very memory-inefficient. Prepending X^k makes it more efficient.
answered 1 hour ago
Luis MendoLuis Mendo
75.5k889293
75.5k889293
add a comment |
add a comment |
$begingroup$
JavaScript (ES7), 46 45 41 bytes
0-indexed.
n=>((x=n**.5+1&~1)*2-(n<x*x+x)*4+3)*x+1-n
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 46 45 41 bytes
0-indexed.
n=>((x=n**.5+1&~1)*2-(n<x*x+x)*4+3)*x+1-n
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES7), 46 45 41 bytes
0-indexed.
n=>((x=n**.5+1&~1)*2-(n<x*x+x)*4+3)*x+1-n
Try it online!
$endgroup$
JavaScript (ES7), 46 45 41 bytes
0-indexed.
n=>((x=n**.5+1&~1)*2-(n<x*x+x)*4+3)*x+1-n
Try it online!
edited 57 mins ago
answered 1 hour ago
ArnauldArnauld
81.7k798337
81.7k798337
add a comment |
add a comment |
$begingroup$
Jelly, 16 14 bytes
R×’¥Ðe3ÄRUẎQị@
A monadic Link accepting an integer, n, which yields an integer, a(n).
Try it online! (very inefficient)
Much quicker, but still fairly inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@
How?
The permutation is to take the natural numbers in reversed slices of lengths [1,5,3,11,5,17,7,23,9,29,11,35,13,...] - the odd positive integers interspersed with the positive integers congruent to five modulo six. i.e [1, 2*3-1, 3, 4*3-1, 5, 6*3-1, 7, 8*3-1, 9, ...]
The Link constructs the first n of these slice lengths and then slices up as many of the positive integers as necessary, flattens them and yields the one at index n.
$endgroup$
add a comment |
$begingroup$
Jelly, 16 14 bytes
R×’¥Ðe3ÄRUẎQị@
A monadic Link accepting an integer, n, which yields an integer, a(n).
Try it online! (very inefficient)
Much quicker, but still fairly inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@
How?
The permutation is to take the natural numbers in reversed slices of lengths [1,5,3,11,5,17,7,23,9,29,11,35,13,...] - the odd positive integers interspersed with the positive integers congruent to five modulo six. i.e [1, 2*3-1, 3, 4*3-1, 5, 6*3-1, 7, 8*3-1, 9, ...]
The Link constructs the first n of these slice lengths and then slices up as many of the positive integers as necessary, flattens them and yields the one at index n.
$endgroup$
add a comment |
$begingroup$
Jelly, 16 14 bytes
R×’¥Ðe3ÄRUẎQị@
A monadic Link accepting an integer, n, which yields an integer, a(n).
Try it online! (very inefficient)
Much quicker, but still fairly inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@
How?
The permutation is to take the natural numbers in reversed slices of lengths [1,5,3,11,5,17,7,23,9,29,11,35,13,...] - the odd positive integers interspersed with the positive integers congruent to five modulo six. i.e [1, 2*3-1, 3, 4*3-1, 5, 6*3-1, 7, 8*3-1, 9, ...]
The Link constructs the first n of these slice lengths and then slices up as many of the positive integers as necessary, flattens them and yields the one at index n.
$endgroup$
Jelly, 16 14 bytes
R×’¥Ðe3ÄRUẎQị@
A monadic Link accepting an integer, n, which yields an integer, a(n).
Try it online! (very inefficient)
Much quicker, but still fairly inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@
How?
The permutation is to take the natural numbers in reversed slices of lengths [1,5,3,11,5,17,7,23,9,29,11,35,13,...] - the odd positive integers interspersed with the positive integers congruent to five modulo six. i.e [1, 2*3-1, 3, 4*3-1, 5, 6*3-1, 7, 8*3-1, 9, ...]
The Link constructs the first n of these slice lengths and then slices up as many of the positive integers as necessary, flattens them and yields the one at index n.
edited 7 mins ago
answered 1 hour ago
Jonathan AllanJonathan Allan
54.7k537175
54.7k537175
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');
});
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%2f183528%2fnew-order-6-easter-egg%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