# Display numbers lacking 2's

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

• I assume the winning criteria is code-golf right? – Luis felipe De jesus Munoz Oct 2 '18 at 13:26
• 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 Oct 2 '18 at 14:08
• Might I suggest using the Sandbox in the future to get feedback on your challenges before posting? – Jo King Oct 2 '18 at 14:15
• @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 Oct 2 '18 at 14:19
• @user202729 Arbitrary restriction is unwelcome, not disallowed. – Jonathan Frech Oct 3 '18 at 1:11

# 05AB1E, 6 bytes

тLʒ2å_


Try it online!

Explanation

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


# Python 2, 44 bytes

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


Try it online!

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

# Retina, 19 17 bytes


100*
.
$.>¶ A2  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.

A2


Remove all entries that contain a 2.

• Does . $.>¶ work for the second stage? – ovs Oct 3 '18 at 13:41 • @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 Oct 3 '18 at 16:40

# 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

• remove the brackets around the numbers. Otherwise it is fine. – Monolica Oct 2 '18 at 14:01
• @Monolica Fixed – Jo King Oct 2 '18 at 14:05
• @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 Oct 3 '18 at 6:33

# 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


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!

• # Tcl, 49 bytes time {if [string f 2 [incr i]]==-1 {puts $i}} 100Failed outgolf! – sergiol Oct 3 '18 at 9:45 • You could replace your test with a regexp: ![regexp 2 [incr i]] for -3 bytes – david Nov 23 '18 at 5:59 • @david How was it possible I didn't come with the solution suggested by you of using regular expressions? Thanks. – sergiol Nov 23 '18 at 10:20 # 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? :) # R, 19 bytes grep(2,1:100,inv=T)  Try it online! • grep(2,1:100,inv=T) for 19. – J.Doe Oct 2 '18 at 18:34 • 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 Oct 2 '18 at 19:02 • Inverting the regex itself is a byte shorter (in this case). – ngm Oct 2 '18 at 19:23 • Doesn't work, still lets 2s past. You'd need ^[^2]*$ which is, um, not shorter. – J.Doe Oct 2 '18 at 19:24
• What, are we supposed to check our answers now? – ngm Oct 2 '18 at 19:25

# 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

• This is so cool! – Emigna Oct 2 '18 at 20:02
• 41 bytes using your trick if we could have a leading comma. – Oliver Oct 3 '18 at 1:22

# 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

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

• ? 1..100-notmatch2 – mazzy Oct 3 '18 at 11:51
• @mazzy Of course, why didn't I think of that? Thanks! – AdmBorkBork Oct 3 '18 at 12:26

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

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'. • 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 Oct 3 '18 at 1:04
• @JonathanFrech Wow, missed that. :/ No clue where that space went! It's there in the TIO... – Khuldraeseth na'Barya Oct 3 '18 at 1:31
• Haskell has notElem for not.elem, but even shorter is all(/='2'). – xnor Oct 3 '18 at 1:47

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


# Kotlin, 32 bytes

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


Try it online!

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

• I don't know if the consensus is that the Print is necessary, but who really cares, anyway. – Misha Lavrov Oct 3 '18 at 1:40
• [...] but who really cares, anyway. -- that's the spirit ... – Jonathan Frech Oct 3 '18 at 1:54
• Do \[LeftCeiling] and \[RightCeiling] really count as a single byte :) – user6014 Oct 5 '18 at 0:41
• @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 Oct 5 '18 at 1:37
• @MishaLavrov Sounds fair ! Neat solution. – user6014 Oct 5 '18 at 1:37

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

• – Jonathan Frech Oct 3 '18 at 2:44
• @JonathanFrech thanks that's clever! – Asleepace Oct 3 '18 at 2:48

# Bash + GNU utilities, 16

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


Try it online!

# Bash, 31 bytes

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


Try it online!

Thanks to Digital Trauma for short loop.

• Welcome to PPCG! How about echo $i instead of the printf? Or even better printf %d\\n {1..100}|grep -v 2? – Digital Trauma Oct 3 '18 at 3:12 • yeah right. i ll update my answer. – ketone Oct 3 '18 at 3:14 • i am learning actually i don't know that much btw thanks. – ketone Oct 3 '18 at 3:16 • Just beats my echo {1..100}|tr ' ' \\n|grep -v 2 – Mark Perryman Oct 3 '18 at 8:35 • -1 byte if you use sed /2/d instead of grep -v 2. – Ruslan Oct 5 '18 at 21:58 # 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. # 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.

• Nice use of PHP's wacky behavior to separate the numbers, lol – Roberto Maldonado Oct 3 '18 at 5:19
• The 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 Oct 3 '18 at 7:50

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

# 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?


# 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


# 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

• 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 Oct 4 '18 at 5:06
• @Joking in this case 'codepage' is 2 bytes for one char – RosLuP Oct 4 '18 at 5:11

# 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

# 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''


# 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


# 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