Skip to content · ⁨Saltar al contenido⁩

Run-length encoding · ⁨Codificación por longitud de carrera⁩

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.

Español

Codificación por longitudes de secuencia

Comprime una cadena reemplazando cada secuencia de caracteres idénticos por ese carácter seguido de cuántas veces se repite: aaabbc → a3b2c1. Escribe siempre el conteo, incluso cuando sea 1.

Recorre la cadena manteniendo el carácter actual y la longitud de su secuencia. Cuando el siguiente carácter difiere, escribe la secuencia (carácter + conteo) e inicia una nueva secuencia. No olvides escribir la última secuencia después de que termine el bucle.

Log in or create account · ⁨Iniciar sesión o crear cuenta⁩

IGCSE, A-Level & AP