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.1280130ldCTy1,48]ké/weibmc:_35qaPr+ 7F=9o[fI;tRg26sSh)(pu.nxv050e0r0P0B0s0d0U0F0v0d0B0U0U0I010P0s0Z010406050U0!0u0u0B0D0h040V0K0d0!0|0K0$0F020B0u0Z0O0F0Q0r160D0A0!0r0U050p13151719110Z04051E1x1H0p1E110e0s0(0;0?0^0`0W0s0R0W0d1V0W0P0 050,0t0d0r1Q0@0_011U1W1Y1W0P1(1*1$0P0D1F0P0W0;1c0U0Z0B0$0`0S011,1S010M0.0r0$1k0r1$2224291.2c1*2f0u2h040b0F0C0D0K0Z0K0U0s1f1h0*200D0D0r0v2C1x2j0$1F0p1~2O1{1}1|1%0e2l0`1Y0$2e2z1$1N1P0=1-2Y0s2!0$0K2(1$0Z2H1F2M2O2_12231h2*2a2/0D160d0 0F0i2L2}102|2k2 1.3133350S38243a2M2X013f0B34040F0y3j2N113m3d0`3p3r0F0k3v3l2}3n3B350z3F3x3H3z3o0K323q350T3M3b2~1R3e3R3g3s0G3W3y3Z3A3#3T3s0l3)3O3+3Q3S3C0J3;3c3?3J040i0c3{3Y2+3@3$0i371y393N3|443~0i3i493k4b43303-3r0i3u4h3w3X3I4m0 0i3E4q3G4c4l3^4v3L4y4j4t4C3 3V4y1I2@1x2(2R0e1}2W3P0v2:2r0)1O1F2?0r2^393F054V0*4%4A1.0n0 0*0M3F0F4s3P0$0M0 2H0v0W0r0D4 0r4)3*440~040Y553=4d0 0/0P5b4.0`580j4@4_3}0 0%5h4k1.580X0w423n0q350F5B5r3n0U0e0 021t0K0P0O5I0!5K5M5J5L5x3P5F5A5B0f0+0P1+0M1g2J0s1g0F2H0$0(0K0s1+0g0D1u0F2A0F0%0F1v0P0F0e240:5f0j5|5~0H3q0U1+2A2/0$5T3?5V3s5B2u0D0o4V0$1N2C0F0w5`6q0F2-0P645f6t1Y0U5~0+0F1{0s0o1+2e0F3R0e2H0;2w0s0^245g4F5n446g6i2u2z0P6m6o5)1h6r0v5Z5#5%6p5,5.5:5 0!6E0h0Z1+0t0K1c6H6d6U562a6X6i5N5P765L780O3M066Y6V2a4:040s4?4y4^723e0t5e2e5D3P585a4L7n3A5e6B7s3?5u5m7x010K0 0I0I7E5c2a0u0s0 417w7M5t0 5w4F6Y7e7F7h2H0P0!0D702_7m7T0`0n0v0 670/547X6i7f3e0 0u7L5i7G7I7~5s3A7p042o7B570 7v2{7F0$7z6T8c7-017D7l7`0`7H040p0p823n7O0 4g2_7d7_7!0 7j8s4`8f882a580L8G7{047}7S7 580m8D3?8o7J8S5d045q8O838j7V3M7Y8z8i7#0+7(7*397,7 7/0 5=1u8(8*8=0 0r1Y7k7+8m3o8F8!3n8I8K7y8M988$048R8l7F8o020d5S9f8i8e8Y9b587W8x8)5C8A047$8.8W304}2I5052509p8a9b9n5f9G048J958E9a9l7 8o0E9z1.8u3 9L0w0m5l9R8#9n8Z8h8P0 0X8`9u8+8}7?9Z9/7Y928,7%7)9V994~9D539L8b4(8d949+8#8I9ra59m7|9L9#9~939o9O7C9-3W0p4+4$4Maq0p4P1x0P4Rav2U2P0B1)as4P1D4-8#2H0u0x0M0B0n0r0x0W0y0 1p1r1t1v6q4)1K3a1E0a0F0N0d0F160$1t0-5~1*0:4*4W9w8-9}aoa?0F0#a}1I3aat0+0-0/04.
Exercice 2 : parité
Parité
Compléter la fonction suivante qui doit être une fonction récursive.
⚠️ Il est interdit d'utiliser %
.1280130ldCTy1,4-ké/weibmc_:35qaPr 7F=9ofgt28;6sSh)(Epunxv050d0p0K0z0q0c0P0C0t0c0z0P0P0F010K0q0V010406050P0W0s0s0z0B0g040Q0H0c0W0@0H0X050n0~1012140|0V04051k1d1n0n1k0|0d0q0Z0,0.0:0=0R0q0J0R0c1B0R0K0`050%0r0c0p1w0/0;011A1C1E1C0K1K1M1I0K0B1l0K0R0,170P0V0z0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5f0T0b7@3@7s01810C7$7~7F8d8f5}618m5 5~624V6`8d50041P6%5D4f557_355q5T5$015M047O0F8F5:010s0q0`4O2Z8B5U015k0i5/640h5@030w0G0N6u5b6Y6!6$6(2e2g0@6-6/6;0c028%8)3t8t8C8v6,8M3p8E8A8d8I0F8L968C8P8R8Z3w5(4m6`8 8V8v7a787q2?8U8G0l0t0`8h8~6M8u591E539b8V0X958T970`99933w9d3)9f3W9h8s9j5.900`9n7d9L3W9t0`6C0*8i9S9U9l9A6E9P5j0`7E9*9j9z049X9p319r8N9F046v875g5s8C5k5ma49E9G9q9I040k9Z3.9N4!2?8d5H3D0n4{0p2v2Wap4(1u4*2y2B2w0z1Las0n4)0|aC0$0(0*04.
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
.1280130ldy14-L]ké/weibmc:_35qaPr+ 7=9o[f.gt28;6sSh)(punv050d0o0L0y0p0c0Q0C0s0c0y0Q0Q0E010L0p0V010406050Q0W0r0r0y0A0e040R0G0c0W0?0G0X050m0}0 11130{0V04051j1c1m0m1j0{0d0p0Y0+0-0/0;0S0p0K0S0c1A0S0L0_050$0q0c0o1v0.0:011z1B1D1B0L1J1L1H0L0A1k0L0S0+160Q0V0y0X0;0M011N1x010I0(0o0X0y0r0o1H1*1,1;1P1@1L1`1|0_0a0C0z0A0G0V0G0Q0p190X0C0!1(0A0A0o0s2h1c1 0X1k0m1$2u1Z1#1!1I0d210;1D0X1_2e1H1s1u0,1O2E0p2G0X0G2K1H0V2n1k2s2u2Y0|1+2i2M1=2R0A100c0_0C0f2r2$0`2#202(1P2*2,2.0M2;1,2?2s2D012{0y2-040C0v2 2t0{322_0;35370C0g3b312$333h2.0w3l3d3n3f340G2+362.0P3s2@2%1w2`3x2|380D3C3e3F3g3H3z380N3L3u3N3w3y3i0F3T2^3V3p040f0b3l1n2W1c2K2x0d1#2C3v0s2S1}1k3/1l3-2!1d2=053^0!2X3U2N010k0_0!0I3l0C3D3o0I0_0c1a0K0W0o0W0A3+3M470^040U4q462)0_1W0o0y0W4w3#4s0_0t4d4f3v0X0q4i0p0Q0L4E3E4G040T4J4r1=0G0_0h020K0L0O4X4x2`4N042P4R40304K3V4t4I4=3c4@470n2.0C514S330Q0d0_020x0W0G4)585a5c595b4*4{3m4F1=5550510i0y0C0I1a2p0p1a0C2n0X0Y0G0p1M0-0C4j0X4l4n0A2j1M4A4C3!4T5m5638510C5d5h5X5f5e5i2Y065V4e4Y2`0_3^0V5D0u5O4D5j5*4,0;4!040E4+5l4-4O4Q533v4t4v5j4}4y045=634^0_4W5@681P0s0f0_03290G4o0C2G0C1+0*0d0l1Z0W0p2n0C6b5j5(5V6h0;494/4c6g5+3g5-2c5:6C2Y5^5 5`0_0E5}6L5_014t0H0j4`5%5)5)6G480_2n0L4o1b6Z6U010r0p0_3*6D6,6M6.040o0)0o6c4U6)2=6E6+6T5R5,045.6Q0y1K4B5?2!705{0J76692d0V7q1P656f6*7b7c336I6:6=5~7d0;6`0_2:6@7G015{0B7F3o4i4k4m4o7u0;657W346O5/0o5;7i1L5P67704t7x791c430o2u2V7?3.1t3:2x2A2v7)7_0m3/0{820#0%0)04.
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
.1280130ldCy1,4-ké/weibmc:35qaPr+ 7=9of.gt28;6sSh)(pNuîènxv050d0o0J0x0p0c0O0B0s0c0x0O0O0D010J0p0T010406050O0V0r0r0x0z0f040P0F0c0V0^0F0Y050m0 1113150}0T04051l1e1o0m1l0}0d0p0!0-0/0;0?0Q0p0I0Q0c1C0Q0J0{050(0q0c0o1x0:0=011B1D1F1D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0o2w2X8b3$1v3(2z2C2x0x1M8e0m3%0}8o0%0)0+04.
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
.1280130ldy14-êk`/wUeibmc:35qaPr+ 7=9ofgt28;6sSh)(punv050d0o0I0x0p0c0N0B0s0c0x0N0N0D010I0p0S010406050N0T0r0r0x0z0e040O0F0c0T0:0F0U050l0`0|0~100^0S04051g191j0l1g0^0d0p0V0(0*0,0.0P0p0H0P0c1x0P0I0?050Z0q0c0o1s0+0-011w1y1A1y0I1G1I1E0I0z1h0I0P0(130N0S0x0U0.0J011K1u010G0#0o0U0x0r0o1E1%1)1.1M1;1I1@1_0?0a0B0y0z0F0S0F0N0p160U0B0X1#0z0z0o0s2e191|0U1h0l1Z2r1W1Y1X1F0d1~0.1A0U1?2b1E1p1r0)1L2B0p2D0U0F2H1E0S2k1h2p2r2V0_1(2f2J1/2O0z0}0c0?0B0f2o2Z0@2Y1}2#1M2%2)2+0J2.1)2:2p2A012^0x2*040B0u2|2q0^2 2?0.32340B0g382~2Z303e2+0v3i3a3k3c310F2(332+0M3p2;2!1t2@3u2_350C3z3b3C3d3E3w350K3I3r3K3t3v3f0E3Q2=3S3m040f0b3X3B2K3T3F0f2-1a2/3q3Y3*3!0f2{3/2}3;3)2$3M340f373`393A3l3 0?0f3h433j3=3~3U483o4b3|464f3#3y4b1k2T192H2u0d1Y2z3s0s2P1`1h4s1i4q2X4o4y0X2U3R3*0j0?0X0G3i0B453s0U0G0?0I0F4X3i4S3S0=040R4!3J3?0?184o4+1/4%0Q0t3(300m2+0B4|4*4K1/0N0d0?020w0T4Y0L54560I5855570n2D0B0G172m0p170B0I0o0c1I0B551J4@4i4j3s514{4|0h0B0k4X4X0R0b0Q0k0B2k0U0V0F0p1J0k02030u0E0L0b5T5V0L0k4^5y52354|0B5C5E4Y0F0R0f5J5L1?5O5Q5D5Z5W5H0B0A0B5I5|5#5%3S5z5*5B5D5F5:0J5?5M5_5R630R5~605I5 0B6k610Q0Q635$4i4#3*675+5,0B0Y0s0B0`0z0B5r0r0i1_0B2S2M0s0;0o3p5x665)6z2f0o0N0I0B0T6X0U0:0o6G2a2c0:4P6v4:1M6y5+59576^5b6`0L6S6z6w1/4M040p6/2V4R6;3d4-4Q701M0F0?0D0D7b78010r0p0?3%4/4 1M4%5v2V066z6 7j722k0I0T0z4.767c0.0N0f535U5W5Y7L6}4i7x7q0.725p0N6R7p4d7r0?7t3:7w5+7G310?0r4Y747i7S017e047h4b777;0U4W5/4~7Z0.4%4)7Y3}2@7a7_7*7?0h7:807k7m3#7 85810?0Q3p7(4}7y0?7A7C7E2/7`8d7I7K5!0R638c8i7=0?0A8C3l7,7.758u898F8H5y7J04636n8B887j7?8G8W7{8J6.8P3S8Y8(6x8R636s7O3z0l4H0o2r2S8@4r1q4t2u2x2s0x1H8`0l4s0^940Y0!0$04.
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
.128013.9888Cy1-]/wi_qPr 7F9f;gR2çàh)(pnD0ldT,4Akée!bmc:35a=o[.8t6sSèuxv050H0O0$0W0j0G0(0o0S0G0W0(0(0X010$0j0C010406050(0+0R0R0W0n0d040)0Y0G0+110Y0D0o020W0R0C0t0o0v0O1b0n0l0+0O0(050h181a1c1e160C04051J1C1M0h1J160H0j0-0_0{0}0 0z0j0u0z0G1!0z0$14050;0Q0G0O1V0|0~011Z1#1%1#0$1-1/1+0$0n1K0$0z0_1h0(0C0W0D0 0w011;1X010s0?0O0D1p0O1+27292e1?2h1/2k0R2m040a0o0m0n0Y0C0Y0(0j1k1m0/250n0n0O0S2H1C2o0D1K0h232T2022211,0H2q0 1%0D2j2E1+1S1U0`1=2%0j2)0D0Y2-1+0C2M1K2R2T2~17281m2/2f2@0n1b0G140o0e2Q3215312p341?36383a0w3d293f2R2$013k0W39040o0U3o2S163r3i0 3u3w0o0K3A3q323s3G3a0V3K3C3M3E3t0Y373v3a0%3R3g331W3j3W3l3x0p3#3D3(3F3*3Y3x0#3.3T3:3V3X3H0r3_3h3{3O040e0F3K1N2|1C2-2W0H222#3U0S2^2w0.1T1K2{0O2}3e474h0/4p412:010M140/0s3K0o3$3N0s141A0$0k282(0H2B2v473/4w13040B4Q3`4w0D140R0Y0$4W4v2f4T0A0T403%4w0i3a0o4?4(4/2f0(0H14021y4$0t4~0+5052500E0N0$0O372=1:2F0o4#0$0o4I0o0+1m4L2=4N0Y2v550$514 5t5s0t3R064?4@4R2f4y040j4B1D3e4D5D3j0Q142t4^3s4T4V5J3p4E3U4Z045g5R3U4+4C5X3{0Y4}0G5t5)5M0 0R0j143n5V2S5*4S144-5`155B625L4X5E142M0$0+0n0D5:651?0M0S140I0n1z3R625|66040O0@0O5$3{4T5 2~5A635C6e0 5F5H6d4)3j4!4$6u5}040Z6L2f5?1446606o1?4T0g6G4_1?5,040P0X6Z3N6J4%6U5;014T6O6.6C016$0f6P1?6R446{0 6X6x3e6z6A6n6/5F686a6c60646H6D6h040q3v0(6t6074636V6D4H6s6 6:5~6m75766@780:7a6*5Y4H0(4J5n0D5p4P6?7e7u4U7t5Z5#7M6!70146=306/6}3c7T5S7v7$3U6_7t7!7t6X0A3#0h4s4o487@0h4b1C0$4d7|2Z2U0W1.7_4b1I4u7U012M0R0k0s0W0M0O0k0z0U141u1w1y1A0o725W1P3f0/0;0?0^5Y4$1:0H0N0C1%0N2m0o2C2j0 8I5Z3C191w1e0L1j2M2K2M2O0j1l0o2D0}0j832Q8O1G8t1T3s1^1$1(1*873s2s2j2l142y0)0S0n125h0m0d231l474n872 4q7?8=3U5F4A7D424G6q7G4K3v5o4O7l7Y6@5T7Q6,7.144,4.3s0(2c045x57595b2)0o5e5g5i7G5k5m9l7J9n5x5z7y7N6E5I2~7d880D5O045Q7)6v145U9p7N7R6K9(6M7:7c7p6^5-5/9?7Z5@045_9,886w7w6A9@7A696b9f4w6g6i6k9o739T885F6r7k9u048q3B7xa5677Ba89{6@9.6-a07%6N7,9}6Tay5%146Yau7N6$0X6)aI9Z9t9:4*7W7t7+aQ6|9}7#aE9)04aH9X9@0Y4;04290Ha9357F7H9O7Kae5W6/9raV3FaPaZ6M7X4q9|14aYb19q7(a~2faUb8aWb3al0g9=6y1C9a7^2T851L048l1c4 0D0^8n0o0{0o0/0+0,0j0*2v8Z1c118A0+4D9aa,bi4i3x4V9a4I9k4M9n0B5g0Z0e0T0f0ebfbM4t0A0o9G7k0n0W0o0N0-3v0+8F5i1m91931mbu5e059abW0F0g0oaL5f4$0Zb!aH9a9K5hb:b=0N0o0ybJbN6j6l7=bN0o0Bce1i0W2HbE2M0}0O0+7k0A0!1N3f7`0:0=0@8+2.3{0W0H4#0D2G8X1m0i1ccP0D0u141I3scMcOcQ1l0f110$1~bo1vbqcm1Qbn0b0o0c0:599H1h1jcRch0o0Q0|8A1:4h0C0jd30o010(1%0S1A2d0B20290S0z8o2j0o0sb-0D0x0=0(b)0D005j280^0O0s2h0S0Wdd0Jb*0Ycz0o0-5a2Bbs8Z1i0^0;0n2#5l1:0R580z4idPdJdAdCdE1:0WdL0Sbv8o5o0jdd0(cC8s167`4ld_8ucH0(04.
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.
🐍 Console Python>>> triangle_bas(4) # affiche un triangle tête en bas
####
###
##
#
🐍 Console Python>>> 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 !
🐍 Script 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
.128013ldCy1,4-Aké/eibmc_:35qaPr+ 7=of.;tRg26sSh)(zpèuNnv050c0n0I0x0o0b0N0B0r0b0x0N0N0D010I0o0T010406050N0V0q0q0x0z0e040O0E0b0V0?0E0X0B020x0q0T0H0B0J0n100z0w0V0n0N050m0}0 11130{0T04051y1r1B0m1y0{0c0o0Y0+0-0/0;0P0o0K0P0b1P0P0I0_050$0p0b0n1K0.0:011O1Q1S1Q0I1Y1!1W0I0z1z0I0P0+160N0T0x0X0;0L011$1M010F0(0n0X1e0n1W1|1~231(261!290q2b040a0B0y0z0E0T0E0N0o191b0!1`0z0z0n0r2w1r2d0X1z0m1^2I1=1@1?1X0c2f0;1S0X282t1W1H1J0,1%2S0o2U0X0E2Y1W0T2B1z2G2I2:0|1}1b2!242)0z100b0_0f2F2@0`2?2e2_1(2{2}0_0L311~332G2R01380x2~040u3c2H0{3f360;3i3k0h3n3e2@3g3t0_0v3w3p3y3r3h0E2|3j0_0M3D342^1L373I39040C3w1C2.1r2Y2L0c1@2Q3G0r2*2l0Z1I1z2-0n2/323W3*0!3=353Q0;0k0_0!0F3w0B3O3z0F0_0X0p2B0s0r0P1k2%1q1s3?3q3|010^040R3W4j2#3h474p3F4k4m0Q0t3D0B4B434q243~040o414h3d4D4v4r0X4t4K2H4M3{4r0E0_0D0D42443G0q0o2 4u4U244m4z4R0`4C4;4T3P4r4G2B0I0V0z0X4!4E1(4%4)4/064;4#4k4G0n1S4J2:4?3z4Q5d574V4X4Z4/5e4$4(043b4/5i4,0_4.2:554=4B5t1(4_0#4|4~5m5B0;525q4A4C5I01590)0n4*4@5u045w325y5z5O5D4{4}4 4N2`47490n4b4d4%0X4g2=500;4m4o5s5^4s045G5h5}4W040i5)4+515p305|5*1(4x665U1(630A6f5f5 5-5/4e5=5T3g5`6r3G4P5 6k3G63655H5}5K5r5@6c5_0_0Q3N0m3^3;3X6O0m3!1r0I3$6T2O2J0x1Z6Q3!1x3`6g0;2B0q0s0F0x0k5.0P0u0_1j1l1n1p0B5X3d1C332Y3g0x0c0q1a2v0o1a0B0c1~0K0n0z0_1x7274762w0i0?0I1:040j1.282E1E331y0d0#0I1#0N1618781b0z0l0r4|2u0Y1#2-2*0V2v0B0V1b1=0U0*0K0z1~2Q2)0q5-7a000x0T0T5a0*1n0o0B0X001p0I0B1}0*0c0V0B0I0E180B0n0F260r0x0r0n0g0+117a6{870b7J0)0B0o0!0X0?6`0*7C8n0B7H3j0o0N0l0*7H7J0z7L1k7t7`172u0n7K0B0F0E8w0G0B0O7;0Y810*7A0N7A0S0+7z7B7D2w7`810z7S1b7Y7!7=0E7%2B8e0B1l4c1p8b890-7`2B0X0c7Z0B0p0n0x0V3*0V0T8@7A1f0N8b818L7e0x0B4l0-8n7e220y0e1^1a0G6 6%0W8U0B0l4{1H7e1a0*0T8H7 112Q8~0|1=1a0K047O8.1u8(0c0e2j0o6`2F9O0X9Q9v7v0{6R3.9+0!0$0(0N04.
Crédits
Franck Chambon
# Tests
(insensible à la casse)(Ctrl+I)
(Ctrl+Clic pour inverser les colonnes)