Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Run-length-encoding/AutoHotkey/run-length-encoding.ahk
Normal file
35
Task/Run-length-encoding/AutoHotkey/run-length-encoding.ahk
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
MsgBox % key := rle_encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW")
|
||||
MsgBox % rle_decode(key)
|
||||
|
||||
rle_encode(message)
|
||||
{
|
||||
StringLeft, previous, message, 1
|
||||
StringRight, last, message, 1
|
||||
message .= Asc(Chr(last)+1)
|
||||
count = 0
|
||||
Loop, Parse, message
|
||||
{
|
||||
If (previous == A_LoopField)
|
||||
count +=1
|
||||
Else
|
||||
{
|
||||
output .= previous . count
|
||||
previous := A_LoopField
|
||||
count = 1
|
||||
}
|
||||
}
|
||||
Return output
|
||||
}
|
||||
|
||||
rle_decode(message)
|
||||
{
|
||||
pos = 1
|
||||
While, item := RegExMatch(message, "\D", char, pos)
|
||||
{
|
||||
digpos := RegExMatch(message, "\d+", dig, item)
|
||||
Loop, % dig
|
||||
output .= char
|
||||
pos := digpos
|
||||
}
|
||||
Return output
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue