Half, Half Half, and, Half

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
8
down vote

favorite












Consider the following number sequence:




$ 0, frac12, frac14, frac34, frac18, frac38, frac58, frac78, frac116, frac316, frac516, frac716, frac916, frac1116, frac1316, frac1516, frac132, frac332, frac532, dots $




It enumerates all binary fractions in the unit interval $ [0, 1) $.



(To make this challenge easier, the first element is optional: You may skip it and consider the sequence starts with 1/2.)



Task



Write a program (complete program or a function) which...



Choose one of these behaviors:



  • Input n, output nth element of the sequence (0-indexed or 1-indexed);

  • Input n, output first n elements of the sequence;

  • Input nothing, output the infinite number sequence one by one;

Rule



  • Your program should at least support first 1000 items;

  • You may choose to output decimal, built-in fraction format, or, a pair of decimal integers as you like;

    • Input / Output as binary numbers is not allowed in this question;


  • This is code-golf, shortest codes win;

  • Standard loopholes disallowed.

Testcases



input output
1 1/2 0.5
2 1/4 0.25
3 3/4 0.75
4 1/8 0.125
10 5/16 0.3125
100 73/128 0.5703125
511 511/512 0.998046875
512 1/1024 0.0009765625


These examples are based on 0-indexed sequence with the leading 0 included. You would need to adjust the input for fitting your solution.



Read More




  • OEIS A006257

    • Josephus problem: $ a_2n = 2a_n-1, a_2n+1 = 2a_n+1 $. (Formerly M2216)

    • 0, 1, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, ...



  • OEIS A062383

    • $ a_0 = 1 $: for $ n>0 $, $ a_n = 2^lfloor log_2n+1 rfloor $ or $ a_n = 2a_lfloor fracn2 rfloor $.

    • 1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, ...



  • A006257(n)/A062383(n) = (0, 0.1, 0.01, 0.11, 0.001, ...) enumerates all binary fractions in the unit interval [0, 1). - Fredrik Johansson, Aug 14 2006











share|improve this question

























    up vote
    8
    down vote

    favorite












    Consider the following number sequence:




    $ 0, frac12, frac14, frac34, frac18, frac38, frac58, frac78, frac116, frac316, frac516, frac716, frac916, frac1116, frac1316, frac1516, frac132, frac332, frac532, dots $




    It enumerates all binary fractions in the unit interval $ [0, 1) $.



    (To make this challenge easier, the first element is optional: You may skip it and consider the sequence starts with 1/2.)



    Task



    Write a program (complete program or a function) which...



    Choose one of these behaviors:



    • Input n, output nth element of the sequence (0-indexed or 1-indexed);

    • Input n, output first n elements of the sequence;

    • Input nothing, output the infinite number sequence one by one;

    Rule



    • Your program should at least support first 1000 items;

    • You may choose to output decimal, built-in fraction format, or, a pair of decimal integers as you like;

      • Input / Output as binary numbers is not allowed in this question;


    • This is code-golf, shortest codes win;

    • Standard loopholes disallowed.

    Testcases



    input output
    1 1/2 0.5
    2 1/4 0.25
    3 3/4 0.75
    4 1/8 0.125
    10 5/16 0.3125
    100 73/128 0.5703125
    511 511/512 0.998046875
    512 1/1024 0.0009765625


    These examples are based on 0-indexed sequence with the leading 0 included. You would need to adjust the input for fitting your solution.



    Read More




    • OEIS A006257

      • Josephus problem: $ a_2n = 2a_n-1, a_2n+1 = 2a_n+1 $. (Formerly M2216)

      • 0, 1, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, ...



    • OEIS A062383

      • $ a_0 = 1 $: for $ n>0 $, $ a_n = 2^lfloor log_2n+1 rfloor $ or $ a_n = 2a_lfloor fracn2 rfloor $.

      • 1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, ...



    • A006257(n)/A062383(n) = (0, 0.1, 0.01, 0.11, 0.001, ...) enumerates all binary fractions in the unit interval [0, 1). - Fredrik Johansson, Aug 14 2006











    share|improve this question























      up vote
      8
      down vote

      favorite









      up vote
      8
      down vote

      favorite











      Consider the following number sequence:




      $ 0, frac12, frac14, frac34, frac18, frac38, frac58, frac78, frac116, frac316, frac516, frac716, frac916, frac1116, frac1316, frac1516, frac132, frac332, frac532, dots $




      It enumerates all binary fractions in the unit interval $ [0, 1) $.



      (To make this challenge easier, the first element is optional: You may skip it and consider the sequence starts with 1/2.)



      Task



      Write a program (complete program or a function) which...



      Choose one of these behaviors:



      • Input n, output nth element of the sequence (0-indexed or 1-indexed);

      • Input n, output first n elements of the sequence;

      • Input nothing, output the infinite number sequence one by one;

      Rule



      • Your program should at least support first 1000 items;

      • You may choose to output decimal, built-in fraction format, or, a pair of decimal integers as you like;

        • Input / Output as binary numbers is not allowed in this question;


      • This is code-golf, shortest codes win;

      • Standard loopholes disallowed.

      Testcases



      input output
      1 1/2 0.5
      2 1/4 0.25
      3 3/4 0.75
      4 1/8 0.125
      10 5/16 0.3125
      100 73/128 0.5703125
      511 511/512 0.998046875
      512 1/1024 0.0009765625


      These examples are based on 0-indexed sequence with the leading 0 included. You would need to adjust the input for fitting your solution.



      Read More




      • OEIS A006257

        • Josephus problem: $ a_2n = 2a_n-1, a_2n+1 = 2a_n+1 $. (Formerly M2216)

        • 0, 1, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, ...



      • OEIS A062383

        • $ a_0 = 1 $: for $ n>0 $, $ a_n = 2^lfloor log_2n+1 rfloor $ or $ a_n = 2a_lfloor fracn2 rfloor $.

        • 1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, ...



      • A006257(n)/A062383(n) = (0, 0.1, 0.01, 0.11, 0.001, ...) enumerates all binary fractions in the unit interval [0, 1). - Fredrik Johansson, Aug 14 2006











      share|improve this question













      Consider the following number sequence:




      $ 0, frac12, frac14, frac34, frac18, frac38, frac58, frac78, frac116, frac316, frac516, frac716, frac916, frac1116, frac1316, frac1516, frac132, frac332, frac532, dots $




      It enumerates all binary fractions in the unit interval $ [0, 1) $.



      (To make this challenge easier, the first element is optional: You may skip it and consider the sequence starts with 1/2.)



      Task



      Write a program (complete program or a function) which...



      Choose one of these behaviors:



      • Input n, output nth element of the sequence (0-indexed or 1-indexed);

      • Input n, output first n elements of the sequence;

      • Input nothing, output the infinite number sequence one by one;

      Rule



      • Your program should at least support first 1000 items;

      • You may choose to output decimal, built-in fraction format, or, a pair of decimal integers as you like;

        • Input / Output as binary numbers is not allowed in this question;


      • This is code-golf, shortest codes win;

      • Standard loopholes disallowed.

      Testcases



      input output
      1 1/2 0.5
      2 1/4 0.25
      3 3/4 0.75
      4 1/8 0.125
      10 5/16 0.3125
      100 73/128 0.5703125
      511 511/512 0.998046875
      512 1/1024 0.0009765625


      These examples are based on 0-indexed sequence with the leading 0 included. You would need to adjust the input for fitting your solution.



      Read More




      • OEIS A006257

        • Josephus problem: $ a_2n = 2a_n-1, a_2n+1 = 2a_n+1 $. (Formerly M2216)

        • 0, 1, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, ...



      • OEIS A062383

        • $ a_0 = 1 $: for $ n>0 $, $ a_n = 2^lfloor log_2n+1 rfloor $ or $ a_n = 2a_lfloor fracn2 rfloor $.

        • 1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, ...



      • A006257(n)/A062383(n) = (0, 0.1, 0.01, 0.11, 0.001, ...) enumerates all binary fractions in the unit interval [0, 1). - Fredrik Johansson, Aug 14 2006








      code-golf number sequence integer rational-numbers






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 48 mins ago









      tsh

      7,1101941




      7,1101941




















          6 Answers
          6






          active

          oldest

          votes

















          up vote
          4
          down vote














          MathGolf, 5 bytes



          k╫k╨]


          Assuming implicit input (does not work on TIO currently)



          _╫╨] ("_" duplicates TOS, "" swaps the top two elements)


          Try it online!



          Explanation



          k Read input as int
          ╫ Left-rotate all bits in input
          k Read input as int
          ╨ Round up to nearest power of 2
          ] Wrap in array (just for pretty printing)


          I took my inspiration from this question to solve the problem, my "own" solution was around 10-12 bytes I think.



          I had intended for the round up to closest power of 2 to return the number itself if it was a number of two, but due to a mistake it rounds to the next power of two (e.g. 4 -> 8 instead of 4 -> 4). This will have to be fixed later, but now it saves me one byte.






          share|improve this answer






















          • @user202729 Yes, thanks for noticing. I updated the explanation.
            – maxb
            8 mins ago

















          up vote
          2
          down vote














          05AB1E, 11 bytes



          [N>oDÅÉs/»,


          Try it online!






          share|improve this answer



























            up vote
            2
            down vote














            Jelly, 9 bytes



            Bṙ1Ḅ,æċ2$


            Try it online!






            share|improve this answer



























              up vote
              2
              down vote














              PowerShell, 40 bytes





              for($i=2;;$i*=2)?$_%2


              Try it online!



              Outputs the infinite sequence as decimal values. Given language limitations, will eventually run into precision problems, but easily handles the first 1000 entries.



              Starts by setting $i=2, then enters a for loop. Each iteration, we construct a range from 1..$i and pull out the odd values with |?$_%2. Those are fed into their own inner loop, where we divide each to get the decimal |%$_/$i. Those are left on the pipeline and output when the pipeline is flushed after every for iteration. Each iteration we're simply incrementing $i by $i*=2 to get the next go-round.






              share|improve this answer



























                up vote
                2
                down vote













                Haskell, 35 bytes



                [(y,x)|x<-map(2^)[1..],y<-[1,3..x]]


                This is an infinite list of integer pairs.



                Try it online!






                share|improve this answer



























                  up vote
                  0
                  down vote













                  Java 10, 89 85 bytes





                  v->for(double i=1,j,t;;)for(t=Math.pow(2,i++),j=1;j<t;j+=2)System.out.println(j/t);


                  Port of @Emigma's 05AB1E answer, so outputs decimals indefinitely as well.



                  Try it online.



                  Explanation:



                  v-> // Method with empty unused parameter and no return-type
                  for(double i=1,j,t;;) // Loop `i` from 1 upwards indefinitely
                  for(t=Math.pow(2,i++), // Set `t` to 2 to the power `i`
                  j=1;j<t;j+=2) // Inner loop `j` in the range [1, `t`) in steps of 2
                  System.out.println( // Print with trailing new-line:
                  j/t); // `j` divided by `t`




                  share




















                    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',
                    convertImagesToLinks: false,
                    noModals: false,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: null,
                    bindNavPrevention: true,
                    postfix: "",
                    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%2f172171%2fhalf-half-half-and-half%23new-answer', 'question_page');

                    );

                    Post as a guest






























                    6 Answers
                    6






                    active

                    oldest

                    votes








                    6 Answers
                    6






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    4
                    down vote














                    MathGolf, 5 bytes



                    k╫k╨]


                    Assuming implicit input (does not work on TIO currently)



                    _╫╨] ("_" duplicates TOS, "" swaps the top two elements)


                    Try it online!



                    Explanation



                    k Read input as int
                    ╫ Left-rotate all bits in input
                    k Read input as int
                    ╨ Round up to nearest power of 2
                    ] Wrap in array (just for pretty printing)


                    I took my inspiration from this question to solve the problem, my "own" solution was around 10-12 bytes I think.



                    I had intended for the round up to closest power of 2 to return the number itself if it was a number of two, but due to a mistake it rounds to the next power of two (e.g. 4 -> 8 instead of 4 -> 4). This will have to be fixed later, but now it saves me one byte.






                    share|improve this answer






















                    • @user202729 Yes, thanks for noticing. I updated the explanation.
                      – maxb
                      8 mins ago














                    up vote
                    4
                    down vote














                    MathGolf, 5 bytes



                    k╫k╨]


                    Assuming implicit input (does not work on TIO currently)



                    _╫╨] ("_" duplicates TOS, "" swaps the top two elements)


                    Try it online!



                    Explanation



                    k Read input as int
                    ╫ Left-rotate all bits in input
                    k Read input as int
                    ╨ Round up to nearest power of 2
                    ] Wrap in array (just for pretty printing)


                    I took my inspiration from this question to solve the problem, my "own" solution was around 10-12 bytes I think.



                    I had intended for the round up to closest power of 2 to return the number itself if it was a number of two, but due to a mistake it rounds to the next power of two (e.g. 4 -> 8 instead of 4 -> 4). This will have to be fixed later, but now it saves me one byte.






                    share|improve this answer






















                    • @user202729 Yes, thanks for noticing. I updated the explanation.
                      – maxb
                      8 mins ago












                    up vote
                    4
                    down vote










                    up vote
                    4
                    down vote










                    MathGolf, 5 bytes



                    k╫k╨]


                    Assuming implicit input (does not work on TIO currently)



                    _╫╨] ("_" duplicates TOS, "" swaps the top two elements)


                    Try it online!



                    Explanation



                    k Read input as int
                    ╫ Left-rotate all bits in input
                    k Read input as int
                    ╨ Round up to nearest power of 2
                    ] Wrap in array (just for pretty printing)


                    I took my inspiration from this question to solve the problem, my "own" solution was around 10-12 bytes I think.



                    I had intended for the round up to closest power of 2 to return the number itself if it was a number of two, but due to a mistake it rounds to the next power of two (e.g. 4 -> 8 instead of 4 -> 4). This will have to be fixed later, but now it saves me one byte.






                    share|improve this answer















                    MathGolf, 5 bytes



                    k╫k╨]


                    Assuming implicit input (does not work on TIO currently)



                    _╫╨] ("_" duplicates TOS, "" swaps the top two elements)


                    Try it online!



                    Explanation



                    k Read input as int
                    ╫ Left-rotate all bits in input
                    k Read input as int
                    ╨ Round up to nearest power of 2
                    ] Wrap in array (just for pretty printing)


                    I took my inspiration from this question to solve the problem, my "own" solution was around 10-12 bytes I think.



                    I had intended for the round up to closest power of 2 to return the number itself if it was a number of two, but due to a mistake it rounds to the next power of two (e.g. 4 -> 8 instead of 4 -> 4). This will have to be fixed later, but now it saves me one byte.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 1 min ago

























                    answered 36 mins ago









                    maxb

                    1,209519




                    1,209519











                    • @user202729 Yes, thanks for noticing. I updated the explanation.
                      – maxb
                      8 mins ago
















                    • @user202729 Yes, thanks for noticing. I updated the explanation.
                      – maxb
                      8 mins ago















                    @user202729 Yes, thanks for noticing. I updated the explanation.
                    – maxb
                    8 mins ago




                    @user202729 Yes, thanks for noticing. I updated the explanation.
                    – maxb
                    8 mins ago










                    up vote
                    2
                    down vote














                    05AB1E, 11 bytes



                    [N>oDÅÉs/»,


                    Try it online!






                    share|improve this answer
























                      up vote
                      2
                      down vote














                      05AB1E, 11 bytes



                      [N>oDÅÉs/»,


                      Try it online!






                      share|improve this answer






















                        up vote
                        2
                        down vote










                        up vote
                        2
                        down vote










                        05AB1E, 11 bytes



                        [N>oDÅÉs/»,


                        Try it online!






                        share|improve this answer













                        05AB1E, 11 bytes



                        [N>oDÅÉs/»,


                        Try it online!







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 43 mins ago









                        Emigna

                        43k431131




                        43k431131




















                            up vote
                            2
                            down vote














                            Jelly, 9 bytes



                            Bṙ1Ḅ,æċ2$


                            Try it online!






                            share|improve this answer
























                              up vote
                              2
                              down vote














                              Jelly, 9 bytes



                              Bṙ1Ḅ,æċ2$


                              Try it online!






                              share|improve this answer






















                                up vote
                                2
                                down vote










                                up vote
                                2
                                down vote










                                Jelly, 9 bytes



                                Bṙ1Ḅ,æċ2$


                                Try it online!






                                share|improve this answer













                                Jelly, 9 bytes



                                Bṙ1Ḅ,æċ2$


                                Try it online!







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered 42 mins ago









                                Dennis♦

                                182k32291722




                                182k32291722




















                                    up vote
                                    2
                                    down vote














                                    PowerShell, 40 bytes





                                    for($i=2;;$i*=2)?$_%2


                                    Try it online!



                                    Outputs the infinite sequence as decimal values. Given language limitations, will eventually run into precision problems, but easily handles the first 1000 entries.



                                    Starts by setting $i=2, then enters a for loop. Each iteration, we construct a range from 1..$i and pull out the odd values with |?$_%2. Those are fed into their own inner loop, where we divide each to get the decimal |%$_/$i. Those are left on the pipeline and output when the pipeline is flushed after every for iteration. Each iteration we're simply incrementing $i by $i*=2 to get the next go-round.






                                    share|improve this answer
























                                      up vote
                                      2
                                      down vote














                                      PowerShell, 40 bytes





                                      for($i=2;;$i*=2)?$_%2


                                      Try it online!



                                      Outputs the infinite sequence as decimal values. Given language limitations, will eventually run into precision problems, but easily handles the first 1000 entries.



                                      Starts by setting $i=2, then enters a for loop. Each iteration, we construct a range from 1..$i and pull out the odd values with |?$_%2. Those are fed into their own inner loop, where we divide each to get the decimal |%$_/$i. Those are left on the pipeline and output when the pipeline is flushed after every for iteration. Each iteration we're simply incrementing $i by $i*=2 to get the next go-round.






                                      share|improve this answer






















                                        up vote
                                        2
                                        down vote










                                        up vote
                                        2
                                        down vote










                                        PowerShell, 40 bytes





                                        for($i=2;;$i*=2)?$_%2


                                        Try it online!



                                        Outputs the infinite sequence as decimal values. Given language limitations, will eventually run into precision problems, but easily handles the first 1000 entries.



                                        Starts by setting $i=2, then enters a for loop. Each iteration, we construct a range from 1..$i and pull out the odd values with |?$_%2. Those are fed into their own inner loop, where we divide each to get the decimal |%$_/$i. Those are left on the pipeline and output when the pipeline is flushed after every for iteration. Each iteration we're simply incrementing $i by $i*=2 to get the next go-round.






                                        share|improve this answer













                                        PowerShell, 40 bytes





                                        for($i=2;;$i*=2)?$_%2


                                        Try it online!



                                        Outputs the infinite sequence as decimal values. Given language limitations, will eventually run into precision problems, but easily handles the first 1000 entries.



                                        Starts by setting $i=2, then enters a for loop. Each iteration, we construct a range from 1..$i and pull out the odd values with |?$_%2. Those are fed into their own inner loop, where we divide each to get the decimal |%$_/$i. Those are left on the pipeline and output when the pipeline is flushed after every for iteration. Each iteration we're simply incrementing $i by $i*=2 to get the next go-round.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 22 mins ago









                                        AdmBorkBork

                                        24.4k359214




                                        24.4k359214




















                                            up vote
                                            2
                                            down vote













                                            Haskell, 35 bytes



                                            [(y,x)|x<-map(2^)[1..],y<-[1,3..x]]


                                            This is an infinite list of integer pairs.



                                            Try it online!






                                            share|improve this answer
























                                              up vote
                                              2
                                              down vote













                                              Haskell, 35 bytes



                                              [(y,x)|x<-map(2^)[1..],y<-[1,3..x]]


                                              This is an infinite list of integer pairs.



                                              Try it online!






                                              share|improve this answer






















                                                up vote
                                                2
                                                down vote










                                                up vote
                                                2
                                                down vote









                                                Haskell, 35 bytes



                                                [(y,x)|x<-map(2^)[1..],y<-[1,3..x]]


                                                This is an infinite list of integer pairs.



                                                Try it online!






                                                share|improve this answer












                                                Haskell, 35 bytes



                                                [(y,x)|x<-map(2^)[1..],y<-[1,3..x]]


                                                This is an infinite list of integer pairs.



                                                Try it online!







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 20 mins ago









                                                nimi

                                                29.9k31881




                                                29.9k31881




















                                                    up vote
                                                    0
                                                    down vote













                                                    Java 10, 89 85 bytes





                                                    v->for(double i=1,j,t;;)for(t=Math.pow(2,i++),j=1;j<t;j+=2)System.out.println(j/t);


                                                    Port of @Emigma's 05AB1E answer, so outputs decimals indefinitely as well.



                                                    Try it online.



                                                    Explanation:



                                                    v-> // Method with empty unused parameter and no return-type
                                                    for(double i=1,j,t;;) // Loop `i` from 1 upwards indefinitely
                                                    for(t=Math.pow(2,i++), // Set `t` to 2 to the power `i`
                                                    j=1;j<t;j+=2) // Inner loop `j` in the range [1, `t`) in steps of 2
                                                    System.out.println( // Print with trailing new-line:
                                                    j/t); // `j` divided by `t`




                                                    share
























                                                      up vote
                                                      0
                                                      down vote













                                                      Java 10, 89 85 bytes





                                                      v->for(double i=1,j,t;;)for(t=Math.pow(2,i++),j=1;j<t;j+=2)System.out.println(j/t);


                                                      Port of @Emigma's 05AB1E answer, so outputs decimals indefinitely as well.



                                                      Try it online.



                                                      Explanation:



                                                      v-> // Method with empty unused parameter and no return-type
                                                      for(double i=1,j,t;;) // Loop `i` from 1 upwards indefinitely
                                                      for(t=Math.pow(2,i++), // Set `t` to 2 to the power `i`
                                                      j=1;j<t;j+=2) // Inner loop `j` in the range [1, `t`) in steps of 2
                                                      System.out.println( // Print with trailing new-line:
                                                      j/t); // `j` divided by `t`




                                                      share






















                                                        up vote
                                                        0
                                                        down vote










                                                        up vote
                                                        0
                                                        down vote









                                                        Java 10, 89 85 bytes





                                                        v->for(double i=1,j,t;;)for(t=Math.pow(2,i++),j=1;j<t;j+=2)System.out.println(j/t);


                                                        Port of @Emigma's 05AB1E answer, so outputs decimals indefinitely as well.



                                                        Try it online.



                                                        Explanation:



                                                        v-> // Method with empty unused parameter and no return-type
                                                        for(double i=1,j,t;;) // Loop `i` from 1 upwards indefinitely
                                                        for(t=Math.pow(2,i++), // Set `t` to 2 to the power `i`
                                                        j=1;j<t;j+=2) // Inner loop `j` in the range [1, `t`) in steps of 2
                                                        System.out.println( // Print with trailing new-line:
                                                        j/t); // `j` divided by `t`




                                                        share












                                                        Java 10, 89 85 bytes





                                                        v->for(double i=1,j,t;;)for(t=Math.pow(2,i++),j=1;j<t;j+=2)System.out.println(j/t);


                                                        Port of @Emigma's 05AB1E answer, so outputs decimals indefinitely as well.



                                                        Try it online.



                                                        Explanation:



                                                        v-> // Method with empty unused parameter and no return-type
                                                        for(double i=1,j,t;;) // Loop `i` from 1 upwards indefinitely
                                                        for(t=Math.pow(2,i++), // Set `t` to 2 to the power `i`
                                                        j=1;j<t;j+=2) // Inner loop `j` in the range [1, `t`) in steps of 2
                                                        System.out.println( // Print with trailing new-line:
                                                        j/t); // `j` divided by `t`





                                                        share











                                                        share


                                                        share










                                                        answered 5 mins ago









                                                        Kevin Cruijssen

                                                        29.9k552165




                                                        29.9k552165



























                                                             

                                                            draft saved


                                                            draft discarded















































                                                             


                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function ()
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172171%2fhalf-half-half-and-half%23new-answer', 'question_page');

                                                            );

                                                            Post as a guest













































































                                                            Comments

                                                            Popular posts from this blog

                                                            What does second last employer means? [closed]

                                                            Installing NextGIS Connect into QGIS 3?

                                                            One-line joke