tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 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