RosettaCodeData/Task/Run-length-encoding/Sidef/run-length-encoding-1.sidef

8 lines
139 B
Text
Raw Permalink Normal View History

2016-12-05 23:44:36 +01:00
func encode(str) {
str.gsub(/((.)(\2*))/, {|a,b| "#{a.len}#{b}" });
}
func decode(str) {
str.gsub(/(\d+)(.)/, {|a,b| b * a.to_i });
}