How to resolve the algorithm Run-length encoding step by step in the Gambas programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Run-length encoding step by step in the Gambas programming language
Table of Contents
Problem Statement
Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression. The output can be anything, as long as you can recreate the input with it.
Note: the encoding step in the above example is the same as a step of the Look-and-say sequence.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Run-length encoding step by step in the Gambas programming language
Source code in the gambas programming language
Public Sub Main()
Dim sString As String = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
Dim siCount As Short = 1
Dim siStart As Short = 1
Dim sHold As New String[]
Dim sTemp As String
sString &= " "
Repeat
sTemp = Mid(sString, siCount, 1)
Do
Inc siCount
If Mid(sString, siCount, 1) <> sTemp Then Break
If siCount = Len(sString) Then Break
Loop
sHold.add(Str(siCount - siStart) & sTemp)
siStart = siCount
Until siCount = Len(sString)
Print sString & gb.NewLine & sHold.Join(", ")
End
You may also check:How to resolve the algorithm 100 doors step by step in the Dyalect programming language
You may also check:How to resolve the algorithm Active object step by step in the Go programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Tokenize a string step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Introspection step by step in the J programming language