Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Run-length-encoding/E/run-length-encoding-1.e
Normal file
28
Task/Run-length-encoding/E/run-length-encoding-1.e
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
def rle(string) {
|
||||
var seen := null
|
||||
var count := 0
|
||||
var result := []
|
||||
def put() {
|
||||
if (seen != null) {
|
||||
result with= [count, seen]
|
||||
}
|
||||
}
|
||||
for ch in string {
|
||||
if (ch != seen) {
|
||||
put()
|
||||
seen := ch
|
||||
count := 0
|
||||
}
|
||||
count += 1
|
||||
}
|
||||
put()
|
||||
return result
|
||||
}
|
||||
|
||||
def unrle(coded) {
|
||||
var result := ""
|
||||
for [count, ch] in coded {
|
||||
result += E.toString(ch) * count
|
||||
}
|
||||
return result
|
||||
}
|
||||
5
Task/Run-length-encoding/E/run-length-encoding-2.e
Normal file
5
Task/Run-length-encoding/E/run-length-encoding-2.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
? rle("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW")
|
||||
# value: [[12, 'W'], [1, 'B'], [12, 'W'], [3, 'B'], [24, 'W'], [1, 'B'], [14, 'W']]
|
||||
|
||||
? unrle(rle("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"))
|
||||
# value: "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
|
||||
Loading…
Add table
Add a link
Reference in a new issue