tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
12
Task/Run-length-encoding/PHP/run-length-encoding.php
Normal file
12
Task/Run-length-encoding/PHP/run-length-encoding.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
function encode($str) {
|
||||
return preg_replace('/(.)\1*/e', 'strlen($0) . $1', $str);
|
||||
}
|
||||
|
||||
function decode($str) {
|
||||
return preg_replace('/(\d+)(\D)/e', 'str_repeat($2, $1)', $str);
|
||||
}
|
||||
|
||||
echo encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW'), "\n";
|
||||
echo decode('12W1B12W3B24W1B14W'), "\n";
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue