Display numbers lacking 2's

22

4

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

Monolica

Posted 2018-10-02T13:20:17.127

Reputation: 1 101

7I assume the winning criteria is code-golf right? – Luis felipe De jesus Munoz – 2018-10-02T13:26:01.320

Does the order matter? ('Sequence' seems to imply that it does.) – Arnauld – 2018-10-02T13:31:33.483

Can we output from 100 to 1 instead of 1 to 100? – Kevin Cruijssen – 2018-10-02T13:59:58.717

Yes the order matters. – Monolica – 2018-10-02T14:04:50.717

4

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 – 2018-10-02T14:08:38.180

1

Might I suggest using the Sandbox in the future to get feedback on your challenges before posting?

– Jo King – 2018-10-02T14:15:55.897

the shortest possible python code wins. – Monolica – 2018-10-02T14:16:34.087

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 – 2018-10-02T14:19:17.310

I added [tag:code-golf] since that seems to be the closest applicable tag for OP's intended challenge – dylnan – 2018-10-02T18:26:24.800

1From review queue, I think as it is the question is under-specified. If the order matters, edit that into the question. People should not need to read comments to know the challenge. – mbomb007 – 2018-10-02T20:17:07.043

1Instead of replying in the comments, [edit] the post. – user202729 – 2018-10-03T00:15:59.633

Also, arbitrarily restricting the language is disallowed.

– user202729 – 2018-10-03T00:17:37.707

4@user202729 Arbitrary restriction is unwelcome, not disallowed. – Jonathan Frech – 2018-10-03T01:11:31.010

1Can we print leading zeroes for any number? – Jo King – 2018-10-03T04:10:32.013

@JonathanFrech Uh, that's right, it's "avoided". – user202729 – 2018-10-03T04:21:31.980

May we output 0 as well? Or 0 to 99? – Okx – 2018-10-03T13:24:03.133

Pretty cool that this has a score of 22 votes – ElPedro – 2019-08-21T18:01:07.893

Answers

12

05AB1E, 6 bytes

тLʒ2å_

Try it online!

Explanation

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

Emigna

Posted 2018-10-02T13:20:17.127

Reputation: 50 798

26

Taxi, 2399 2391 2370 1783 1773 1706 bytes

-8 bytes for realizing that, instead of leaving a certain passenger at Sunny Side Park forever, it's more worth it to throw them off of Riverview Bridge. Ah, what a lovely town this is.

-21 bytes for taking out a comment I stupidly left in.

-587 bytes by simply changing the entire way I went about this (apparently a shorter way is by arithmetic; integer-dividing [17, 27, 37, 47,...] by 9 yields the sequence, but you gotta skip over the 20's yourself.)

-17 bytes for the realization that any quotes-encased string without a space doesn't need quotes after all (thanks Jo King!).

-67 bytes for the realization that linebreaks are optional.

17 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 l 2 r 1 l 1 l 2 l.Pickup a passenger going to Cyclone.Go to Cyclone:e 1 l 2 r.[B]Pickup a passenger going to Cyclone.Pickup a passenger going to Divide and Conquer.9 is waiting at Starchild Numerology.Go to Starchild Numerology:s 2 l 2 r.Pickup a passenger going to Divide and Conquer.Go to Divide and Conquer:e 1 l 2 r 3 r 2 r 1 r.Pickup a passenger going to Trunkers.Go to Trunkers:e 1 r 3 r 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:e 1 r 1 r.Pickup a passenger going to Post Office.\n is waiting at Writer's Depot.Go to Writer's Depot:n 5 l 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.Go to Cyclone:s 1 r 1 l 2 r.Pickup a passenger going to Addition Alley.Pickup a passenger going to Equal's Corner.177 is waiting at Starchild Numerology.Go to Starchild Numerology:s 2 l 2 r.Pickup a passenger going to Equal's Corner.Go to Equal's Corner:w 1 l.Switch to plan C if no one is waiting.Pickup a passenger going to Sunny Skies Park.100 is waiting at Starchild Numerology.Switch to plan D.[C]10 is waiting at Starchild Numerology.[D]Go to Starchild Numerology:n 1 r.Pickup a passenger going to Addition Alley.Go to Sunny Skies Park:w 1 r.Go to Addition Alley:n 1 r 1 r 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 1 l.Pickup a passenger going to Cyclone.Pickup a passenger going to Equal's Corner.917 is waiting at Starchild Numerology.Go to Starchild Numerology:s 2 l 2 r.Pickup a passenger going to Equal's Corner.Go to Equal's Corner:w 1 l.Switch to plan E if no one is waiting.Switch to plan F.[E]Go to Go More:n 1 l.Go to Cyclone:w 1 r.Switch to plan B.[F]

Try it online!

This one isn't winning me any code golf competitions anytime soon, but I decided to try out the esolang Taxi.

Taxi is an esolang in which all programming is done by picking up and dropping off passengers at various stops in the fictional town of Townsburg. Of course, your taxicab will sometimes run out of gas, so you also need to visit gas stations every so often, and pay using the credits you receive as fare (in this case, I only need to stop for gas - at Go More - once per loop iteration!).

I used some tricks that reduce the filesize a bit, such as rephrasing directions like east 1st left, 2nd right as e 1 l 2 r, removing the word the where it is optional, and using the least complicated route towards all of my destinations (not necessarily the shortest path).

I hate this shorter solution more than the one I originally came up with. This solution down here is a more general way of accomplishing the task, which could start and end anywhere you want. Here it is, in its entirety.

2245 bytes (way more general)

1 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 l 2 r 1 l 1 l 2 l.Pickup a passenger going to Cyclone.Go to Cyclone:e 1 l 2 r.[B]Pickup a passenger going to Addition Alley.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:n 2 r 2 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 5 l 2 l.Pickup a passenger going to Chop Suey.Go to Zoom Zoom:n.0 is waiting at Writer's Depot.Go to Writer's Depot:w.Pickup a passenger going to Narrow Path Park.Go to Narrow Path Park:n 3 r 1 l 1 r.Go to Chop Suey:e 1 r 1 l 1 r.[C]Switch to plan E if no one is waiting.Pickup a passenger going to Crime Lab.2 is waiting at Writer's Depot.Go to Writer's Depot:n 1 l 3 l.Pickup a passenger going to Crime Lab.Go to Crime Lab:n 3 r 2 r.Switch to plan D if no one is waiting.Pickup a passenger going to KonKat's.Go to Narrow Path Park:n 5 l.Pickup a passenger going to KonKat's.Go to KonKat's:e 1 r.Pickup a passenger going to Narrow Path Park.Go to Narrow Path Park:n 2 l.Go to Chop Suey:e 1 r 1 l 1 r.Switch to plan C.[D]Go to Chop Suey:n 5 r 1 l.Switch to plan C.[E]Go to Narrow Path Park:n 1 l 1 r 1 l.Pickup a passenger going to Crime Lab.0 is waiting at Writer's Depot.Go to Writer's Depot:w 1 l 1 r 2 l.1 is waiting at Starchild Numerology.Pickup a passenger going to Crime Lab.Go to Crime Lab:n 3 r 2 r.Switch to plan F if no one is waiting.Pickup a passenger going to Riverview Bridge.Go to Cyclone:n 4 l 2 l.Pickup a passenger going to Post Office.Go to Riverview Bridge:n 2 r.\n is waiting at Writer's Depot.Go to Writer's Depot:w 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.Go to Starchild Numerology:s 1 r 1 l 1 l 2 l.Switch to plan G.[F]Go to Cyclone:s 1 r 1 l 2 r.Pickup a passenger going to Riverview Bridge.Go to Riverview Bridge:n 2 r.Go to Starchild Numerology:w 2 l 3 l 2 r.[G]Pickup a passenger going to Addition Alley.Go to Addition Alley:e 1 l 2 r 3 r 1 r.Pickup a passenger going to Magic Eight.101 is waiting at Starchild Numerology.Go to Starchild Numerology:n 1 l 1 l 3 l 2 r.Pickup a passenger going to Magic Eight.Go to Magic Eight:w 1 r 2 r 1 r.Switch to plan H if no one is waiting.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 2 r.Switch to plan B.[H]

Try it online!

And if mega-cheating is allowed, this one is way shorter than either of the last two.

456 bytes (totally cheating)

1\n3\n4\n5\n6\n7\n8\n9\n10\n11\n13\n14\n15\n16\n17\n18\n19\n30\n31\n33\n34\n35\n36\n37\n38\n39\n40\n41\n43\n44\n45\n46\n47\n48\n49\n50\n51\n53\n54\n55\n56\n57\n58\n59\n60\n61\n63\n64\n65\n66\n67\n68\n69\n70\n71\n73\n74\n75\n76\n77\n78\n79\n80\n81\n83\n84\n85\n86\n87\n88\n89\n90\n91\n93\n94\n95\n96\n97\n98\n99\n100 is waiting at Writer's Depot.Go to Writer's Depot:w 1 l 2 r 1 l 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.

Try it online!

JosiahRyanW

Posted 2018-10-02T13:20:17.127

Reputation: 2 600

That quotes thing is a helpful one, thanks. However, I disagree with the "don't have to go to the Taxi Garage" thing. Is exiting with an error allowed? I can't find a good set of general rules on this. – JosiahRyanW – 2018-10-05T17:11:00.743

Yeah, generally STDERR is ignored. Relevant meta

– Jo King – 2018-10-05T21:28:27.123

Some of my answers could benefit from that. – JosiahRyanW – 2018-10-05T21:56:53.933

22

Python 2, 39 bytes

k=7
exec"k+=10;print(k>177)*10+k/9;"*81

Try it online!

Uses arithmetic operations only to generate numbers without 2's.

The value k follows the arithmetic progression 17, 27, 37, 47, ..., which when floor-divided by 9 gives 1,3,4,5,6,7,8,9,10,11,13,14,... which counts up numbers not ending in 2. To skip 20 through 29, outputs are increased by 10 past a certain threshold.

xnor

Posted 2018-10-02T13:20:17.127

Reputation: 115 687

14

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

Arnauld

Posted 2018-10-02T13:20:17.127

Reputation: 111 334

1This is so cool! – Emigna – 2018-10-02T20:02:07.017

141 bytes using your trick if we could have a leading comma. – Oliver – 2018-10-03T01:22:59.843

12

R, 19 bytes

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

Try it online!

ngm

Posted 2018-10-02T13:20:17.127

Reputation: 3 974

grep(2,1:100,inv=T) for 19. – J.Doe – 2018-10-02T18:34:39.500

2Ha - 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 – 2018-10-02T19:02:37.037

Inverting the regex itself is a byte shorter (in this case). – ngm – 2018-10-02T19:23:31.777

Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter. – J.Doe – 2018-10-02T19:24:22.463

4What, are we supposed to check our answers now? – ngm – 2018-10-02T19:25:26.253

10

Python 2, 44 bytes

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

Try it online!

TFeld

Posted 2018-10-02T13:20:17.127

Reputation: 19 246

10

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

Jo King

Posted 2018-10-02T13:20:17.127

Reputation: 38 234

remove the brackets around the numbers. Otherwise it is fine. – Monolica – 2018-10-02T14:01:13.357

@Monolica Fixed – Jo King – 2018-10-02T14:05:07.617

1@Monolica It seems a little weird that you singled my answer out as not allowed to print as a list, where so many other answers do so. On the other hand, it doesn't cost me any bytes, so whatever – Jo King – 2018-10-03T06:33:58.923

7

PowerShell, 22 16 bytes

1..100-notmatch2

Try it online!

-6 bytes thanks to mazzy

Generates the range 1 to 100, then pulls out those objects where they do -notmatch the number 2. Running the -notmatch against an array like this acts like a filter on the array. Each item is left on the pipeline, and output is implicit.

AdmBorkBork

Posted 2018-10-02T13:20:17.127

Reputation: 41 581

? 1..100-notmatch2 – mazzy – 2018-10-03T11:51:52.060

@mazzy Of course, why didn't I think of that? Thanks! – AdmBorkBork – 2018-10-03T12:26:04.030

6

Japt, 7 bytes

Lõs kø2

Lõs kø2     Full Program
Lõs         Range ["1"..."100"] (numbers are casted to string)
    k       Remove
     ø2     anything that contains "2"

Try it online!

Luis felipe De jesus Munoz

Posted 2018-10-02T13:20:17.127

Reputation: 9 639

6

Haskell, 48 33 31 bytes

Thanks @JonathanFrech for fifteen bytes saved, and @xnor for another two! I missed a big golf and didn't realize main=print$ can be omitted.

filter(all(/='2').show)[1..100]

Try it online!

Easily extended by changing the 100. Stringifies all the numbers and keeps only those without a '2'.

Khuldraeseth na'Barya

Posted 2018-10-02T13:20:17.127

Reputation: 2 608

See this; the main=print$ is not necessary. Have you tested your code? I do not think that elem'2' is valid syntax. Why map? Simply filter(not.elem '2'.show)[1..100] does the job. – Jonathan Frech – 2018-10-03T01:04:49.003

@JonathanFrech Wow, missed that. :/ No clue where that space went! It's there in the TIO... – Khuldraeseth na'Barya – 2018-10-03T01:31:24.277

2Haskell has notElem for not.elem, but even shorter is all(/='2'). – xnor – 2018-10-03T01:47:07.793

6

Bash + GNU utilities, 16

  • 1 byte saved thanks to @Dennis.
seq 100|sed /2/d

Try it online!

Digital Trauma

Posted 2018-10-02T13:20:17.127

Reputation: 64 644

5

Retina, 19 17 bytes


100*
.
$.>`¶
A`2

Try it online! Edit: Saved 2 bytes thanks to @ovs, although the last line now includes a newline. Explanation:


100*

Insert 100 characters.

.
$.>`¶

Replace each character with the number of characters up to and including that character, plus a newline.

A`2

Remove all entries that contain a 2.

Neil

Posted 2018-10-02T13:20:17.127

Reputation: 95 035

Does . $.>\¶` work for the second stage? – ovs – 2018-10-03T13:41:58.230

@ovs I had had something more complicated before and switched to L$ to avoid a leading newline, so I hadn't realised I could switch back, thanks. – Neil – 2018-10-03T16:40:50.690

5

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

Kevin Cruijssen

Posted 2018-10-02T13:20:17.127

Reputation: 67 575

4

Tcl, 44 bytes

time {if ![regexp 2 [incr i]] {puts $i}} 100

Try it online!


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!

sergiol

Posted 2018-10-02T13:20:17.127

Reputation: 3 055

# Tcl, 49 bytes time {if [string f 2 [incr i]]==-1 {puts $i}} 100Failed outgolf! – sergiol – 2018-10-03T09:45:02.557

You could replace your test with a regexp: ![regexp 2 [incr i]] for -3 bytes – david – 2018-11-23T05:59:10.113

@david How was it possible I didn't come with the solution suggested by you of using regular expressions? Thanks. – sergiol – 2018-11-23T10:20:32.370

4

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

recursive

Posted 2018-10-02T13:20:17.127

Reputation: 8 616

4

Wolfram Language (Mathematica), 42 bytes

Print@⌈Range[1,100,10/9]~Drop~{18,26}⌉

Try it online!

The arithmetic sequence 1, 19/9, 29/9, 39/9, ... grows at just the right rate that taking the ceiling skips all the numbers ending in 2. Then we get rid of 20 through 29 by Dropping the values at indices 18 through 26.

Misha Lavrov

Posted 2018-10-02T13:20:17.127

Reputation: 4 846

I don't know if the consensus is that the Print is necessary, but who really cares, anyway. – Misha Lavrov – 2018-10-03T01:40:04.020

[...] but who really cares, anyway. -- that's the spirit ... – Jonathan Frech – 2018-10-03T01:54:09.047

Do \[LeftCeiling] and \[RightCeiling] really count as a single byte :) – user6014 – 2018-10-05T00:41:09.140

@user6014 I'm counting them as the 3 bytes they take up in Unicode, but it's still a bit cheaper than an actual Ceiling command. – Misha Lavrov – 2018-10-05T01:37:23.447

@MishaLavrov Sounds fair ! Neat solution. – user6014 – 2018-10-05T01:37:58.477

4

C (GCC), 62 55 Bytes

• 7 Bytes thanks to Jonathan Frech

f(n){for(n=0;++n-101;n/10-2&&n%10-2&&printf("%d,",n));}

Loops from 1 to 100 and prints the number only if 2 is not in the ones or tens place.

Try it online!

Asleepace

Posted 2018-10-02T13:20:17.127

Reputation: 311

155 bytes. – Jonathan Frech – 2018-10-03T02:44:09.240

@JonathanFrech thanks that's clever! – Asleepace – 2018-10-03T02:48:00.047

4

Powershell, 19 bytes

1..100-split'.*2.*'

This script show null-value instead 'numbers with 2 inside' and completely solves the task 'number 2 shouldn’t appear anywhere in the sequence'.

Output:

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

Powerhsell (output does not contain null-values), 24 bytes

1..100-split'.*2.*'-ne''

mazzy

Posted 2018-10-02T13:20:17.127

Reputation: 4 832

4

Python 3, 53 51 50 49 46 bytes

['2'in str(n)or print(n)for n in range(1,101)]

Try it online!

Not the strongest language for this task, but I'm new to golfing.

Thanks to the commenters for their tips!

Gigaflop

Posted 2018-10-02T13:20:17.127

Reputation: 221

Welcome to PPCG! You can get it down to a round 50 by deleting the space before the if. – ElPedro – 2018-10-03T18:07:03.177

[print(n)for n in range(1,101)if"2"not in str(n)] works. – JosiahRyanW – 2018-10-04T19:22:38.400

Alternatively, based on one of the Python 2 answers: n=17;exec("print((n>177)*10+n//9);n+=10;"*81) – JosiahRyanW – 2018-10-04T19:24:51.443

@JosiahRyanW I wasn't aware of the implicit print, thanks! – Gigaflop – 2018-10-04T19:29:20.733

It's not really "implicit printing", but rather a print statement inside a list comprehension. You still need the print statement. – JosiahRyanW – 2018-10-04T19:30:04.257

@JosiahRyanW I misread your comment and saved just the list comprehension [print(n)for n in range(1,101)if"2"not in str(n)] as a one-line file, and it output the desired results when I ran it. That's what I thought was implicit printing. – Gigaflop – 2018-10-04T19:33:10.710

@Gigaflop Ah, I get it. Still, I do find it cool that they're able to do that. – JosiahRyanW – 2018-10-04T19:34:52.013

1'2'in str(n)or print(n) is shorter than a comprehension guard. – Jonathan Frech – 2018-10-09T03:01:34.863

@JonathanFrech Thanks for the tip! – Gigaflop – 2018-10-09T12:49:22.410

4

sh + coreutils, 16 chars

seq 100|sed /2/d

Generates sequence from 1 to 100 (inclusive) and deletes any lines that have '2' in them.

2xsaiko

Posted 2018-10-02T13:20:17.127

Reputation: 699

This code is identical to answer by Digital Trauma.

– Ruslan – 2018-10-05T21:55:15.860

oh crap, didn't see that one, even though I checked. Should I delete this since mine was posted later? – 2xsaiko – 2018-10-06T07:50:31.693

4

Z80Golf, 49 48 bytes

00000000: 1630 2e0a 5faf f57b fe02 2818 82ff f182  .0.._..{..(.....
00000010: ff92 3cf5 7dff f1bd 280a fe02 2803 f518  ..<.}...(...(...
00000020: e63c 18fa 7b3c bd20 db3e 31ff 3dff ff76  .<..{<. .>1.=..v

Try it online!

Assembly:

ld d, 30h			; ascii '0' character
ld l, 0Ah			; number 10 and ascii newline
tens:
	ld e,a			; store tens digit
	xor a			; reset ones digit to 0
	push af			; store initial ones digit 0
	ones:
		ld a,e		; get stored tens digit
		cp 2
		jr z,cont	; if tens digit==2(e.g.20-29),skip loop
		add d
		rst 38h 	; print tens digit
		pop af		; get stored ones digit
		add d
		rst 38h 	; print ones digit
		sub d
		inc a		; increment ones digit
		push af		; store ones digit
		ld a, l
		rst 38h 	; print newline
		pop af		; get stored ones digit again
		cp l
		jr z,cont	; if ones digit==10, break loop
		cp 2
		jr z,inc_again	; if ones digit==2, incr again
		repeat_loop:
		push af		; store ones digit again
		jr ones		; repeat print loop
		inc_again:
			inc a
			jr repeat_loop
		
	cont:
	ld a,e			; get stored tens digit
	inc a			; increment tens digit
	cp l
	jr nz, tens		; if tens place!=10, continue loop
ld a,31h
rst 38h				; print '1'
dec a
rst 38h				; print '0'
rst 38h				; print '0'
halt

Saved one byte with the repeat_loop jump

Logern

Posted 2018-10-02T13:20:17.127

Reputation: 845

3

Kotlin, 32 bytes

{(1..100).filter{'2' !in ""+it}}

Try it online!

snail_

Posted 2018-10-02T13:20:17.127

Reputation: 1 982

3

Bash, 31 bytes

printf %d\\n {1..100}|grep -v 2

Try it online!

Thanks to Digital Trauma for short loop.

ketone

Posted 2018-10-02T13:20:17.127

Reputation: 41

1Welcome to PPCG! How about echo $i instead of the printf? Or even better printf %d\\n {1..100}|grep -v 2? – Digital Trauma – 2018-10-03T03:12:05.500

yeah right. i ll update my answer. – ketone – 2018-10-03T03:14:14.683

i am learning actually i don't know that much btw thanks. – ketone – 2018-10-03T03:16:17.070

Just beats my echo {1..100}|tr ' ' \\n|grep -v 2 – Mark Perryman – 2018-10-03T08:35:48.340

-1 byte if you use sed /2/d instead of grep -v 2. – Ruslan – 2018-10-05T21:58:27.313

The entire printf can be replaced with seq 100, which delimits with newlines by default. – Sophia Lechner – 2019-03-29T22:09:20.010

3

ORK, 1092 bytes

There is such a thing as a t
A t can w a number
A t can d a number
A t has a t which is a number

When a t is to w a number:
I have a mathematician called M
M's first operand is the number
M's second operand is 1
M is to add
The number is M's result
My t is 0
I have a number called n
n is the number
I am to d n
M's first operand is my t
M's second operand is 1
M is to compare
I have a scribe called W
If M says it's less then W is to write the number
If M says it's less then W is to write " "
M's first operand is the number
M's second operand is 100
M is to compare
If M says it's less then I am to loop

When a t is to d a number:
I have a mathematician called M
M's first operand is the number
M's second operand is 10
M is to modulo
I have a mathematician called N
N's first operand is M's result
N's second operand is 2
N is to compare
If N says it's equal then my t is 1
M is to divide
The number is M's result
M's first operand is the number
M's second operand is 0
M is to compare
If M says it's greater then I am to loop

When this program starts:
I have a t called T
T is to w 0

Try it online!

Objects R Kool. Output is a space-delimited list of numbers.

This translates (approximately) to the following pseudocode:

class t {
	int t;
	
	void w(number) {
		label T_W;
		mathematician M;
		M.first_operand = number;
		M.second_operand = 1;
		M.add();
		number = M.result;
		t = 0;
		int n = number;
		d(n);
		M.first_operand = t;
		M.second_operand = 1;
		M.compare();
		scribe W;
		if M.its_less { W.write(number); }
		if M.its_less { W.write(" "); }
		M.first_operand = number;
		M.second_operand = 100;
		M.compare();
		if M.its_less { goto T_W; }
	}
	
	void d(number) {
		label T_D;
		mathematician M;
		M.first_operand = number;
		M.second_operand = 10;
		M.modulo();
		mathematician N;
		N.first_operand = M.result;
		N.second_operand = 2;
		N.compare();
		if N.its_equal { t = 1; }
		M.divide();
		number = M.result;
		M.first_operand = number;
		M.second_operand = 0;
		M.compare();
		if M.its_greater { goto T_D; }
	}
}

void main() {
	t T;
	T.w(0);
}

As you can see, everything is done using objects, including basic math and IO functions (through the built-in mathematician and scribe classes). Only whole functions can loop, which explains the need for an object with two functions to do the work.

JosiahRyanW

Posted 2018-10-02T13:20:17.127

Reputation: 2 600

3

PHP 7.1, 40 bytes

while($i++<100)strstr($i,50)||print$i._;

prints numbers separated by underscores. Run with -nr or try it online.

Titus

Posted 2018-10-02T13:20:17.127

Reputation: 13 814

Nice use of PHP's wacky behavior to separate the numbers, lol – Roberto Maldonado – 2018-10-03T05:19:07.977

1The preg_filter() based one is interesting. (I never used that function. ) That one would be shorter with preg_grep(): <?=join(_,preg_grep("/2/",range(1,100),1));. – manatwork – 2018-10-03T07:50:22.067

3

MathGolf, 7 6 bytes

♀╒Ç{2╧

Try it online!

Explanation

♀╒       Push 100 and convert to 1-based range ([1,2,...,100])
  Č{     Inverse filter by block
    2╧   Does the number contain 2?

maxb

Posted 2018-10-02T13:20:17.127

Reputation: 5 754

3

C (clang), 56 bytes

f(i){for(i=0;i++<100;i%10^2&&i/10^2&&printf("%d\n",i));}

Try it online!

Logern

Posted 2018-10-02T13:20:17.127

Reputation: 845

2

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? :)

Galen Ivanov

Posted 2018-10-02T13:20:17.127

Reputation: 13 815

2

Ruby, 35 31 bytes

100.times{|e|p e if/2/!~e.to_s}

Try it online!

Thanks to Conor O'Brien for -4 bytes

Idva

Posted 2018-10-02T13:20:17.127

Reputation: 97

2

brainfuck, 176 bytes

---------[[-<]-[>]>[>]-[-<]<++]-[>-<+++++++++]>--[>[->]<[<<<]>>[->]>-]<<,<-[-<]>[>]<[.[->+<]++++++++++.,<]>>[>]>>->-<<<<[>>>[<<[<]<.>>[>]>.[-<+>]++++++++++.,>]<<[<]<,<]>>>>.<..

Try it online!

Shorter is definitely possible. This generates the numbers 1,3,4,5,6,7,8,9 and 0,1,3,4,5,6,7,8,9. First it outputs each number in the first list, then it outputs every combination of the first and second list, then finally prints just 100.

Explanation:

---------   Push minus 9
[           Repeat 9 times
  [-<]-[>]    Add the negative of the number to the first list
  >[>]-[-<]<  Add the negative of the number to the second list
  ++          Increment the counter
]
Tape: 255 254 253 252 251 250 249 248 247 0' 0 246 247 248 249 250 251 252 253 254
-[>-<+++++++++]>--  Push 197
Tape: 255 254 253 252 251 250 249 248 247 0 197' 246 247 248 249 250 251 252 253 254
[
  >[->]<    Subtract 197 from every element in both lists to convert to digits
  [<<<]>>
  [->]>-
]
Tape: 58 57 56 55 54 53 52 51 49 0' 49 50 51 52 53 54 55 56 57
<<,<-[-<]>[>]<  Remove the 0 and the 2 from the first list
Tape: 58 57 56 55 54 53 52 51 0 0 0' 49 50 51 52 53 54 55 56 57
[  Loop over the first list
  .[->+<]        Print digit
  ++++++++++.,<  Print a newline
]
>>[>]>>->-   Remove the 2 from the second list
<<<<      
[  Loop over first list
  >>>
  [  Loop over second list
    <<[<]<.        Print first digit
    >>[>]>.        Print second digit
    [-<+>]         Move second digit over one
    ++++++++++.,>  Print a newline
  ]
  <<[<]<,<  Remove the digit from the first list and move to the next
]
>>>>.<..  Print 100 using the second list

Jo King

Posted 2018-10-02T13:20:17.127

Reputation: 38 234

2

SimpleTemplate, 51 bytes

This was a fun challenge! And it is a challenge where my language can do well.

{@forfrom 1to100}{@if_ is notmatches"<2>"}{@echol_}

Cycles through all values from 1 to 100, outputting the ones that don't have 2, separated by a newline.

You can try it on http://sandbox.onlinephpfunctions.com/code/2c97a2b6954c29844f1079938da771d51e2e0d99

Ungolfed:

{@for i from 1 to 100}
    {@if i is not matches "<2>"}
        {@echo i, "\n"}
    {@/}
{@/}

The {@/} is used to close the {@for ...} and {@if ...}, but is optional.
When compiling to PHP, it adds the needed closing.


If you're curious, the golfed code results in this PHP code:

// {@forfrom 1to100}
// ~ optimization enabled ~ inlining the results
foreach(array(...) as $DATA['_']){

    // {@if_ is notmatches"<2>"}
    if(!(preg_match("<2>", (isset($DATA['_'])?$DATA['_']:null)))) {

        // {@echol_}
        echo implode('', $FN['array_flat']((isset($DATA['_'])?$DATA['_']:null)));echo PHP_EOL;


// AUTO-CLOSE
};};

Where $FN['array_flat'] is defined outside of this code.

Ismael Miguel

Posted 2018-10-02T13:20:17.127

Reputation: 6 797

2

K4, 15 bytes

Solution:

1_&~"2"in'$!101

Example:

q)k)1_&~"2"in'$!101
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

Explanation:

1_&~"2"in'$!101 / the solution
           !101 / range 0..100
          $     / string
    "2"in'      / is "2" in each?
   ~            / not
  &             / indices where true
1_              / drop the first

Extra:

TIO for 16 byte K (oK) answer: Try it online!

streetster

Posted 2018-10-02T13:20:17.127

Reputation: 3 635

2

Jelly, 7 bytes

³D2eṆƲƇ

Try it online!

Erik the Outgolfer

Posted 2018-10-02T13:20:17.127

Reputation: 38 134

2

Pyth, 17 bytes

VS100I!}\2%"%s"NN

Try it online

My first code golf submission, also my first time using Pyth, this took way longer to put together than I expected.

Explanation

VS100 for loop from 1 to 100

I!}\2%"%s if the string "2" is in the string conversion of N

%"%sN convert N to a string. This is the only way I could figure out how to do this. If there is a shorter way to do int -> string conversion please let me know. I'm honestly just looking for a way to call str() or repr() on it with less chars.

N print n

EDIT: Looks like someone else beat me to it with Pyth. Turns out to convert N to a str I could do `N`, I'm going to leave mine the same because if I change it its almost the exact same solution.

Tryer

Posted 2018-10-02T13:20:17.127

Reputation: 71

Welcome to the site! – Khuldraeseth na'Barya – 2018-10-04T22:38:36.293

2

Scala, 56 48 47 45 42 bytes

1 to'd'filter(_+""forall(50!=))map println

Prints the elements separated by a line.

Here is a 38 bytes version that calls toString (technically allowed by the rules):

print(1 to'd'filter(_+""forall(50!=)))

Resulting in:

Vector(1, 3, 4, ..., 100)

6infinity8

Posted 2018-10-02T13:20:17.127

Reputation: 371

1

Pip, 9 bytes

2NI_FI\,h

Use any of the flags -l, -n, -s, -p to get nice-looking output. Try it online!

Explanation

        h  Preset variable: 100
      \,   1-based range: [1 2 3 ... 100]
    FI     FIlter on this function:
2NI_        2 is Not In the argument
           Print the resulting list (implicit)

DLosc

Posted 2018-10-02T13:20:17.127

Reputation: 21 213

1

JavaScript (ES6), 51 bytes

After reading Arnauld's answer, I wanted to try a non-recursive approach. Sure enough, it's longer, but it may be of some interest.

_=>[...Array(101).keys()].filter(n=>n*!/2/.test(n))

Try it online!

[...Array(101).keys()] creates a list of the numbers 0 through 100. We then filter to get rid of 0 and any number that contains a 2.

DLosc

Posted 2018-10-02T13:20:17.127

Reputation: 21 213

1

Whitespace, 121 bytes

[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T  S S S _Add][S N
S _Duplicate][S S S T   T   S S T   S T N
_Push_101][T    S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_EXIT][S N
S _Duplicate][S S S T   S T S N
_Push_10][T S T T   _Modulo][S S S T    S N
_Push_2][T  S S T   _Subtract][N
T   S N
_If_0_Jump_to_Label_LOOP][S N
S _Duplicate][S S S T   S T S N
_Push_10][T S T S _Integer_divide][S S S T  S N
_Push_2][T  S S T   _Subtract][N
T   S N
_If_0_Jump_to_Label_LOOP][S N
S _Duplicate][T N
S T _Print_integer_to_STDOUT][S S S T   S T S N
_Push_10][T N
S S _Print_character_to_STDOUT][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Pseudo-code:

Integer i = 0
Label LOOP:
  i = i+1
  If(i == 101):
    Exit program
  If(i modulo-10 == 2):
    Go to next iteration of LOOP
  If(i integer-divided by 10 == 2):
    Go to next iteration of LOOP
  Print i to STDOUT
  Print a newline to STDOUT
  Go to next iteration of LOOP

Kevin Cruijssen

Posted 2018-10-02T13:20:17.127

Reputation: 67 575

1

APL(NARS), 17 chars, 34 bytes

a/⍨∼'2'∊¨⍕¨a←⍳100

test

  a/⍨∼'2'∊¨⍕¨a←⍳100
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

RosLuP

Posted 2018-10-02T13:20:17.127

Reputation: 3 036

I don't know much about APL (much less this specific variant), but aren't the instructions typically single bytes from a different codepage? – Jo King – 2018-10-04T05:06:58.737

@Joking in this case 'codepage' is 2 bytes for one char – RosLuP – 2018-10-04T05:11:18.757

1

Gol><>, 19 bytes

`dFLP:aSD2=$2=+ZN|;

Try it online!

Explanation:

`dFLP:aSD2=$2=+ZN|;

`d                  //Push 100 to the stack
  F                 //For loop from 0 to 99
   LP               //  Push the loopcounter+1 to the stack,achieving a range [1..100]
     :              //  Double for potential output later (saves 1 byte compared to pushing it again)
      aSD           //  Push division & modulus of current number by 10
         2=         //  Check if (num % 10) == 2 , pushes either 0 or 1
           $2=      //  Check if (num / 10) == 2 , "
              +     //  Add the results acting as a logical or for is zero question
               ZN   //  If neither the mod nor the div are equal to 2 output the number
                 |; //Exit after loop

Gegell

Posted 2018-10-02T13:20:17.127

Reputation: 81

1

Ruby, 28 characters

puts [*?1..'100'].grep_v /2/

Thanks to:

Sample run:

bash-4.4$ ruby -e 'puts [*?1.."100"].grep_v /2/' | head -15
1
3
4
5
6
7
8
9
10
11
13
14
15
16
17

Try it online!

manatwork

Posted 2018-10-02T13:20:17.127

Reputation: 17 865

1

V, 14 13 bytes

Saved 1 byte thanks to @oktupol

á199ñÄj<C-a>ñç2/d

Try it online! <C-A> represents the start of heading character (0x01)

Explanation

á1            Insert a 1 on the first line
99ñ           Repeat 99 times:
 Ä             Duplicate the last line
 j<C-A>        Increment the last line by one
ñç2/          For every line containing a 2:
 d             Remove the line

Herman L

Posted 2018-10-02T13:20:17.127

Reputation: 3 611

1

Use globals to save one byte: TIO

– oktupol – 2018-10-04T13:52:26.547

1

Forth (gforth), 58 bytes

: f 101 1 do i 10 /mod 2 <> swap 2 <> * if i . then loop ;

Try it online!

Explanation

Loops from 1 to 100 (inclusive) and if both the ones and tens place of the index are not equal to 2, print it

Code explanation

: f                    \ start a new word definition
  101 1 do             \ start a loop from 1 to 100 inclusive
    i 10 /mod          \ get the quotient and remainder of dividing i by 10
    2 <>               \ check if the the tens place is not equal to 2
    swap               \ move the result down the stack one
    2 <>               \ check that the ones place is not equal to 2
    *                  \ multiply results (cheaper AND)
    if i . then        \ if true, output i
  loop                 \ end counted loop
;                      \ end word definition

reffu

Posted 2018-10-02T13:20:17.127

Reputation: 1 361

1

Pyth, 13 11 bytes

f!}`2`TS100

Try it online!

-2 with many thanks (nearly a year later!) to @ar4093

Original version:

VS*TTI!}\2`NN

Try it online!

I'm still a Pyth beginner so this could probably be improved on.

Explanation

for N in num_to_range(Psorted(times(T,T))):   # For N in range 1 to 10*10
 if Pnot(Pin("2",repr(N))):                   # If "2" is not in `N`
  imp_print(N)                                # Print N

ElPedro

Posted 2018-10-02T13:20:17.127

Reputation: 5 301

1-2 bytes by using filtering instead of a for loop: f!}\2`TS100` – ar4093 – 2019-08-21T08:50:49.530

1

MBASIC, 59 bytes

1 FOR I=1 TO 100:IF INSTR(STR$(I),"2")=0 THEN PRINT I
2 NEXT

There's probably a mathematical way to do this, but this approach is what first came to mind.

wooshinyobject

Posted 2018-10-02T13:20:17.127

Reputation: 171

1

T-SQL, 65 bytes

DECLARE @ INT=1a:IF @ NOT LIKE'%2%'PRINT @;SET @+=1IF @<101GOTO a

I'm a bit annoyed that this variable loop is shorter than the best set-based SQL variant I could find (91 bytes):

SELECT DISTINCT number FROM spt_values WHERE number>0and number<101AND number NOT LIKE'%2%'

This one even has the additional restriction of needing to be run in the master database (since it uses an undocumented system table).

The best set-based solution I could find without that requirement was 94 bytes:

WITH t AS(SELECT 1n UNION ALL SELECT n+1FROM t WHERE n<100)SELECT*FROM t WHERE n NOT LIKE'%2%'

BradC

Posted 2018-10-02T13:20:17.127

Reputation: 6 099

1

Perl 5 (5.12+), 25 bytes

$,=$/;say grep!/2/,1..100

Try it online!

Pretty straightforward. The $,=$/ makes the following print put a newline between list elements, which is shorter than using join.

hobbs

Posted 2018-10-02T13:20:17.127

Reputation: 2 403

1

Attache, 24 bytes

Output!2&`!in@List\1:100

Try it online!

Alternatively, Print=>2&`!in@List\1:100.

Filters (\) from 1:100 values whose digits (@List) do not contain (`!in) a 2 (2&), which is then Outputted.

Conor O'Brien

Posted 2018-10-02T13:20:17.127

Reputation: 36 228

1

Ruby, 31 bytes

p$.if"#{$.+=1}"!~/2/ until$.>99

Try it online!

A different, iterative approach than other ruby answers. This uses the not-match operator !~ as well as the implicitly-zero input line number variable $. as the iterator. The TIO link shows my golfing progress, from 48 bytes to 31 bytes.

Conor O'Brien

Posted 2018-10-02T13:20:17.127

Reputation: 36 228

1

F#, 66 bytes

Solution

Seq.filter(fun i->i%10<>2&&i/10<>2){1..100}|>Seq.iter(printfn"%d")

Explanation

Filters a sequence of numbers 1 to 100 by retaining those whose modulus of 10 is not 2, and which integer-divided by 10 do not result in 2, then prints the sequence with newlines between items.

This works for numbers up to and including 199. A more general solution is slightly longer (74 bytes):

Seq.filter(fun i->(string i).IndexOf '2'<0){1..100}|>Seq.iter(printfn"%d")

With proper spacing, and rearranged for readability, this looks as follows:

{1 .. 100}
|> Seq.filter (fun i -> (string i).IndexOf '2' < 0)
|> Seq.iter (printfn "%d")

dumetrulo

Posted 2018-10-02T13:20:17.127

Reputation: 131

1

C# with only Linq, 170/184 bytes

using System.Linq;class a{static void Main(string[]b)=>Enumerable.Range(1,100).ToList().ForEach(x=>System.Console.Write(x.ToString().Contains("2")?"":x.ToString()+" "));}

while this code does work, dotnetfiddle requires both the class and the main method to be public, so that the total is 14 bytes more.

Try it Online!

user71809

Posted 2018-10-02T13:20:17.127

Reputation: 21

It's way shorter not to use LINQ or ToString(): public class a{public static void Main(){for(var x=0;++x<101;)System.Console.Write((""+x).Contains("2")?"":x+" ");}} – milk – 2018-10-04T20:51:42.393

@milk huh, you're right, I actually didn't even consider that... I'll change the title to C# Linq then. – user71809 – 2018-10-05T17:43:14.477

1

[C# (.NET Core)], 63 62 bytes

Thanks to milk for saving one byte in the for loop.

for(int i=0;++i<101;)if(i%10!=2&&i/10!=2)Console.WriteLine(i);

Try it online!

Ungolfed:

for (int i = 0; ++i < 101;)         // all integers from 1-100 (starts from zero, increments before code runs)
    if (i % 10 != 2                 // all numbers not ending with '2'
                    && i / 10 != 2) // all numbers not starting with '2'
        Console.WriteLine(i);       // write to console

Meerkat

Posted 2018-10-02T13:20:17.127

Reputation: 371

2You can save 1 byte by using this pattern for the for loop: for(int i=0;++i<101;) – milk – 2018-10-04T21:00:39.743

1

Rust, 65 bytes

fn main(){for i in 1..101{if i%10!=2&&i/10!=2{println!("{}",i)}}}

Try it online!

Similar to the answers by Meerkat and dumetrulo, just iterate through and print only those whose ones digit and tens digit are not 2.

chryslovelace

Posted 2018-10-02T13:20:17.127

Reputation: 41

1

Ohm v2, 7 9 bytes

⁸#u⁇2εX

Explanation:

⁸#u⁇2εX
⁸        Push 100
 #       Push range 0..a
  u      Turn to string (vectorizes)
   ⁇     Filter only those that match conditional
    2εX  Match those that do not contain "2"

Try it online!

ThePlasmaRailgun

Posted 2018-10-02T13:20:17.127

Reputation: 383

1

LUA, 113 68 47 45 bytes

Thanks to LUA's rather loose dynamic typing, can straight-up search the integer.

Thanks to @manatwork (twice)

Thanks to @Jo King

for x=1,100 do n=("").find(x,2)or print(x)end

Try it online!

ouflak

Posted 2018-10-02T13:20:17.127

Reputation: 925

“All solutions to challenges should: (…) Be a serious contender for the winning criteria in use. For example, an entry to a code golf contest needs to be golfed, and an entry to a speed contest should make some attempt to be fast.” — [help/on-topic] Please try to reduce the size of your solution. With just minimal refactoring can become 68 characters long: x=0 while x<100 do x=x+1 if not string.find(x,2)then print(x)end end. There are some Tips for golfing in Lua to help you out.

– manatwork – 2018-10-05T09:58:59.297

Welcome to PPCG! You can golf this down to 47 bytes using a for loop and a ternary statement instead of an if

– Jo King – 2018-10-05T10:02:58.147

Thanks. Still trolling through that tips link to see what can apply. Tried a few things, but the online compiler didn't seem to like my attempts at brevity. There are obviously many answers here posted that were not going to be a contender (the C# is my favorite, but I like the Taxi answer as well). – ouflak – 2018-10-05T10:03:23.857

Ah, most people consider code-golf a competition between submissions in the same language. While a Taxi or Shakespeare submission might appear absurdly long compared to regular programming languages, remember that they are far outgolfed by any highly focused golfing language. Hope you stick around, since there aren't that many Lua golfers :) – Jo King – 2018-10-05T10:05:35.377

Thanks for the welcome. Still wondering if there isn't some way curb this even more using a goto statement. Now taking a look at your 47 byte solution... – ouflak – 2018-10-05T10:08:54.187

45 if you call the method on a string literal: ("").find(x,2) – manatwork – 2018-10-05T10:17:54.003

@manatwork, That's a nice trick. Feeling very humbled now.... – ouflak – 2018-10-05T10:23:29.273

1

Crystal, 65 bytes

(1..100).each do |x|
    x.to_s().includes?('2') ? 0 : puts x
end

Try it online!

Alice

Posted 2018-10-02T13:20:17.127

Reputation: 121

1Welcome to PPCG! You can golf this down to 49 bytes by removing some whitespace, and using the fact that do...end can be replaced by {...}: (1..100).each{|x|x.to_s.includes?('2')?0: puts x} If you use p x instead of puts x you can shave some more bytes – Conor O'Brien – 2018-10-05T14:37:19.573

1Im newer to crystal. So thanks, I didn't even know all that stuff! – Alice – 2018-10-05T14:38:13.683

@Dylan I would suggest to incorporate said golfing suggestions to improve your score. – Jonathan Frech – 2018-10-09T02:59:07.107

1

Tidy, 27 bytes

{{x:"2"!in x.0}from[1,100]}

Try it online!

Function which returns the appropriate range. x.0 concatenates x and 0 as a string.

Conor O'Brien

Posted 2018-10-02T13:20:17.127

Reputation: 36 228

1

JavaScript (Node.js), 45 44 bytes

-1 byte thanks to Neil

for(i=0;i++<100;)/2/.test(i)||console.log(i)

Try it online!

ggorlen

Posted 2018-10-02T13:20:17.127

Reputation: 121

2Can you not use || instead of ?0:? – Neil – 2018-10-07T20:33:57.000

1

Windows Batch, 49 48 bytes

@for /l %%G in (1,1,100)do @echo %%G|find /v "2"

Loops from 1 to 100, and for each number looped, only output those who does not contain any "2".

1 byte is saved by @Neil.

stevefestl

Posted 2018-10-02T13:20:17.127

Reputation: 539

You don't need that ~ do you? – Neil – 2018-10-07T20:35:02.000

Oh! You're right. It looks like I have forgotten how to code golf. – stevefestl – 2018-10-09T13:14:29.140

1

Haskell, 57 Bytes

Solution

import Data.List
unlines.nub.map(filter(/='2').show).$[1..100]

or

import Data.List
nub.map(filter(/='2').show)$[1..100]

if you just want the list.

Output

Prelude Data.List> unlines.nub.map(filter(/='2').show)$[1..]
"1\n\n3\n4\n5\n6\n7\n8\n9\n10\n11\n13\n14\n15\n16\n17\n18\n19\n0\n30\n31\n33\n34\n35\n36\n37\n38\n39\n40\n41\n43\n44\n45\n46\n47\n48\n49\n50\n51\n53\n54\n55\n56\n57\n58\n59\n60\n61\n63\n64\n65\n66\n67\n68\n69\n70\n71\n73\n74\n75\n76\n77\n78\n79\n80\n81\n83\n84\n85\n86\n87\n88\n89\n90\n91\n93\n94\n95\n96\n97\n98\n99\n100

Explanation

Makes all numbers a string, removes their '2's and weeds out the duplicates.

schuelermine

Posted 2018-10-02T13:20:17.127

Reputation: 151

1Hello and welcome to PPCG. We usually add all necessary imports to the byte count, here import Data.List. However, you can declare that your program is not written in plain Haskell, but in some variant that includes stuff by default, e.g. Haskell (lambdabot). – nimi – 2018-10-06T14:36:00.577

1Additionally to what @nimi mentioned, your answer is not valid because your program lists values over 100 too, it will print two newlines after 1 and a 0 after 19. – ბიმო – 2018-10-06T16:17:53.707

1

Ruby, 33 bytes

Solution:

puts (?1..'100').reject{|x|x[?2]}

user10421174

Posted 2018-10-02T13:20:17.127

Reputation: 11

1

JavaScript, 57 bytes

_=>`${[...Array(101).keys()]}`.replace(/^0,|\d?2.?,/g,'')

Try it online!

guest271314

Posted 2018-10-02T13:20:17.127

Reputation: 1

0

SmileBASIC, 50 bytes

@L
N=N+1IF.>INSTR(STR$(N),"2")THEN?N
ON N>99GOTO@L

Explanation:

@LABEL
 N = N + 1
 IF 0 > INSTR(STR$(N), "2") THEN PRINT N
ON N>99 GOTO @LABEL

INSTR(STR$(N), "2") is -1 if N doesn't contain a 2.

ON ... GOTO takes a list of labels, and jumps to a label in that list corresponding to the value of an expression.
If N isn't greater than 99, N>99 returns 0 so it jumps to the 0th label, @LABEL.
Otherwise, N>99 is 1 so it tries to jump to label 1 in the list, but since the list isn't long enough, it doesn't jump and the program ends.

ON is meant to be used like switch/case, with a longer list of labels. But ON x GOTO @LABEL can be used as a shorter way of writing IF !(x) GOTO @LABEL:

IF N<=99GOTO@L
IF N<100GOTO@L
ON N>99GOTO@L

12Me21

Posted 2018-10-02T13:20:17.127

Reputation: 6 110

0

ink, 34 bytes

-(i){("{i}"!?"2"):{i}}
{i<100:->i}

Try it online!

Explanation

-(i)             // Labelled gather - keeps track of how many times it's been visited (in variable i)
{"{i}"!?"2":     // If "2" is not a substring of i...
{i}              // ...print i
}
{i<100:->i}      // If i is less than 100, go back to i.

Sara J

Posted 2018-10-02T13:20:17.127

Reputation: 2 576

0

Vim, 18 bytes/keystrokes

100o0<esc>V{g<C-a>J:g/2/d<cr>

Try it online!

James

Posted 2018-10-02T13:20:17.127

Reputation: 54 537

0

C++, 84 81 bytes

-3 bytes thanks to ceilingcat

The function needs a void return value to compile with MSVC

#include<cstdio>
void f(){for(int i=0;++i<101;)i%10-2&&i/10-2&&printf("%d\n",i);}

The if read as "if the first digit isn't 2 and the second digit isn't 2"

HatsuPointerKun

Posted 2018-10-02T13:20:17.127

Reputation: 1 891

0

Perl 5, 19 bytes

map{/2/||say}1..100

Try it online!

Xcali

Posted 2018-10-02T13:20:17.127

Reputation: 7 671