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

Omitting the following parentheses

Tips to organize LaTeX presentations for a semester

Monty Hall Problem-Probability Paradox

What does this say in Elvish?

A term for a woman complaining about things/begging in a cute/childish way

Is multiple magic items in one inherently imbalanced?

How many morphisms from 1 to 1+1 can there be?

How could we fake a moon landing now?

What would you call this weird metallic apparatus that allows you to lift people?

What does it mean that physics no longer uses mechanical models to describe phenomena?

Why is std::move not [[nodiscard]] in C++20?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

The test team as an enemy of development? And how can this be avoided?

How to ternary Plot3D a function

How does the math work when buying airline miles?

Why are vacuum tubes still used in amateur radios?

Does the Mueller report show a conspiracy between Russia and the Trump Campaign?

RSA find public exponent

One-one communication

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

Is openssl rand command cryptographically secure?

Project Euler #1 in C++

Did any compiler fully use 80-bit floating point?



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










3












$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.



Decorated 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.



Ulam spiral



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









share|improve this question









$endgroup$
















    3












    $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.



    Decorated 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.



    Ulam spiral



    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









    share|improve this question









    $endgroup$














      3












      3








      3





      $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.



      Decorated 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.



      Ulam spiral



      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









      share|improve this question









      $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.



      Decorated 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.



      Ulam spiral



      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      agtoeveragtoever

      1,421425




      1,421425




















          5 Answers
          5






          active

          oldest

          votes


















          1












          $begingroup$


          Wolfram Language (Mathematica), 60 bytes



          8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&


          Try it online!






          share|improve this answer









          $endgroup$




















            1












            $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!






            share|improve this answer











            $endgroup$




















              1












              $begingroup$


              MATL, 12 bytes



              Eq1YL!tPwG=)


              Try it online!



              Very memory-inefficient. Prepending X^k makes it more efficient.






              share|improve this answer









              $endgroup$




















                1












                $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!






                share|improve this answer











                $endgroup$




















                  1












                  $begingroup$


                  Jelly,  16  14 bytes



                  2,6×Ɱ’ẎÄRUẎQị@


                  A monadic Link accepting an integer, n, which yields an integer, a(n).



                  Try it online! (very inefficient)



                  Quicker, but still inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@






                  share|improve this answer











                  $endgroup$













                    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
                    );



                    );













                    draft saved

                    draft discarded


















                    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









                    1












                    $begingroup$


                    Wolfram Language (Mathematica), 60 bytes



                    8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&


                    Try it online!






                    share|improve this answer









                    $endgroup$

















                      1












                      $begingroup$


                      Wolfram Language (Mathematica), 60 bytes



                      8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&


                      Try it online!






                      share|improve this answer









                      $endgroup$















                        1












                        1








                        1





                        $begingroup$


                        Wolfram Language (Mathematica), 60 bytes



                        8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&


                        Try it online!






                        share|improve this answer









                        $endgroup$




                        Wolfram Language (Mathematica), 60 bytes



                        8(s=⌊(⌊Sqrt[#-1]⌋+1)/2⌋)^2-#+2+If[#<=4s^2+2s,-2,6]s&


                        Try it online!







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 1 hour ago









                        J42161217J42161217

                        14.3k21354




                        14.3k21354





















                            1












                            $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!






                            share|improve this answer











                            $endgroup$

















                              1












                              $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!






                              share|improve this answer











                              $endgroup$















                                1












                                1








                                1





                                $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!






                                share|improve this answer











                                $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!







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 40 mins ago

























                                answered 52 mins ago









                                Embodiment of IgnoranceEmbodiment of Ignorance

                                3,044127




                                3,044127





















                                    1












                                    $begingroup$


                                    MATL, 12 bytes



                                    Eq1YL!tPwG=)


                                    Try it online!



                                    Very memory-inefficient. Prepending X^k makes it more efficient.






                                    share|improve this answer









                                    $endgroup$

















                                      1












                                      $begingroup$


                                      MATL, 12 bytes



                                      Eq1YL!tPwG=)


                                      Try it online!



                                      Very memory-inefficient. Prepending X^k makes it more efficient.






                                      share|improve this answer









                                      $endgroup$















                                        1












                                        1








                                        1





                                        $begingroup$


                                        MATL, 12 bytes



                                        Eq1YL!tPwG=)


                                        Try it online!



                                        Very memory-inefficient. Prepending X^k makes it more efficient.






                                        share|improve this answer









                                        $endgroup$




                                        MATL, 12 bytes



                                        Eq1YL!tPwG=)


                                        Try it online!



                                        Very memory-inefficient. Prepending X^k makes it more efficient.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 31 mins ago









                                        Luis MendoLuis Mendo

                                        75.5k889293




                                        75.5k889293





















                                            1












                                            $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!






                                            share|improve this answer











                                            $endgroup$

















                                              1












                                              $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!






                                              share|improve this answer











                                              $endgroup$















                                                1












                                                1








                                                1





                                                $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!






                                                share|improve this answer











                                                $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!







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited 17 mins ago

























                                                answered 42 mins ago









                                                ArnauldArnauld

                                                81.7k798337




                                                81.7k798337





















                                                    1












                                                    $begingroup$


                                                    Jelly,  16  14 bytes



                                                    2,6×Ɱ’ẎÄRUẎQị@


                                                    A monadic Link accepting an integer, n, which yields an integer, a(n).



                                                    Try it online! (very inefficient)



                                                    Quicker, but still inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@






                                                    share|improve this answer











                                                    $endgroup$

















                                                      1












                                                      $begingroup$


                                                      Jelly,  16  14 bytes



                                                      2,6×Ɱ’ẎÄRUẎQị@


                                                      A monadic Link accepting an integer, n, which yields an integer, a(n).



                                                      Try it online! (very inefficient)



                                                      Quicker, but still inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@






                                                      share|improve this answer











                                                      $endgroup$















                                                        1












                                                        1








                                                        1





                                                        $begingroup$


                                                        Jelly,  16  14 bytes



                                                        2,6×Ɱ’ẎÄRUẎQị@


                                                        A monadic Link accepting an integer, n, which yields an integer, a(n).



                                                        Try it online! (very inefficient)



                                                        Quicker, but still inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@






                                                        share|improve this answer











                                                        $endgroup$




                                                        Jelly,  16  14 bytes



                                                        2,6×Ɱ’ẎÄRUẎQị@


                                                        A monadic Link accepting an integer, n, which yields an integer, a(n).



                                                        Try it online! (very inefficient)



                                                        Quicker, but still inefficient for 15 is 2,6×Ɱ’RẎJṁƊUFị@







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited 11 mins ago

























                                                        answered 30 mins ago









                                                        Jonathan AllanJonathan Allan

                                                        54.7k537175




                                                        54.7k537175



























                                                            draft saved

                                                            draft discarded
















































                                                            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).




                                                            draft saved


                                                            draft discarded














                                                            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





















































                                                            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