Number Sequence Challenge
Clash 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
code-golf sequence kolmogorov-complexity
New contributor
 |Â
show 5 more comments
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
code-golf sequence kolmogorov-complexity
New contributor
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
 |Â
show 5 more comments
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
code-golf sequence kolmogorov-complexity
New contributor
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
code-golf sequence kolmogorov-complexity
New contributor
New contributor
edited 20 mins ago
AdmBorkBork
24.7k360215
24.7k360215
New contributor
asked 7 hours ago
Monolica
463
463
New contributor
New contributor
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
 |Â
show 5 more comments
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
 |Â
show 5 more comments
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
add a comment |Â
up vote
4
down vote
R, 19 bytes
grep(2,1:100,inv=T)
Try it online!
grep(2,1:100,inv=T)
for 19.
â J.Doe
2 hours ago
1
Ha - this was what I tried at first but withv=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
add a comment |Â
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!
add a comment |Â
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
add a comment |Â
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
This is so cool!
â Emigna
1 hour ago
add a comment |Â
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
.
add a comment |Â
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
remove the brackets around the numbers. Otherwise it is fine.
â Monolica
7 hours ago
@Monolica Fixed
â Jo King
7 hours ago
add a comment |Â
up vote
0
down vote
Japt, 7 bytes
Lõs kø2
Try it online!
add a comment |Â
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!
add a comment |Â
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? :)
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
05AB1E, 6 bytes
ÃÂLÃÂ2ÃÂ¥_
Try it online!
Explanation
ÃÂL # push [1 ... 100]
ÃÂ # filter, keep only elements that
2ÃÂ¥_ # does not contain 2
answered 7 hours ago
Emigna
43.5k431131
43.5k431131
add a comment |Â
add a comment |Â
up vote
4
down vote
R, 19 bytes
grep(2,1:100,inv=T)
Try it online!
grep(2,1:100,inv=T)
for 19.
â J.Doe
2 hours ago
1
Ha - this was what I tried at first but withv=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
add a comment |Â
up vote
4
down vote
R, 19 bytes
grep(2,1:100,inv=T)
Try it online!
grep(2,1:100,inv=T)
for 19.
â J.Doe
2 hours ago
1
Ha - this was what I tried at first but withv=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
add a comment |Â
up vote
4
down vote
up vote
4
down vote
R, 19 bytes
grep(2,1:100,inv=T)
Try it online!
R, 19 bytes
grep(2,1:100,inv=T)
Try it online!
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 withv=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
add a comment |Â
grep(2,1:100,inv=T)
for 19.
â J.Doe
2 hours ago
1
Ha - this was what I tried at first but withv=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
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
Python 2, 44 bytes
print[n for n in range(1,101)if'2'not in`n`]
Try it online!
answered 7 hours ago
TFeld
12k2833
12k2833
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered 7 hours ago
Kevin Cruijssen
30.9k553168
30.9k553168
add a comment |Â
add a comment |Â
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
This is so cool!
â Emigna
1 hour ago
add a comment |Â
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
This is so cool!
â Emigna
1 hour ago
add a comment |Â
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
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
edited 5 hours ago
answered 7 hours ago
Arnauld
65.6k583277
65.6k583277
This is so cool!
â Emigna
1 hour ago
add a comment |Â
This is so cool!
â Emigna
1 hour ago
This is so cool!
â Emigna
1 hour ago
This is so cool!
â Emigna
1 hour ago
add a comment |Â
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
.
add a comment |Â
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
.
add a comment |Â
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
.
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
.
answered 7 hours ago
Neil
75.8k744171
75.8k744171
add a comment |Â
add a comment |Â
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
remove the brackets around the numbers. Otherwise it is fine.
â Monolica
7 hours ago
@Monolica Fixed
â Jo King
7 hours ago
add a comment |Â
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
remove the brackets around the numbers. Otherwise it is fine.
â Monolica
7 hours ago
@Monolica Fixed
â Jo King
7 hours ago
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
up vote
0
down vote
Japt, 7 bytes
Lõs kø2
Try it online!
add a comment |Â
up vote
0
down vote
Japt, 7 bytes
Lõs kø2
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Japt, 7 bytes
Lõs kø2
Try it online!
Japt, 7 bytes
Lõs kø2
Try it online!
answered 7 hours ago
Luis felipe De jesus Munoz
3,0361046
3,0361046
add a comment |Â
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
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!
edited 7 hours ago
answered 7 hours ago
sergiol
2,1571825
2,1571825
add a comment |Â
add a comment |Â
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? :)
add a comment |Â
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? :)
add a comment |Â
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? :)
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? :)
edited 6 hours ago
answered 7 hours ago
Galen Ivanov
4,9471929
4,9471929
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered 10 mins ago
recursive
4,4461220
4,4461220
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered 51 secs ago
AdmBorkBork
24.7k360215
24.7k360215
add a comment |Â
add a comment |Â
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.
Monolica is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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