Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Run-length-encoding/Jq/run-length-encoding-1.jq
Normal file
9
Task/Run-length-encoding/Jq/run-length-encoding-1.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def runs:
|
||||
reduce .[] as $item
|
||||
( [];
|
||||
if . == [] then [ [ $item, 1] ]
|
||||
else .[length-1] as $last
|
||||
| if $last[0] == $item then .[length-1] = [$item, $last[1] + 1]
|
||||
else . + [[$item, 1]]
|
||||
end
|
||||
end ) ;
|
||||
9
Task/Run-length-encoding/Jq/run-length-encoding-2.jq
Normal file
9
Task/Run-length-encoding/Jq/run-length-encoding-2.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def run_length_encode:
|
||||
explode | runs | reduce .[] as $x (""; . + "\($x[1])\([$x[0]]|implode)");
|
||||
|
||||
def run_length_decode:
|
||||
reduce (scan( "[0-9]+[A-Z]" )) as $pair
|
||||
( "";
|
||||
($pair[0:-1] | tonumber) as $n
|
||||
| $pair[-1:] as $letter
|
||||
| . + ($n * $letter)) ;
|
||||
1
Task/Run-length-encoding/Jq/run-length-encoding-3.jq
Normal file
1
Task/Run-length-encoding/Jq/run-length-encoding-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"ABBCCC" | run_length_encode | run_length_decode
|
||||
2
Task/Run-length-encoding/Jq/run-length-encoding-4.jq
Normal file
2
Task/Run-length-encoding/Jq/run-length-encoding-4.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$ jq -n -f Run_length_encoding.jq
|
||||
"ABBCCC"
|
||||
Loading…
Add table
Add a link
Reference in a new issue