Skip to content · ⁨Passer au contenu⁩

Run-length encoding · ⁨Encodage par suites⁩

English

Run-length encoding

Compress a string by replacing each run of the same character with that character followed by how many times it repeats: aaabbc → a3b2c1. Always write the count, even when it is 1.

Walk the string tracking the current character and how long its run is. When the next character differs, write out the run (character + count) and start a fresh run. Don't forget to write the last run after the loop ends.

Français

Codage par longueur de run

Compressez une chaîne en remplaçant chaque série de caractères identiques par ce caractère suivi du nombre de répétitions : aaabbc → a3b2c1. Écrivez toujours le compteur, même quand il vaut 1.

Parcourez la chaîne en suivant le caractère courant et la longueur de sa série. Lorsque le prochain caractère diffère, écrivez la série (caractère + compteur) et commencez une nouvelle série. N'oubliez pas d'écrire la dernière série après la fin de la boucle.

Log in or create account · ⁨Se connecter ou créer un compte⁩

IGCSE, A-Level & AP