Number Sequence Challenge

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











up vote
1
down vote

favorite












Display numbers from one to one-hundred (in increasing order), but number 2 shouldn’t appear anywhere in the sequence. So, for example, the numbers two (2) or twenty-three (23) shouldn't be in the sequence.



Here is an example output, with newlines separating the numbers:



1
3
4
5
6
7
8
9
10
11
13
14
15
16
17
18
19
30
31
33
34
35
36
37
38
39
40
41
43
44
45
46
47
48
49
50
51
53
54
55
56
57
58
59
60
61
63
64
65
66
67
68
69
70
71
73
74
75
76
77
78
79
80
81
83
84
85
86
87
88
89
90
91
93
94
95
96
97
98
99
100









share|improve this question









New contributor




Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 6




    I assume the winning criteria is code-golf right?
    – Luis felipe De jesus Munoz
    7 hours ago










  • Does the order matter? ('Sequence' seems to imply that it does.)
    – Arnauld
    7 hours ago







  • 2




    Our site does not work the same way as other sites from the Stack Exchange network. Regarding accepted answers, please take this comment from Jonathan Allan into account. And please add a winning criterion.
    – Arnauld
    7 hours ago






  • 1




    Might I suggest using the Sandbox in the future to get feedback on your challenges before posting?
    – Jo King
    6 hours ago






  • 1




    @Monolica If the shortest answer wins, you'll need the tag [code-golf]. Here is a list for all available winning criteria tags for future reference.
    – Kevin Cruijssen
    6 hours ago















up vote
1
down vote

favorite












Display numbers from one to one-hundred (in increasing order), but number 2 shouldn’t appear anywhere in the sequence. So, for example, the numbers two (2) or twenty-three (23) shouldn't be in the sequence.



Here is an example output, with newlines separating the numbers:



1
3
4
5
6
7
8
9
10
11
13
14
15
16
17
18
19
30
31
33
34
35
36
37
38
39
40
41
43
44
45
46
47
48
49
50
51
53
54
55
56
57
58
59
60
61
63
64
65
66
67
68
69
70
71
73
74
75
76
77
78
79
80
81
83
84
85
86
87
88
89
90
91
93
94
95
96
97
98
99
100









share|improve this question









New contributor




Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 6




    I assume the winning criteria is code-golf right?
    – Luis felipe De jesus Munoz
    7 hours ago










  • Does the order matter? ('Sequence' seems to imply that it does.)
    – Arnauld
    7 hours ago







  • 2




    Our site does not work the same way as other sites from the Stack Exchange network. Regarding accepted answers, please take this comment from Jonathan Allan into account. And please add a winning criterion.
    – Arnauld
    7 hours ago






  • 1




    Might I suggest using the Sandbox in the future to get feedback on your challenges before posting?
    – Jo King
    6 hours ago






  • 1




    @Monolica If the shortest answer wins, you'll need the tag [code-golf]. Here is a list for all available winning criteria tags for future reference.
    – Kevin Cruijssen
    6 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Display numbers from one to one-hundred (in increasing order), but number 2 shouldn’t appear anywhere in the sequence. So, for example, the numbers two (2) or twenty-three (23) shouldn't be in the sequence.



Here is an example output, with newlines separating the numbers:



1
3
4
5
6
7
8
9
10
11
13
14
15
16
17
18
19
30
31
33
34
35
36
37
38
39
40
41
43
44
45
46
47
48
49
50
51
53
54
55
56
57
58
59
60
61
63
64
65
66
67
68
69
70
71
73
74
75
76
77
78
79
80
81
83
84
85
86
87
88
89
90
91
93
94
95
96
97
98
99
100









share|improve this question









New contributor




Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Display numbers from one to one-hundred (in increasing order), but number 2 shouldn’t appear anywhere in the sequence. So, for example, the numbers two (2) or twenty-three (23) shouldn't be in the sequence.



Here is an example output, with newlines separating the numbers:



1
3
4
5
6
7
8
9
10
11
13
14
15
16
17
18
19
30
31
33
34
35
36
37
38
39
40
41
43
44
45
46
47
48
49
50
51
53
54
55
56
57
58
59
60
61
63
64
65
66
67
68
69
70
71
73
74
75
76
77
78
79
80
81
83
84
85
86
87
88
89
90
91
93
94
95
96
97
98
99
100






code-golf sequence kolmogorov-complexity






share|improve this question









New contributor




Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 20 mins ago









AdmBorkBork

24.7k360215




24.7k360215






New contributor




Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 7 hours ago









Monolica

463




463




New contributor




Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Monolica is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 6




    I assume the winning criteria is code-golf right?
    – Luis felipe De jesus Munoz
    7 hours ago










  • Does the order matter? ('Sequence' seems to imply that it does.)
    – Arnauld
    7 hours ago







  • 2




    Our site does not work the same way as other sites from the Stack Exchange network. Regarding accepted answers, please take this comment from Jonathan Allan into account. And please add a winning criterion.
    – Arnauld
    7 hours ago






  • 1




    Might I suggest using the Sandbox in the future to get feedback on your challenges before posting?
    – Jo King
    6 hours ago






  • 1




    @Monolica If the shortest answer wins, you'll need the tag [code-golf]. Here is a list for all available winning criteria tags for future reference.
    – Kevin Cruijssen
    6 hours ago













  • 6




    I assume the winning criteria is code-golf right?
    – Luis felipe De jesus Munoz
    7 hours ago










  • Does the order matter? ('Sequence' seems to imply that it does.)
    – Arnauld
    7 hours ago







  • 2




    Our site does not work the same way as other sites from the Stack Exchange network. Regarding accepted answers, please take this comment from Jonathan Allan into account. And please add a winning criterion.
    – Arnauld
    7 hours ago






  • 1




    Might I suggest using the Sandbox in the future to get feedback on your challenges before posting?
    – Jo King
    6 hours ago






  • 1




    @Monolica If the shortest answer wins, you'll need the tag [code-golf]. Here is a list for all available winning criteria tags for future reference.
    – Kevin Cruijssen
    6 hours ago








6




6




I assume the winning criteria is code-golf right?
– Luis felipe De jesus Munoz
7 hours ago




I assume the winning criteria is code-golf right?
– Luis felipe De jesus Munoz
7 hours ago












Does the order matter? ('Sequence' seems to imply that it does.)
– Arnauld
7 hours ago





Does the order matter? ('Sequence' seems to imply that it does.)
– Arnauld
7 hours ago





2




2




Our site does not work the same way as other sites from the Stack Exchange network. Regarding accepted answers, please take this comment from Jonathan Allan into account. And please add a winning criterion.
– Arnauld
7 hours ago




Our site does not work the same way as other sites from the Stack Exchange network. Regarding accepted answers, please take this comment from Jonathan Allan into account. And please add a winning criterion.
– Arnauld
7 hours ago




1




1




Might I suggest using the Sandbox in the future to get feedback on your challenges before posting?
– Jo King
6 hours ago




Might I suggest using the Sandbox in the future to get feedback on your challenges before posting?
– Jo King
6 hours ago




1




1




@Monolica If the shortest answer wins, you'll need the tag [code-golf]. Here is a list for all available winning criteria tags for future reference.
– Kevin Cruijssen
6 hours ago





@Monolica If the shortest answer wins, you'll need the tag [code-golf]. Here is a list for all available winning criteria tags for future reference.
– Kevin Cruijssen
6 hours ago











12 Answers
12






active

oldest

votes

















up vote
3
down vote



accepted











05AB1E, 6 bytes



тLʒ2å_


Try it online!



Explanation



тL # push [1 ... 100]
ʒ # filter, keep only elements that
2Ã¥_ # does not contain 2





share|improve this answer



























    up vote
    4
    down vote














    R, 19 bytes





    grep(2,1:100,inv=T)


    Try it online!






    share|improve this answer






















    • grep(2,1:100,inv=T) for 19.
      – J.Doe
      2 hours ago






    • 1




      Ha - this was what I tried at first but with v=F as well because obviously, I thought to myself, I want the values and not the indices...duh!
      – ngm
      2 hours ago











    • Inverting the regex itself is a byte shorter (in this case).
      – ngm
      1 hour ago










    • Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter.
      – J.Doe
      1 hour ago






    • 1




      What, are we supposed to check our answers now?
      – ngm
      1 hour ago

















    up vote
    3
    down vote














    Python 2, 44 bytes





    print[n for n in range(1,101)if'2'not in`n`]


    Try it online!






    share|improve this answer



























      up vote
      2
      down vote













      Java 10, 67 bytes





      v->for(int i=0;++i<101;)if(i%10!=2&i/10!=2)System.out.println(i);


      Try it online.



      Explanation:



      v-> // Method with empty unused parameter and no return-type
      for(int i=0;++i<101;) // Loop `i` in the range (0, 101)
      if(i%10!=2 // If `i` modulo-10 is not 2
      &i/10!=2) // And `i` integer-divided by 10 is not 2 either
      System.out.println(i); // Print `i` with a trailing newline





      share|improve this answer



























        up vote
        2
        down vote













        JavaScript (ES6), 43 bytes



        Returns the sequence as a comma-separated string.





        f=(n=98)=>n?f(n-=n-27?n%10?1:2:11)+[,n+3]:1


        Try it online!



        Why doing it this way?



        We could iterate from $1$ to $100$ and test each number with /2/.test(n), which is a rather concise statement. But in this scenario, we'd have to handle empty entries with something like (/2/.test(n)?'':...), which adds a couple more bytes.



        For example, this would work for 45 bytes:



        f=(n=1)=>n>99?n:(/2/.test(n)?'':[n,,])+f(n+1)


        Or this would work for 44 bytes, if a leading comma is acceptable:



        f=(n=100)=>n?f(n-1)+(/2/.test(n)?'':[,n]):''


        All in all (and until proven otherwise), it turns out to be shorter to skip right away all values of $n$ that contain a $2$.



        Commented



        f = // f is a recursive function taking:
        (n = 98) => // n = counter, initialized to 98
        n ? // if n is not equal to 0:
        f( // prepend the result of a recursive call:
        n -= // update n:
        n - 27 ? // if n is not equal to 27:
        n % 10 ? // if n is not a multiple of 10:
        1 // subtract 1 from n
        : // else:
        2 // subtract 2 from n
        : // else (n = 27):
        11 // subtract 11 from n (--> 16)
        ) + // end of recursive call
        [, n + 3] // append a comma, followed by n + 3; notice that this is the value
        // of n *after* it was updated for the recursive call; at the first
        // iteration, we have: n = 98 -> updated to 97 -> n + 3 = 100
        : // else (n = 0):
        1 // output the first term '1' and stop recursion





        share|improve this answer






















        • This is so cool!
          – Emigna
          1 hour ago

















        up vote
        1
        down vote














        Retina, 19 bytes




        100*
        L$`.
        $.>`
        A`2


        Try it online! Explanation:




        100*


        Insert 100 characters.



        L$`.
        $.>`


        For each character, list the number of characters up to and including that character.



        A`2


        Remove all entries that contain a 2.






        share|improve this answer



























          up vote
          1
          down vote














          Perl 6, 22 bytes





          put grep !/2/,1..100


          Try it online!



          There's probably a better way to do the code block, but I couldn't find a regex adverb to invert the match






          share|improve this answer






















          • remove the brackets around the numbers. Otherwise it is fine.
            – Monolica
            7 hours ago










          • @Monolica Fixed
            – Jo King
            7 hours ago

















          up vote
          0
          down vote














          Japt, 7 bytes



          Lõs kø2


          Try it online!






          share|improve this answer



























            up vote
            0
            down vote














            Tcl, 47 bytes



            time if [incr i]%10!=2&$i/10!=2 puts $i 100


            Try it online!







            Tcl, 50 bytes



            time if 2 ni [split [incr i] ""] puts $i 100


            Try it online!








            share|improve this answer





























              up vote
              0
              down vote














              Red, 44 bytes



              repeat n 100[unless find form n"2"[print n]]


              Try it online!



              Uses unless instead of if not, because why not? :)






              share|improve this answer





























                up vote
                0
                down vote














                Stax, 6 bytes



                Ç░τ╒╜h


                Run and debug it



                Unpacked, ungolfed, and commented, it looks like this.



                AJ 10 squared
                f output each value in [1 .. n] satisfying the following filter
                E get array of decimal digits in number
                2# count the number of 2s
                ! logical not


                Run this one






                share|improve this answer



























                  up vote
                  0
                  down vote














                  PowerShell, 22 bytes





                  1..100|?$_-notmatch2


                  Try it online!



                  Generates the range 1 to 100, then pulls out those objects where |?... they do -notmatch the number 2. Each item is left on the pipeline, and output is implicit.





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



                    );






                    Monolica is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173189%2fnumber-sequence-challenge%23new-answer', 'question_page');

                    );

                    Post as a guest






























                    12 Answers
                    12






                    active

                    oldest

                    votes








                    12 Answers
                    12






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    3
                    down vote



                    accepted











                    05AB1E, 6 bytes



                    тLʒ2å_


                    Try it online!



                    Explanation



                    тL # push [1 ... 100]
                    ʒ # filter, keep only elements that
                    2Ã¥_ # does not contain 2





                    share|improve this answer
























                      up vote
                      3
                      down vote



                      accepted











                      05AB1E, 6 bytes



                      тLʒ2å_


                      Try it online!



                      Explanation



                      тL # push [1 ... 100]
                      ʒ # filter, keep only elements that
                      2Ã¥_ # does not contain 2





                      share|improve this answer






















                        up vote
                        3
                        down vote



                        accepted







                        up vote
                        3
                        down vote



                        accepted







                        05AB1E, 6 bytes



                        тLʒ2å_


                        Try it online!



                        Explanation



                        тL # push [1 ... 100]
                        ʒ # filter, keep only elements that
                        2Ã¥_ # does not contain 2





                        share|improve this answer













                        05AB1E, 6 bytes



                        тLʒ2å_


                        Try it online!



                        Explanation



                        тL # push [1 ... 100]
                        ʒ # filter, keep only elements that
                        2Ã¥_ # does not contain 2






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 7 hours ago









                        Emigna

                        43.5k431131




                        43.5k431131




















                            up vote
                            4
                            down vote














                            R, 19 bytes





                            grep(2,1:100,inv=T)


                            Try it online!






                            share|improve this answer






















                            • grep(2,1:100,inv=T) for 19.
                              – J.Doe
                              2 hours ago






                            • 1




                              Ha - this was what I tried at first but with v=F as well because obviously, I thought to myself, I want the values and not the indices...duh!
                              – ngm
                              2 hours ago











                            • Inverting the regex itself is a byte shorter (in this case).
                              – ngm
                              1 hour ago










                            • Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter.
                              – J.Doe
                              1 hour ago






                            • 1




                              What, are we supposed to check our answers now?
                              – ngm
                              1 hour ago














                            up vote
                            4
                            down vote














                            R, 19 bytes





                            grep(2,1:100,inv=T)


                            Try it online!






                            share|improve this answer






















                            • grep(2,1:100,inv=T) for 19.
                              – J.Doe
                              2 hours ago






                            • 1




                              Ha - this was what I tried at first but with v=F as well because obviously, I thought to myself, I want the values and not the indices...duh!
                              – ngm
                              2 hours ago











                            • Inverting the regex itself is a byte shorter (in this case).
                              – ngm
                              1 hour ago










                            • Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter.
                              – J.Doe
                              1 hour ago






                            • 1




                              What, are we supposed to check our answers now?
                              – ngm
                              1 hour ago












                            up vote
                            4
                            down vote










                            up vote
                            4
                            down vote










                            R, 19 bytes





                            grep(2,1:100,inv=T)


                            Try it online!






                            share|improve this answer















                            R, 19 bytes





                            grep(2,1:100,inv=T)


                            Try it online!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 1 hour ago

























                            answered 7 hours ago









                            ngm

                            2,44920




                            2,44920











                            • grep(2,1:100,inv=T) for 19.
                              – J.Doe
                              2 hours ago






                            • 1




                              Ha - this was what I tried at first but with v=F as well because obviously, I thought to myself, I want the values and not the indices...duh!
                              – ngm
                              2 hours ago











                            • Inverting the regex itself is a byte shorter (in this case).
                              – ngm
                              1 hour ago










                            • Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter.
                              – J.Doe
                              1 hour ago






                            • 1




                              What, are we supposed to check our answers now?
                              – ngm
                              1 hour ago
















                            • grep(2,1:100,inv=T) for 19.
                              – J.Doe
                              2 hours ago






                            • 1




                              Ha - this was what I tried at first but with v=F as well because obviously, I thought to myself, I want the values and not the indices...duh!
                              – ngm
                              2 hours ago











                            • Inverting the regex itself is a byte shorter (in this case).
                              – ngm
                              1 hour ago










                            • Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter.
                              – J.Doe
                              1 hour ago






                            • 1




                              What, are we supposed to check our answers now?
                              – ngm
                              1 hour ago















                            grep(2,1:100,inv=T) for 19.
                            – J.Doe
                            2 hours ago




                            grep(2,1:100,inv=T) for 19.
                            – J.Doe
                            2 hours ago




                            1




                            1




                            Ha - this was what I tried at first but with v=F as well because obviously, I thought to myself, I want the values and not the indices...duh!
                            – ngm
                            2 hours ago





                            Ha - this was what I tried at first but with v=F as well because obviously, I thought to myself, I want the values and not the indices...duh!
                            – ngm
                            2 hours ago













                            Inverting the regex itself is a byte shorter (in this case).
                            – ngm
                            1 hour ago




                            Inverting the regex itself is a byte shorter (in this case).
                            – ngm
                            1 hour ago












                            Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter.
                            – J.Doe
                            1 hour ago




                            Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter.
                            – J.Doe
                            1 hour ago




                            1




                            1




                            What, are we supposed to check our answers now?
                            – ngm
                            1 hour ago




                            What, are we supposed to check our answers now?
                            – ngm
                            1 hour ago










                            up vote
                            3
                            down vote














                            Python 2, 44 bytes





                            print[n for n in range(1,101)if'2'not in`n`]


                            Try it online!






                            share|improve this answer
























                              up vote
                              3
                              down vote














                              Python 2, 44 bytes





                              print[n for n in range(1,101)if'2'not in`n`]


                              Try it online!






                              share|improve this answer






















                                up vote
                                3
                                down vote










                                up vote
                                3
                                down vote










                                Python 2, 44 bytes





                                print[n for n in range(1,101)if'2'not in`n`]


                                Try it online!






                                share|improve this answer













                                Python 2, 44 bytes





                                print[n for n in range(1,101)if'2'not in`n`]


                                Try it online!







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered 7 hours ago









                                TFeld

                                12k2833




                                12k2833




















                                    up vote
                                    2
                                    down vote













                                    Java 10, 67 bytes





                                    v->for(int i=0;++i<101;)if(i%10!=2&i/10!=2)System.out.println(i);


                                    Try it online.



                                    Explanation:



                                    v-> // Method with empty unused parameter and no return-type
                                    for(int i=0;++i<101;) // Loop `i` in the range (0, 101)
                                    if(i%10!=2 // If `i` modulo-10 is not 2
                                    &i/10!=2) // And `i` integer-divided by 10 is not 2 either
                                    System.out.println(i); // Print `i` with a trailing newline





                                    share|improve this answer
























                                      up vote
                                      2
                                      down vote













                                      Java 10, 67 bytes





                                      v->for(int i=0;++i<101;)if(i%10!=2&i/10!=2)System.out.println(i);


                                      Try it online.



                                      Explanation:



                                      v-> // Method with empty unused parameter and no return-type
                                      for(int i=0;++i<101;) // Loop `i` in the range (0, 101)
                                      if(i%10!=2 // If `i` modulo-10 is not 2
                                      &i/10!=2) // And `i` integer-divided by 10 is not 2 either
                                      System.out.println(i); // Print `i` with a trailing newline





                                      share|improve this answer






















                                        up vote
                                        2
                                        down vote










                                        up vote
                                        2
                                        down vote









                                        Java 10, 67 bytes





                                        v->for(int i=0;++i<101;)if(i%10!=2&i/10!=2)System.out.println(i);


                                        Try it online.



                                        Explanation:



                                        v-> // Method with empty unused parameter and no return-type
                                        for(int i=0;++i<101;) // Loop `i` in the range (0, 101)
                                        if(i%10!=2 // If `i` modulo-10 is not 2
                                        &i/10!=2) // And `i` integer-divided by 10 is not 2 either
                                        System.out.println(i); // Print `i` with a trailing newline





                                        share|improve this answer












                                        Java 10, 67 bytes





                                        v->for(int i=0;++i<101;)if(i%10!=2&i/10!=2)System.out.println(i);


                                        Try it online.



                                        Explanation:



                                        v-> // Method with empty unused parameter and no return-type
                                        for(int i=0;++i<101;) // Loop `i` in the range (0, 101)
                                        if(i%10!=2 // If `i` modulo-10 is not 2
                                        &i/10!=2) // And `i` integer-divided by 10 is not 2 either
                                        System.out.println(i); // Print `i` with a trailing newline






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 7 hours ago









                                        Kevin Cruijssen

                                        30.9k553168




                                        30.9k553168




















                                            up vote
                                            2
                                            down vote













                                            JavaScript (ES6), 43 bytes



                                            Returns the sequence as a comma-separated string.





                                            f=(n=98)=>n?f(n-=n-27?n%10?1:2:11)+[,n+3]:1


                                            Try it online!



                                            Why doing it this way?



                                            We could iterate from $1$ to $100$ and test each number with /2/.test(n), which is a rather concise statement. But in this scenario, we'd have to handle empty entries with something like (/2/.test(n)?'':...), which adds a couple more bytes.



                                            For example, this would work for 45 bytes:



                                            f=(n=1)=>n>99?n:(/2/.test(n)?'':[n,,])+f(n+1)


                                            Or this would work for 44 bytes, if a leading comma is acceptable:



                                            f=(n=100)=>n?f(n-1)+(/2/.test(n)?'':[,n]):''


                                            All in all (and until proven otherwise), it turns out to be shorter to skip right away all values of $n$ that contain a $2$.



                                            Commented



                                            f = // f is a recursive function taking:
                                            (n = 98) => // n = counter, initialized to 98
                                            n ? // if n is not equal to 0:
                                            f( // prepend the result of a recursive call:
                                            n -= // update n:
                                            n - 27 ? // if n is not equal to 27:
                                            n % 10 ? // if n is not a multiple of 10:
                                            1 // subtract 1 from n
                                            : // else:
                                            2 // subtract 2 from n
                                            : // else (n = 27):
                                            11 // subtract 11 from n (--> 16)
                                            ) + // end of recursive call
                                            [, n + 3] // append a comma, followed by n + 3; notice that this is the value
                                            // of n *after* it was updated for the recursive call; at the first
                                            // iteration, we have: n = 98 -> updated to 97 -> n + 3 = 100
                                            : // else (n = 0):
                                            1 // output the first term '1' and stop recursion





                                            share|improve this answer






















                                            • This is so cool!
                                              – Emigna
                                              1 hour ago














                                            up vote
                                            2
                                            down vote













                                            JavaScript (ES6), 43 bytes



                                            Returns the sequence as a comma-separated string.





                                            f=(n=98)=>n?f(n-=n-27?n%10?1:2:11)+[,n+3]:1


                                            Try it online!



                                            Why doing it this way?



                                            We could iterate from $1$ to $100$ and test each number with /2/.test(n), which is a rather concise statement. But in this scenario, we'd have to handle empty entries with something like (/2/.test(n)?'':...), which adds a couple more bytes.



                                            For example, this would work for 45 bytes:



                                            f=(n=1)=>n>99?n:(/2/.test(n)?'':[n,,])+f(n+1)


                                            Or this would work for 44 bytes, if a leading comma is acceptable:



                                            f=(n=100)=>n?f(n-1)+(/2/.test(n)?'':[,n]):''


                                            All in all (and until proven otherwise), it turns out to be shorter to skip right away all values of $n$ that contain a $2$.



                                            Commented



                                            f = // f is a recursive function taking:
                                            (n = 98) => // n = counter, initialized to 98
                                            n ? // if n is not equal to 0:
                                            f( // prepend the result of a recursive call:
                                            n -= // update n:
                                            n - 27 ? // if n is not equal to 27:
                                            n % 10 ? // if n is not a multiple of 10:
                                            1 // subtract 1 from n
                                            : // else:
                                            2 // subtract 2 from n
                                            : // else (n = 27):
                                            11 // subtract 11 from n (--> 16)
                                            ) + // end of recursive call
                                            [, n + 3] // append a comma, followed by n + 3; notice that this is the value
                                            // of n *after* it was updated for the recursive call; at the first
                                            // iteration, we have: n = 98 -> updated to 97 -> n + 3 = 100
                                            : // else (n = 0):
                                            1 // output the first term '1' and stop recursion





                                            share|improve this answer






















                                            • This is so cool!
                                              – Emigna
                                              1 hour ago












                                            up vote
                                            2
                                            down vote










                                            up vote
                                            2
                                            down vote









                                            JavaScript (ES6), 43 bytes



                                            Returns the sequence as a comma-separated string.





                                            f=(n=98)=>n?f(n-=n-27?n%10?1:2:11)+[,n+3]:1


                                            Try it online!



                                            Why doing it this way?



                                            We could iterate from $1$ to $100$ and test each number with /2/.test(n), which is a rather concise statement. But in this scenario, we'd have to handle empty entries with something like (/2/.test(n)?'':...), which adds a couple more bytes.



                                            For example, this would work for 45 bytes:



                                            f=(n=1)=>n>99?n:(/2/.test(n)?'':[n,,])+f(n+1)


                                            Or this would work for 44 bytes, if a leading comma is acceptable:



                                            f=(n=100)=>n?f(n-1)+(/2/.test(n)?'':[,n]):''


                                            All in all (and until proven otherwise), it turns out to be shorter to skip right away all values of $n$ that contain a $2$.



                                            Commented



                                            f = // f is a recursive function taking:
                                            (n = 98) => // n = counter, initialized to 98
                                            n ? // if n is not equal to 0:
                                            f( // prepend the result of a recursive call:
                                            n -= // update n:
                                            n - 27 ? // if n is not equal to 27:
                                            n % 10 ? // if n is not a multiple of 10:
                                            1 // subtract 1 from n
                                            : // else:
                                            2 // subtract 2 from n
                                            : // else (n = 27):
                                            11 // subtract 11 from n (--> 16)
                                            ) + // end of recursive call
                                            [, n + 3] // append a comma, followed by n + 3; notice that this is the value
                                            // of n *after* it was updated for the recursive call; at the first
                                            // iteration, we have: n = 98 -> updated to 97 -> n + 3 = 100
                                            : // else (n = 0):
                                            1 // output the first term '1' and stop recursion





                                            share|improve this answer














                                            JavaScript (ES6), 43 bytes



                                            Returns the sequence as a comma-separated string.





                                            f=(n=98)=>n?f(n-=n-27?n%10?1:2:11)+[,n+3]:1


                                            Try it online!



                                            Why doing it this way?



                                            We could iterate from $1$ to $100$ and test each number with /2/.test(n), which is a rather concise statement. But in this scenario, we'd have to handle empty entries with something like (/2/.test(n)?'':...), which adds a couple more bytes.



                                            For example, this would work for 45 bytes:



                                            f=(n=1)=>n>99?n:(/2/.test(n)?'':[n,,])+f(n+1)


                                            Or this would work for 44 bytes, if a leading comma is acceptable:



                                            f=(n=100)=>n?f(n-1)+(/2/.test(n)?'':[,n]):''


                                            All in all (and until proven otherwise), it turns out to be shorter to skip right away all values of $n$ that contain a $2$.



                                            Commented



                                            f = // f is a recursive function taking:
                                            (n = 98) => // n = counter, initialized to 98
                                            n ? // if n is not equal to 0:
                                            f( // prepend the result of a recursive call:
                                            n -= // update n:
                                            n - 27 ? // if n is not equal to 27:
                                            n % 10 ? // if n is not a multiple of 10:
                                            1 // subtract 1 from n
                                            : // else:
                                            2 // subtract 2 from n
                                            : // else (n = 27):
                                            11 // subtract 11 from n (--> 16)
                                            ) + // end of recursive call
                                            [, n + 3] // append a comma, followed by n + 3; notice that this is the value
                                            // of n *after* it was updated for the recursive call; at the first
                                            // iteration, we have: n = 98 -> updated to 97 -> n + 3 = 100
                                            : // else (n = 0):
                                            1 // output the first term '1' and stop recursion






                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited 5 hours ago

























                                            answered 7 hours ago









                                            Arnauld

                                            65.6k583277




                                            65.6k583277











                                            • This is so cool!
                                              – Emigna
                                              1 hour ago
















                                            • This is so cool!
                                              – Emigna
                                              1 hour ago















                                            This is so cool!
                                            – Emigna
                                            1 hour ago




                                            This is so cool!
                                            – Emigna
                                            1 hour ago










                                            up vote
                                            1
                                            down vote














                                            Retina, 19 bytes




                                            100*
                                            L$`.
                                            $.>`
                                            A`2


                                            Try it online! Explanation:




                                            100*


                                            Insert 100 characters.



                                            L$`.
                                            $.>`


                                            For each character, list the number of characters up to and including that character.



                                            A`2


                                            Remove all entries that contain a 2.






                                            share|improve this answer
























                                              up vote
                                              1
                                              down vote














                                              Retina, 19 bytes




                                              100*
                                              L$`.
                                              $.>`
                                              A`2


                                              Try it online! Explanation:




                                              100*


                                              Insert 100 characters.



                                              L$`.
                                              $.>`


                                              For each character, list the number of characters up to and including that character.



                                              A`2


                                              Remove all entries that contain a 2.






                                              share|improve this answer






















                                                up vote
                                                1
                                                down vote










                                                up vote
                                                1
                                                down vote










                                                Retina, 19 bytes




                                                100*
                                                L$`.
                                                $.>`
                                                A`2


                                                Try it online! Explanation:




                                                100*


                                                Insert 100 characters.



                                                L$`.
                                                $.>`


                                                For each character, list the number of characters up to and including that character.



                                                A`2


                                                Remove all entries that contain a 2.






                                                share|improve this answer













                                                Retina, 19 bytes




                                                100*
                                                L$`.
                                                $.>`
                                                A`2


                                                Try it online! Explanation:




                                                100*


                                                Insert 100 characters.



                                                L$`.
                                                $.>`


                                                For each character, list the number of characters up to and including that character.



                                                A`2


                                                Remove all entries that contain a 2.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 7 hours ago









                                                Neil

                                                75.8k744171




                                                75.8k744171




















                                                    up vote
                                                    1
                                                    down vote














                                                    Perl 6, 22 bytes





                                                    put grep !/2/,1..100


                                                    Try it online!



                                                    There's probably a better way to do the code block, but I couldn't find a regex adverb to invert the match






                                                    share|improve this answer






















                                                    • remove the brackets around the numbers. Otherwise it is fine.
                                                      – Monolica
                                                      7 hours ago










                                                    • @Monolica Fixed
                                                      – Jo King
                                                      7 hours ago














                                                    up vote
                                                    1
                                                    down vote














                                                    Perl 6, 22 bytes





                                                    put grep !/2/,1..100


                                                    Try it online!



                                                    There's probably a better way to do the code block, but I couldn't find a regex adverb to invert the match






                                                    share|improve this answer






















                                                    • remove the brackets around the numbers. Otherwise it is fine.
                                                      – Monolica
                                                      7 hours ago










                                                    • @Monolica Fixed
                                                      – Jo King
                                                      7 hours ago












                                                    up vote
                                                    1
                                                    down vote










                                                    up vote
                                                    1
                                                    down vote










                                                    Perl 6, 22 bytes





                                                    put grep !/2/,1..100


                                                    Try it online!



                                                    There's probably a better way to do the code block, but I couldn't find a regex adverb to invert the match






                                                    share|improve this answer















                                                    Perl 6, 22 bytes





                                                    put grep !/2/,1..100


                                                    Try it online!



                                                    There's probably a better way to do the code block, but I couldn't find a regex adverb to invert the match







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited 7 hours ago

























                                                    answered 7 hours ago









                                                    Jo King

                                                    16.6k24190




                                                    16.6k24190











                                                    • remove the brackets around the numbers. Otherwise it is fine.
                                                      – Monolica
                                                      7 hours ago










                                                    • @Monolica Fixed
                                                      – Jo King
                                                      7 hours ago
















                                                    • remove the brackets around the numbers. Otherwise it is fine.
                                                      – Monolica
                                                      7 hours ago










                                                    • @Monolica Fixed
                                                      – Jo King
                                                      7 hours ago















                                                    remove the brackets around the numbers. Otherwise it is fine.
                                                    – Monolica
                                                    7 hours ago




                                                    remove the brackets around the numbers. Otherwise it is fine.
                                                    – Monolica
                                                    7 hours ago












                                                    @Monolica Fixed
                                                    – Jo King
                                                    7 hours ago




                                                    @Monolica Fixed
                                                    – Jo King
                                                    7 hours ago










                                                    up vote
                                                    0
                                                    down vote














                                                    Japt, 7 bytes



                                                    Lõs kø2


                                                    Try it online!






                                                    share|improve this answer
























                                                      up vote
                                                      0
                                                      down vote














                                                      Japt, 7 bytes



                                                      Lõs kø2


                                                      Try it online!






                                                      share|improve this answer






















                                                        up vote
                                                        0
                                                        down vote










                                                        up vote
                                                        0
                                                        down vote










                                                        Japt, 7 bytes



                                                        Lõs kø2


                                                        Try it online!






                                                        share|improve this answer













                                                        Japt, 7 bytes



                                                        Lõs kø2


                                                        Try it online!







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered 7 hours ago









                                                        Luis felipe De jesus Munoz

                                                        3,0361046




                                                        3,0361046




















                                                            up vote
                                                            0
                                                            down vote














                                                            Tcl, 47 bytes



                                                            time if [incr i]%10!=2&$i/10!=2 puts $i 100


                                                            Try it online!







                                                            Tcl, 50 bytes



                                                            time if 2 ni [split [incr i] ""] puts $i 100


                                                            Try it online!








                                                            share|improve this answer


























                                                              up vote
                                                              0
                                                              down vote














                                                              Tcl, 47 bytes



                                                              time if [incr i]%10!=2&$i/10!=2 puts $i 100


                                                              Try it online!







                                                              Tcl, 50 bytes



                                                              time if 2 ni [split [incr i] ""] puts $i 100


                                                              Try it online!








                                                              share|improve this answer
























                                                                up vote
                                                                0
                                                                down vote










                                                                up vote
                                                                0
                                                                down vote










                                                                Tcl, 47 bytes



                                                                time if [incr i]%10!=2&$i/10!=2 puts $i 100


                                                                Try it online!







                                                                Tcl, 50 bytes



                                                                time if 2 ni [split [incr i] ""] puts $i 100


                                                                Try it online!








                                                                share|improve this answer















                                                                Tcl, 47 bytes



                                                                time if [incr i]%10!=2&$i/10!=2 puts $i 100


                                                                Try it online!







                                                                Tcl, 50 bytes



                                                                time if 2 ni [split [incr i] ""] puts $i 100


                                                                Try it online!









                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited 7 hours ago

























                                                                answered 7 hours ago









                                                                sergiol

                                                                2,1571825




                                                                2,1571825




















                                                                    up vote
                                                                    0
                                                                    down vote














                                                                    Red, 44 bytes



                                                                    repeat n 100[unless find form n"2"[print n]]


                                                                    Try it online!



                                                                    Uses unless instead of if not, because why not? :)






                                                                    share|improve this answer


























                                                                      up vote
                                                                      0
                                                                      down vote














                                                                      Red, 44 bytes



                                                                      repeat n 100[unless find form n"2"[print n]]


                                                                      Try it online!



                                                                      Uses unless instead of if not, because why not? :)






                                                                      share|improve this answer
























                                                                        up vote
                                                                        0
                                                                        down vote










                                                                        up vote
                                                                        0
                                                                        down vote










                                                                        Red, 44 bytes



                                                                        repeat n 100[unless find form n"2"[print n]]


                                                                        Try it online!



                                                                        Uses unless instead of if not, because why not? :)






                                                                        share|improve this answer















                                                                        Red, 44 bytes



                                                                        repeat n 100[unless find form n"2"[print n]]


                                                                        Try it online!



                                                                        Uses unless instead of if not, because why not? :)







                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited 6 hours ago

























                                                                        answered 7 hours ago









                                                                        Galen Ivanov

                                                                        4,9471929




                                                                        4,9471929




















                                                                            up vote
                                                                            0
                                                                            down vote














                                                                            Stax, 6 bytes



                                                                            Ç░τ╒╜h


                                                                            Run and debug it



                                                                            Unpacked, ungolfed, and commented, it looks like this.



                                                                            AJ 10 squared
                                                                            f output each value in [1 .. n] satisfying the following filter
                                                                            E get array of decimal digits in number
                                                                            2# count the number of 2s
                                                                            ! logical not


                                                                            Run this one






                                                                            share|improve this answer
























                                                                              up vote
                                                                              0
                                                                              down vote














                                                                              Stax, 6 bytes



                                                                              Ç░τ╒╜h


                                                                              Run and debug it



                                                                              Unpacked, ungolfed, and commented, it looks like this.



                                                                              AJ 10 squared
                                                                              f output each value in [1 .. n] satisfying the following filter
                                                                              E get array of decimal digits in number
                                                                              2# count the number of 2s
                                                                              ! logical not


                                                                              Run this one






                                                                              share|improve this answer






















                                                                                up vote
                                                                                0
                                                                                down vote










                                                                                up vote
                                                                                0
                                                                                down vote










                                                                                Stax, 6 bytes



                                                                                Ç░τ╒╜h


                                                                                Run and debug it



                                                                                Unpacked, ungolfed, and commented, it looks like this.



                                                                                AJ 10 squared
                                                                                f output each value in [1 .. n] satisfying the following filter
                                                                                E get array of decimal digits in number
                                                                                2# count the number of 2s
                                                                                ! logical not


                                                                                Run this one






                                                                                share|improve this answer













                                                                                Stax, 6 bytes



                                                                                Ç░τ╒╜h


                                                                                Run and debug it



                                                                                Unpacked, ungolfed, and commented, it looks like this.



                                                                                AJ 10 squared
                                                                                f output each value in [1 .. n] satisfying the following filter
                                                                                E get array of decimal digits in number
                                                                                2# count the number of 2s
                                                                                ! logical not


                                                                                Run this one







                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered 10 mins ago









                                                                                recursive

                                                                                4,4461220




                                                                                4,4461220




















                                                                                    up vote
                                                                                    0
                                                                                    down vote














                                                                                    PowerShell, 22 bytes





                                                                                    1..100|?$_-notmatch2


                                                                                    Try it online!



                                                                                    Generates the range 1 to 100, then pulls out those objects where |?... they do -notmatch the number 2. Each item is left on the pipeline, and output is implicit.





                                                                                    share
























                                                                                      up vote
                                                                                      0
                                                                                      down vote














                                                                                      PowerShell, 22 bytes





                                                                                      1..100|?$_-notmatch2


                                                                                      Try it online!



                                                                                      Generates the range 1 to 100, then pulls out those objects where |?... they do -notmatch the number 2. Each item is left on the pipeline, and output is implicit.





                                                                                      share






















                                                                                        up vote
                                                                                        0
                                                                                        down vote










                                                                                        up vote
                                                                                        0
                                                                                        down vote










                                                                                        PowerShell, 22 bytes





                                                                                        1..100|?$_-notmatch2


                                                                                        Try it online!



                                                                                        Generates the range 1 to 100, then pulls out those objects where |?... they do -notmatch the number 2. Each item is left on the pipeline, and output is implicit.





                                                                                        share













                                                                                        PowerShell, 22 bytes





                                                                                        1..100|?$_-notmatch2


                                                                                        Try it online!



                                                                                        Generates the range 1 to 100, then pulls out those objects where |?... they do -notmatch the number 2. Each item is left on the pipeline, and output is implicit.






                                                                                        share











                                                                                        share


                                                                                        share










                                                                                        answered 51 secs ago









                                                                                        AdmBorkBork

                                                                                        24.7k360215




                                                                                        24.7k360215




















                                                                                            Monolica is a new contributor. Be nice, and check out our Code of Conduct.









                                                                                             

                                                                                            draft saved


                                                                                            draft discarded


















                                                                                            Monolica is a new contributor. Be nice, and check out our Code of Conduct.












                                                                                            Monolica is a new contributor. Be nice, and check out our Code of Conduct.











                                                                                            Monolica is a new contributor. Be nice, and check out our Code of Conduct.













                                                                                             


                                                                                            draft saved


                                                                                            draft discarded














                                                                                            StackExchange.ready(
                                                                                            function ()
                                                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173189%2fnumber-sequence-challenge%23new-answer', 'question_page');

                                                                                            );

                                                                                            Post as a guest













































































                                                                                            Comments

                                                                                            Popular posts from this blog

                                                                                            Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                                                                            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                                                                            Confectionery