Exercices - série 2
Exercice 1 : recherche dichotomique
Recherche dichotomique
Bob a voulu écrire une version récursive de la recherche par dichotomie.
Malheureusement son code ne fonctionne pas. Corrigez-le.
.128073.128013_4:2-.Sw3/]+7bpPiqIoF1tl(9 ;=vTm6u8RsCfrge[hcé05a,nkydx)050%0R0y0Y0s0z0M0C0U0z0Y0M0M0E010y0s0q010406050M0J0H0H0Y0P0$040i0v0z0J0}0v0!0C020Y0H0q0D0C0L0R170P0t0J0R0M050l1416181a120q04051F1y1I0l1F120%0s0F0=0@0_0{0@0!0Q0J0Y0Q0R0g0q0$0y0T1h0C0T0s0Q0T0z1.0T0y10050-0p0z0R1R0^0`011-1/1;1/0y1`1|1^0y0P1G1)0=1d0M0q0Y0!0{0f011~1T010O0/0R0!1l0R1^2g2i2n202q1|2t0H2v040b0C0r0P0v0q0v0M0s1g1i0+2e0P0P0R0U2Q1y2x0!1G0l1)2$2a2c2b1_0%2z1U0s0!2s2N1^1O1Q0?1 2:2=0!0v2_1^0q2V1G2!2$36132h1i2{2o2 0P170z1^0Y1,2V0O0{030c0c0U300R1;2~0v0g0W0g0x100C0x1y0Y373a11392y3c203e3g3i3k0R3m013o3q3s3u2?3x0g2l040C0f3E3G2i3I2!2/013N0Y3h1G3j0T3l3n3p3r0+3X2 3Z0k3B0k3)2Z3H123-3L0{3:3=053@3_3T3{3W2;3Y3y0d3B0d441z463J3b1S3M0v3f3;3P3^3R3`3V3}4j3 3y0X3B0X4p36473a3.4b4z4f3U3|3t4F3w3y0I3B0I4L4r484u4a4w3O3?3Q3S4T4i3v3Z0o3B0o4$3+4N3K4)3/4+4y4-4A4/4h4E4=3y0K3B0K4`2#4|4t2|4 4x4c4e4B4g4D4V570g0B3B0B5c3,4O495h4,4d4.4C4U3~4X3z0W100x0W5u5e4P505j5B5m5D4W3Z0x3A045V5L4s5N5i4R5l4:564k3z3#0x3(0l3F454{5!5x4Q524S555o5+0x415X435:3*5d5@4~5_5A535C4;5~4m5X4o635=654(5g685k545n5E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100mcR5xb bgc+677LcYc(04brcxc$8|b(0!5U7$3ja$b;6_7,6|b-5~7$63bIbJ7^bL0,bOc63+cMcs01bV108T1vaFc7b%czaj5 cCaQ5~8qd5cD9*duaT9fdi3.a=4Va^bRc3cTc`ci04cXdN5^b`c=017tc*c27^b 020z8ddYc8b6047MdRb1c@dp3+7Wc|5U90d0bzd23z95dzdw7;0x90d9dadF5xddbNbPc/7y047j7l7n7ldUcadU0!dMch5x7tdQemc:c!eacn100net20cu5Xeh100e0m7Gd(c%d*d,eqbacjd:7VaXdsb)3z6samd cF9%d~a+e0eTe3b^d)dHbZeBd/b#dqc{eQc}6_ald_d6e0aqeYbE3zale$bIbK7idee9eGdjekec2Wee7oe+cbe.cS047Ae+0Sc^fedSesd-eL04eEex4ac;focV04cke-d;0l6(1J6M0l6O1y0y6QfH2,2%0Y1{6Z6N6W1E9c5x2V0H0c0O0Y0#0R0c0T601q1s1u1w9n791L3I1F0a0C0u0z0C170!1u0.8$1|0;056(bMdf1y6(0C0hg81J3IfF0,0.0:04.
Exercice 2 : parité
Parité
Compléter la fonction suivante qui doit être une fonction récursive.
⚠️ Il est interdit d'utiliser %
.128013l(9 _4:;=vTm26-uS8ws3C/fr7gebhEpPicé05qa,onkFyd1x)t050V0C0Z0O0I0b0u0e0J0b0O0u0u0j010Z0I0G010406050u0q0m0m0O0z0U040r0Q0b0q0@0Q0R050x0~1012140|0G04051k1d1n0x1k0|0V0I0k0,0.0:0=0.0R0B0q0O0B0C0p0G0U0Z0E1b0e0E0I0B0E0b1P0E0Z0`050%0D0b0C1w0/0;011O1Q1S1Q0Z1Y1!1W0Z0z1l1K0,170u0G0O0R0=0n011$1y010y0)0C0R0O0m0C1W1{1}221(251!282a0`0a0e0H0z0Q0G0Q0u0I1a0R0e0#1_0z0z0C0J2v1d2d0R1l0x1K2I1=1@1?1X0V2f1z0I0R272s1W1t1v0-1%2S2U0R0Q2Y1W0G2B1l2G2I2/0}1|2w2!232(0z110b1W0O1N2B0y0=030f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~3e6/eMfo5Pf$cOf2fvfbf50$f7eV3Pfc0`cT9YcWficYfkc!6~d!d(3F5Bd%b~8Q6 3KeRf.0439f`c 8GfRf{fUfjave?7cg1g6f#c)frdFgnf+f,fLf?f/0Zf;fAeW0R7.b(9SfP8k7}gI3=eYfKc.d|0pf=5cfN5TeC5c7|c}5H8K0x7z7g7u7i7r1d0Z7lg,2O2J0O1Zg)0x7j8J0#0%0)0u04.
Indice pour la parité
n
et n - 2
ont la même parité (tous les deux pairs, ou tous les deux impairs)
Exercice 3 : longueur d'une liste
Longueur de liste
Compléter la fonction suivante qui doit être une fonction récursive.
⚠️ Il est interdit d'utiliser len
.128013l(9 _4:;=vLm26-uS8w.s3/]+fr7gebh[pPic05qaonkyd1)t050U0E0X0P0K0b0v0e0L0b0P0v0v0j010X0K0I010406050v0q0m0m0P0B0T040r0Q0b0q0=0Q0R050x0|0~10120`0I04051i1b1l0x1i0`0U0K0k0*0,0.0:0,0R0D0q0P0D0E0p0I0T0X0G190e0G0K0D0G0b1N0G0X0^050#0F0b0E1u0-0/011M1O1Q1O0X1W1Y1U0X0B1j1I0*150v0I0P0R0:0n011!1w010A0%0E0R0P0m0E1U1_1{201$231Y26280^0a0e0J0B0Q0I0Q0v0K180R0e0Z1@0B0B0E0L2t1b2b0R1j0x1I2G1:1=1;1V0U2d1x0K0R252q1U1r1t0+1#2Q2S0R0Q2W1U0I2z1j2E2G2-0{1`2u2Y212$0B0 0b1U0P1L2z0A0:030f0f0L2%0E1Q2#0Q0p0n0p0V0^0V1b0P2.2;0_2:2c2?1$2^2`2|2~0E3001323436382T3b3b0^0n3h3j1{3l2E2P013q0P2{1j2}0G2 3133350Z3A2$3C0w0^0w3G2D3k0`3K3o0:3N3P053R3T3w3V3z2R3B3c0g0^0g3(1c3*3m2=1v3p0Q2_3O3s3S3u3U3y3X3`3Z3c0N0^0N402-3+2;3L3/4a3?3x3W374g3a3c0o0^0o4m423,453.473r3Q3t3v4u3_393C0C0^0C4D3I4o3n4G3M4I494K4b4M3^4f4P3c0s0^0s4U2F4W442Z4Z483:3=4c3@4e4w4+0p0d0^0d4:2G2*0E2G2W2J0U1=2O3-014v2V1s1j572,3k3)3I054v5m2c0K0U0:332E3C3e4K5u5w4~3Y4y3d1 2h0E5D4v5F5z1U0x3i433L0S0^0Z0A5o2F5S5f0t0^0e5Y5s4?2@0A0^0b191A0E0q0B5)5!4Y0@040c5^4F4@0R0^1-0E0P0q5~4p5f5{0h5)5(5 2@0F5.0K0v0X674X4@5{0W6c5_4@0Q0^0p020D0X0i6q6e3p6g042R6k415p6B0:6a5)0`6H5Z3K5C015x2;3C1~5B5v6S5E4x6V5I275K6Z5M6#3c6W3(6J015$040e6@5(6O5*3L0v0U0^020O0q0Q6y70727471736z6`6N2/6Q6Y6T1{3!3s6R4)4 3{0p3#0e5J5L4O7n3#2G5R6:6}5%6^0l2}0A192B0K1K2z0R0k0Q0K1Z0,0e5/1z0q5=0B2v1Z63656M6l2u7k0f5y3|7j7f6!503}7q6(7s4*7n3}7w6{5f7z6?6^75797 77767a4n7#0e7%7)0p4j6X7=7m4h8a6%288d5N4i5P3i6^6d684Y5U6E5X6`8p6m2@620P1X64668v6r216t040j0j6A8q6n0^0H0y6b7b86886U4z7+8j6,0p4A7:8i6*7t8f4A7_8o8o8F1$8s2z0X5?1a8E6:0m0K0^0M7!6`5S8U7h3c4R8c8(7?8f4R8$6)7l8k0p953G8.6:8s370v0E86690^8R85907e5D894-969d8Z4-9b8Y509x9h8-6@8/3.8z8B7Z9t8M8G0^0u9o4Y61042p0I9T8N5|6p8S9O5t7,89529y7-7n529C978e5G9,9G9H9J018;0!8@8L8x1$8{3fa05+1$8H0za54q5.5:7T5?9Z215{5}9(a69K047Y8D7d9P1$6o8 2/0x5r1m2+1b5a1b0X5caC2M2H8A1Y595j6N0Z0#0%0v04.
Indice pour la longueur d'une liste
Vous pouvez utiliser .pop()
Exercice 4 : bégaiement
bégaiement
Ecrire une fonction récursive repeat
qui prendra en argument un entier n
et une chaine de caractère txt
, et qui renvoie une chaine de caractères qui contient n fois la chaine de caractères txt
juxtaposées.
Exemple: repeat(5, "bla")
renvoie blablablablabla
.128013l(9î _4:;=vm26-uS8w.s3èC/+fr7gebhpPicNé05qa,onkyd1x)t050X0F0#0R0K0b0v0f0L0b0R0v0v0k010#0K0I010406050v0q0m0m0R0C0W040r0T0b0q0_0T0U050z101214160~0I04051m1f1p0z1m0~0X0K0l0.0:0=0@0:0U0E0q0R0E0F0p0I0W0#0H1d0f0H0K0E0H0b1R0H0#0|050)0G0b0F1y0;0?011Q1S1U1S0#1!1$1Y0#0C1n1M0.190v0I0R0U0@0n011(1A010B0+0F0U0R0m0F1Y1}1 241*271$2a2c0|0a0f0J0C0T0I0T0v0K1c0U0f0%1{0C0C0F0L2x1f2f0U1n0z1M2K1@1_1^1Z0X2h1B0K0U292u1Y1v1x0/1)2U2W0U0T2!1Y0I2D1n2I2K2;0 1~2y2$252*0C130b1Y0R1P2D0B0@030g0g0L2+0F1U2)0T0p0w0p0Y0|0Y1f0R2=2^0}2@2g2`1*2|2~30320F340136383a3c2X3f0p22040n3l3n1 3p2I2T013u0R2 1n310H333537390%3E2*3G0w0|0w3L2H3o0~3P3s0@3S3U053W3Y3A3!3D2V3F3g0h0|0h3-1g3/3q2_1z3t0T2}3T3w3X3y3Z3C3$3 3(3g0P0|0P452;3:2^3Q3@4f3{3B3#3b4l3e3g0o0|0o4r473;4a3?4c3v3V3x3z4z3~3d3G0D0|0D4I3N4t3r4L3R4N4e4P4g4R3}4k4U3g0s0|0s4Z2J4#492%4(4d3^3`4h3|4j4B4:0p0d0|0d4^2K2.0F2K2!2N0X1_2S3=014A2Z1w1n5c2:3o3.3N054A5r2g0K0X0@372I3G3i4P5z5B533%4D3h232l0F5I4A5K5E1Y0z3m483Q0V0|0%0B5t2J5X5k0t0|0f5%5x4{2{0B0|2D0I0F0R0#5.5)4%0{040c5|4K4|0U0|1e465u63255 0i5.5-6a3t0G0|2V5{685(6g0@5 0S6e5}640|0#0Z6l2?6o016c6s6A0U6i040v1@624u5k5 0!6D6L4%0T0|0p020E0#0j6P4$646G6I0C6Z5:1*6C6m3p6-5X5H015C2^3G3I3_0f6;4.54403H5N2b5P6=5J4C6^5U5W6A5+040f7d5-6/6A0v0X0|020Q0q0T6X7l7n7p7m7o6Y6-0~7g4u6|0g5D3g3*5G5A745R767D712c5Q4T6 7E3-7h7j7c7e0i1~0C2b0f0U0i2z1%0#0W5^0f290_0F0C0u0f0M0T0m0G2D7%0f0B0T0K0-7m1%0b02030w0d0j1O2D390I0K82310L0H0R0e2W7{0L140R2F0x2D0v0u5.7x6z7z7G6?1 3G427F7N4/6 427!728E6~4m0p8C7R6Q4|7i5,7V7X7Z6w0#7$2A7)7+6%7;0y8h3 8l8n8p8r0f810f8385871O0X7~0#0f0C0N0I0N0#7/8t7w6K5y8y7B6@4n3w7A7I554o8I7M7H7O8M4o2K798Q258S7U7d7q7u9u7s7r7v4s962y7A7C0p4F8D9j8F8M4F9h736}5S4E789s6f9p1*5Z040K5$6-9T6!2{666)3Q6S040k0k9)5k0m0K0|0O9/5~0|6d957y975I9E4W9H9O7J0p4W9M8K9Pa59R7eac9#6*0@9W2D0#0q0C672;ae3Q0v5F84860jas878u9B6{989E4=a275554=a79I8L5LaC3Lac6t259W3b0v0F9^4|6,9A9}9CaA9a569c989e6 57aHa355579n9SaN6Aah0(akam3oao5k65048XaU259+0Ab13t5?0F5^5`ay6M0|61aY4v9(9!aO1*9+0pb50@9;3jbb9_046rbi6E6v6xbraV0|6O9|2?0z5w1q2/1f5f1f0#5hbL2Q2L0R1#5dbJ5o7x0%0)0+0v04.
Exercice 5 : La tête à Toto
La tête à Toto
Compléter la fonction récursive toto
telle que :
toto(0)
renvoie '0'
toto(1)
renvoie '(0 + 0)'
toto(2)
renvoie '((0 + 0) + (0 + 0))'
- etc sur le même principe
On garantit que n
est un entier positif ou nul.
Compléter ci-dessous
.128013l(9 _4:;=vm26-uS8ws3/+fr7geUbhpPic05qa`on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9nd2dB01c 0wdJc`04c%a)dO5adMdT4!dD049n9XdIc|bXdVd%c!c$c(bJdzd(0@dNd*c.dY9n9$dFdb1a6H1l6p0v6r1a0W6te32L2G0M1W6C6q6z7i0Y0!0$0t04.
Exercice 6 : Test de palindrome
Palindrome
Un mot est un palindrome s'il se lit de la même façon de droite à gauche comme de gauche à droite.
Exercice
Écrire une fonction récursive est_palindrome
qui prend en paramètre une chaine de caractères mot
et renvoie le booléen True
si mot
est un palindrome ou False
sinon.
Premiers indices
- Le premier caractère de la chaine
mot
est mot[0]
- Le dernier caractère de la chaine
mot
est mot[-1]
- Pour une copie d'une tranche ("slice" en anglais) du second jusqu'à l'avant-dernier caractère d'une chaine
mot
, on peut écrire mot[1:-1]
Derniers indices
- Si la chaine fait zéro ou un caractère, c'est un palindrome.
- Sinon on peut comparer le premier et le dernier caractère.
- Enfin, un appel récursif permet de répondre sur le reste de la chaine.
Palindrome
Compléter ci-dessous
.9888.128013A_4:2!-.Sw3/]7bçpPiqoF1tl(9 ;=vTm6u8RsèCfrgàe[hcDé05a,nkydx)050+0U0z0$0u0A0N0D0X0A0$0N0N0F010z0u0s010406050N0K0I0I0$0R0*040k0w0A0K110w0(0D020$0I0s0E0D0M0U1b0R0v0K0U0N050n181a1c1e160s04051J1C1M0n1J160+0u0G0_0{0}0 0{0(0S0K0$0S0U0i0s0*0z0W1l0D0W0u0S0W0A1=0W0z14050;0q0A0U1V0|0~011;1?1^1?0z1~201|0z0R1K1-0_1h0N0s0$0(0 0g01221X010Q0?0U0(1p0U1|2k2m2r242u202x0I2z040b0D0t0R0w0s0w0N0u1k1m0/2i0R0R0U0X2U1C2B0(1K0n1-2*2e2g2f1}0+2D1Y0u0(2w2R1|1S1U0`232@2_0(0w2}1|0s2Z1K2(2*3a172l1m2 2s330R1b0A1|0$1:2Z0Q0 030d0d0X340U1^320w0i0#0i0y140D0y1C0$3b3e153d2C3g243i3k3m3o0U3q013s3u3w3y2`3B0i2p040D0g3I3K2m3M2(2?013R0$3l1K3n0W3p3r3t3v0/3#333%0m3F0m3-2%3L163;3P0 3@3_053{3}3X3 3!2^3$3C0e3F0e481D4a3N3f1W3Q0w3j3^3T3|3V3~3Z414n433C0#3F0#4t3a4b3e3=4f4D4j3Y403x4J3A3C0J3F0J4P4v4c4y4e4A3S3`3U3W4X4m3z3%0p3F0p4*3/4R3O4-3?4/4C4;4E4?4l4I4_3C0L3F0L4~2)504x30534B4g4i4F4k4H4Z5b0i0C3F0C5g3:4S4d5l4:4h4=4G4Y424#3D0!140y0!5y1N381C2}2-0+2g2=5B4Y2|1T1K370U393L493/054Y5)2C0u0+0 3t2(3%3E4;5;5?5r5I5_2q2H0U5}5H4!602*3J4w3=0)140/0Q5+2)6a5B0l3F6g5/5j3h0Q141A0z0d2l3y0+2O2I6m6i5213040B6A4,5k0(140I0w0z6G5A6C140-0f6m164u5,3;5|015@3e3%3)5E6Z595s4o3(612y644^6-6(0n696H2s6k3*0D6~6O515k0N0+14021y6M0E760K787a780Y0Z0z0U3j4n0D2S0D6L0z0D6s0D0K1m6v2^6x0w2I7d0z79777B7A0E6U701m6*0d5^3C455{5=6!5~667N6/2I6;5a6-7O3-6V3c6Y7Q6#2m3%4q7P7X6,4K0i4q0D627/5 4p1|6^6}6 6`246c040u6f6W2)0D6B6I0q142G7I3=6D6F866n4T6K6M8e5B6D0-6m88800 0w750A7B8r892s0I0u143,8i8A246D6T8i7$5*7(5}7M3B3T7K655t4M7@6:7R8U6-4M687~6~8)8H0 822Z0z0K0R0(8z8t010)0X140H0R1z7H8G8O7R8Q4%7.8Z6=7;4%8X7W967Y987|3J8)8s6P5k823x0N0U8n6Q048K4Q8e7K8Q4{956+7`0i4{9a639c7:5J9x3-9h9h8+8^14848?9j3h8l6N909R8I140V9p5k8C145O9V712s6D0o9Q9*248v040h0F9.6o3Q9T9!9+9Y9|9:140i9 0 9$043H9)9_0 9,9s4va80D9v6$5c8S7)7S5t5d9D7_7T0i5d8%9Kau9i9/8,148.8:8=8iawa98^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D6F5.b9ddg40B7o0V0y0f3Dgsg%gx0-7@219n0R3n0Z0G3^0Kc87q1mcUcI1mgJ7m5-gxg:0!0o0Df$dW0z0Vg@g_0/3*7rh1h30Z0D0Tg!gx8|8~gwhpg)hs1i0$2UgT1c1A9n0K9n0-0j1Ndrb|0=0@cA2~520$0+6L0(2Tcr1m0l1ch#1!cg1L3=hYh!h$1l0i110z2c04gE1xhA1Q1L040a0D0P0:c20N1h1jh%hv0D0q0|gX213v0s0uif0D010N1^0X1A2q0B2e2m0X0Wb?2w0D0Qg 0(0r0=0Ng{0(007r2l0^3V2u0X0$ip0%7@0whM0D0G7i2OgHgT1i0^0;0R2=7t210I7g1.2Wc6iUiM0uiOip0D0$iW0XgKb?7wi?1AhPb`6VbY5S0:hT0N04.
Exercice 7 : triangles
A faire
Écrire deux fonctions (procédures) récursives triangle_bas
, puis triangle_haut
prenant un entier n
non nul en paramètre et qui affichent un triangle. Ces fonctions ne renvoient rien.
Python Console Session>>> triangle_bas(4) # affiche un triangle tête en bas
####
###
##
#
Python Console Session>>> triangle_haut(4) # affiche un triangle tête en haut
#
##
###
####
Triangles
Compléter ci-dessous
Solution
Attention
L'ordre des instructions est bien sûr important !
Pythondef triangle_bas(n):
"""Affiche un triangle tête en bas"""
if n > 0:
print("#" * n)
triangle_bas(n - 1)
def triangle_haut(n):
"""Affiche un triangle tête en haut"""
if n > 0:
triangle_haut(n - 1)
print("#" * n)
Exercice 8 : Si vous avez du temps ... problème de la grenouille
🐸
Une grenouille doit monter un escalier. Quand elle saute pour monter, elle monte de 1 ou 2 marches.
Combien de chemins différents existent-ils pour un escalier de n marches ?
Vous êtes en complète autonomie pour cet exercice facultatif.
👉 Montrer au professeur votre solution, ou vos tentatives.
La fonction nbre_chemins
prend en paramètre un entier n
que l'on garantit strictement supérieur à zéro.
Compléter ci-dessous
.128013l(A _4:;=vm26-uSw.Rs3Cèz/+fr7gebhpPicé0Nq5a,onkyd1)t050X0F0!0R0K0b0u0e0L0b0R0u0u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6%5x7p4f7l3Y6~7a6t0{4Q6x31704K6D7F7A0?6I046K796s0?7c3W7f711{6W5 7U6b7n6)3u4D7m6@5p6_4D6=2z7*6/4C6{6}6 6p7K01730%76786E7`7S3X7e6y5E6-7$0o4U7)7t6k4B3u4U7.5v8c6^8e897?6o6q7`6u3o0u0F7Z4 7X846!4J87674f4/8b6d7+8l4/8h7:7v3u8E7y7^7G4 7|75777P6U6B5X5Z0F5#5%0U5)8z6O5-0{5:857Q5@047 7J8:7M0o8W8+7b6R043x8/8X5{0{0Z8{7V7L0{0A967H8=8!8$6Q8(8v6V8-9i8Y8=9b6H0{8`808:829l9304958y580z5b4@564_531t0!4|9H2%2Y0R1?9E0z4`1z5S3%2Q0l0f0B0R0V8#0H6+1l1n1p1r0e6X331G3C2;3%0R0X0l1c2K0K1$0X2d1V0C0{1z9=9@9_2L0o0^0!23040d212n2T9/9S0w0%0!1^0u181a9{1d0C0M0L762J0k1^2~2{0p2K0e0p1d250x0,0E0C2d2)2`0l8!0e0X000R0I0I8s0e1p0K5t001r0!0e2c0,0X0p0e0!0T1a0e3L2l0L0R0L0F0S0-13aP9+a?0bat0+7!ae0K9*0,am0Ua$ar3*0K0u0M0,arat0Cav1maea%192J0Fau0e0B0Tbd0s0e0qaY0ka.0,ak0uak0y0-ajalan2La%a.0CaC1daIaK5t0TaN2Qa}0e1n0L5$0ua`a^0/a%2Q0U0XaJ0e0G0F0R0p3m0p0IbXak1hb$0ea.bs0Fb.010I1Qaka02D1Z1#0U0s1E3C1A0ObB0e0M751Jc11c0,c40pbC132)b)0~251c0E04aybR1wbL0X0W2yb51q2Ucw1R04ccag9F0k3C9Q0%0)0+04.
Crédits
Franck Chambon
# Tests
(insensible à la casse)(Ctrl+I)
(Alt+: ; Ctrl pour inverser les colonnes)
(Esc)