2'li olmayan numaraları görüntüleme


22

Sayıları yüzlerce (artan sırada) görüntüler, ancak sayı 2, dizinin hiçbir yerinde görünmemelidir. Bu nedenle, örneğin, iki ( 2) veya yirmi üç ( 23) sayıları dizide olmamalıdır.

İşte sayıları ayıran yeni satırlarla birlikte örnek bir çıktı:

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

7
Kazanan kriterlerin kod-golf olduğunu sanıyorum?
Luis felipe De jesus Munoz

4
Sitemiz, Stack Exchange ağındaki diğer sitelerle aynı şekilde çalışmaz. Kabul edilen cevaplarla ilgili olarak, lütfen bu yorumu Jonathan Allan'dan dikkate alınız . Ve lütfen kazanan bir kriter ekleyin.
Arnauld

1
Gelecekte Sandbox'ı , göndermeden önce zorluklarınız hakkında geri bildirim almak için kullanmanızı önerebilir miyim ?
Jo King

1
@Monolica En kısa cevap kazanırsa, etikete ihtiyacınız olacak [code-golf]. Gelecekte referans olması için mevcut tüm kazanma kriterleri etiketlerinin bir listesi.
Kevin Cruijssen

4
@ user202729 Keyfi kısıtlama istenmeyen, izin verilmeyen.
Jonathan Frech

Yanıtlar:



26

Taksi , 2399 2391 2370 1783 1773 1706 bayt

-8 bayt, Sunny Side Park'ta belirli bir yolcuyu sonsuza dek bırakmak yerine, onları Riverview Köprüsü'nden atmaya değer. Ah, bu ne güzel bir kasaba.

Aptalca bıraktığım bir yorumda -21 bayt.

-587 bayt, basitçe bununla ilgili yürüdüğümün bütün yolunu değiştirerek (görünüşe göre daha kısa bir yol aritmetiktir; tam sayıyı [17, 27, 37, 47, ...] 9'a bölüştür, diziyi atlaman gerekir. 20'sin kendin.)

-17 Boşluk içermeyen herhangi bir alıntı-kaplı dize sonuçta alıntılara ihtiyaç duyulmadığının farkına varmak için (Jo King!).

-Bir satır çizgilerinin isteğe bağlı olduğunu anlamak için -67 bayt.

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]

Çevrimiçi deneyin!

Bu, herhangi bir zamanda herhangi bir kod golf yarışmasını kazanmıyor, ancak esolang Taksi'yi denemeye karar verdim.

Taksi, kurgusal Townsburg kentinde çeşitli duraklarda yolcuları alıp bırakarak tüm programlamanın yapıldığı bir esolang. Tabii ki, taksiciniz bazen tükenebilir, bu yüzden de sık sık benzin istasyonlarını ziyaret etmeniz ve aldığınız kredileri kullanarak ödeme yapmanız gerekir (bu durumda, sadece gaz için durmam gerekir - Go More'da - döngü yineleme başına bir kez!).

Böyle gibi yön rephrasing olarak bir dosya boyutu biraz azaltmak bazı hileler, kullanılan east 1st left, 2nd rightolarak e 1 l 2 r, kelimeyi kaldırarak thebu isteğe bağlıdır ve benim yerlerinden her doğru az komplike rotayı (ille kısa yolu) kullanarak.

Bu kısa çözümden, ilk başta bulduğumdan daha fazla nefret ediyorum. Buradaki çözüm, istediğiniz her yerde başlayıp bitebilecek olan göreve ulaşmanın daha genel bir yoludur. İşte, bütünüyle.

2245 bayt (daha genel)

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]

Çevrimiçi deneyin!

Ve eğer mega hile yapmaya izin verilirse, bu son ikisinden de daha kısa.

456 bayt (tamamen hile)

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.

Çevrimiçi deneyin!


Bu alıntı bir şey yararlıdır, teşekkürler. Ancak, "Taksi Garajına gitmek zorunda değilsin" şeyine katılmıyorum. Hatayla çıkmaya izin var mı? Bu konuda iyi bir genel kurallar dizisi bulamıyorum.
JosiahRyanW

Evet, genellikle STDERR göz ardı edilir. İlgili meta
Jo King,

Cevaplarımdan bazıları bundan yararlanabilir.
JosiahRyanW

22

Python 2,39 bayt

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

Çevrimiçi deneyin!

Aritmetik işlemleri yalnızca 2'li sayıların üretilmesi için kullanır.

Değer , 9'a bölündüğü zaman , 2'de bitmeyen sayıları sayan karitmetik ilerlemesini izler. 20'den 29'a kadar atlamak için, çıktılar belirli bir eşiği geçtikten 10'a kadar artar.17, 27, 37, 47, ...1,3,4,5,6,7,8,9,10,11,13,14,...


14

JavaScript (ES6), 43 bayt

Diziyi virgülle ayrılmış bir dize olarak döndürür.

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

Çevrimiçi deneyin!

Neden bu şekilde yapıyorsun?

1100 kadar tekrarlayabilir ve her sayının test edilmesini sağlayabiliriz /2/.test(n)ki bu çok özlü bir ifadedir. Fakat bu senaryoda, boş girişleri (/2/.test(n)?'':...), birkaç bayt daha ekleyen bir şeyle ele almamız gerekiyordu .

Örneğin, bu 45 bayt için işe yarar :

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

Veya , öncü virgül kabul edilebilirse, bu 44 bayt için işe yarar:

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

Sonuç olarak (ve aksi ispat edilmedikçe), 2 içeren n'nin tüm değerlerini hemen atlamak daha kısa olur .n2

Yorumlananlar

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

1
Bu çok havalı!
Emigna

1
Önde gelen virgül olabilirse , numaranızı kullanarak 41 bayt .
Oliver,

12

R , 19 bayt

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

Çevrimiçi deneyin!


grep(2,1:100,inv=T)19:
J.Doe

2
Ha - Bu ilk başta denediğim şeydi ama v=Faynı zamanda, çünkü açıkçası, kendime düşündüm, değerleri istiyorum , endeksleri değil ... ha!
NGM

Düzenli ifadenin kendisini ters çevirmek bir bayt kısalmasıdır (bu durumda).
NGM

Çalışmıyor, hala 2s geçmiş izin veriyor. ^[^2]*$Hangisine ihtiyacın olduğunu, um, daha kısa değil.
J.Doe

4
Şimdi cevaplarımızı kontrol etmemiz gerekiyor mu?
NGM


10

Perl 6 , 22 bayt

put grep {!/2/},1..100

Çevrimiçi deneyin!

Muhtemelen kod bloğunu yapmanın daha iyi bir yolu var, ancak eşleşmeyi tersine çevirecek bir regex zarf bulamadım.


sayıların etrafındaki parantezleri çıkarın. Aksi takdirde iyidir.
Monolica

@ Monolica Fix
Jo King

1
@ Monolica Pek çok garip görünüyor ki, cevabımı liste halinde yazdırmama izinsiz olarak seçtiniz, diğer pek çok cevabın böyle yaptığı. Öte yandan, bana herhangi bir bayta mal olmuyor,
Jo King

7

PowerShell , 22 16 bayt

1..100-notmatch2

Çevrimiçi deneyin!

Mazzy sayesinde -6 bayt

Aralığını üretir 1için 100bunlar, o obje dışarı çeker, daha sonra -notmatchsayısı 2. Buna -notmatchbenzer bir diziye karşı koşmak, dizideki bir filtre gibi davranır. Her madde boru hattında bırakılır ve çıktı gizlidir.


? 1..100-notmatch2
mazzy

@mazzy Elbette, bunu neden düşünmedim? Teşekkürler!
AdmBorkBork,

6

Haskell , 48 33 31 bayt

Kaydedilen on beş bayt için @JonathanFrech ve bir başka iki için @ xnor! Büyük bir golfu kaçırdım ve main=print$atlanabileceğinin farkında değildim .

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

Çevrimiçi deneyin!

Değiştirerek kolayca genişletilebilir 100. Tüm numaraları siler ve sadece a olmayanları tutar '2'.


Şuna bakın ; main=print$gerekli değildir. Kodunu test ettin mi? Bunun elem'2'geçerli bir sözdizimi olduğunu sanmıyorum . Neden map? Sadece filter(not.elem '2'.show)[1..100]işi yapar.
Jonathan Frech

@JonathanFrech Wow, bunu özledim. : / O alanın nereye gittiğine dair hiçbir ipucu yok! O
TIO'da var

2
Haskell bunun notElemiçin var not.elem, ama daha da kısa all(/='2').
xnor



5

Java 10, 67 bayt

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

Çevrimiçi deneyin.

Açıklama:

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

5

Retina , 19 17 bayt


100*
.
$.>`¶
A`2

Çevrimiçi deneyin! Düzenleme: Son satırda yeni satır olmasına rağmen @ovs sayesinde 2 bayt kaydedildi. Açıklama:


100*

100 karakter ekleyin.

.
$.>`¶

Her karakteri, o karaktere kadar olan ve bu karakterin dahil olduğu karakter sayısıyla ve yeni bir satırla değiştirin.

A`2

A içeren tüm girişleri kaldırın 2.


. $.>`¶İkinci aşama için çalışıyor mu ?
ovs

@ovs Daha önce daha karmaşık bir şey yaşadım ve yeni bir çizgiden L$kaçınmak için yer değiştirdim, bu yüzden geri dönebileceğimin farkında değildim, teşekkürler.
Neil


4

Wolfram Dili (Mathematica) , 42 bayt

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

Çevrimiçi deneyin!

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

[...] but who really cares, anyway. -- that's the spirit ...
Jonathan Frech

Do \[LeftCeiling] and \[RightCeiling] really count as a single byte :)
user6014

@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

@MishaLavrov Sounds fair ! Neat solution.
user6014


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


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


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!


Welcome to PPCG! You can get it down to a round 50 by deleting the space before the if.
ElPedro

[print(n)for n in range(1,101)if"2"not in str(n)] works.
JosiahRyanW

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

@JosiahRyanW I wasn't aware of the implicit print, thanks!
Gigaflop

1
'2'in str(n)or print(n) is shorter than a comprehension guard.
Jonathan Frech

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!



You could replace your test with a regexp: ![regexp 2 [incr i]] for -3 bytes
david

@david How was it possible I didn't come with the solution suggested by you of using regular expressions? Thanks.
sergiol


3

Bash, 31 bytes

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

Try it online!

Thanks to Digital Trauma for short loop.


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

yeah right. i ll update my answer.
ketone

i am learning actually i don't know that much btw thanks.
ketone

Just beats my echo {1..100}|tr ' ' \\n|grep -v 2
Mark Perryman

-1 byte if you use sed /2/d instead of grep -v 2.
Ruslan

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.


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?


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.


Nice use of PHP's wacky behavior to separate the numbers, lol
Roberto Maldonado

1
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


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

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.

Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.