Basic Compression
Description:
First, You will write a very basic compression algorithm
It gets a string:
string="aaaaaaaabaaaa"
And generates an array that sums all the repeating characters like so:
compressed=[[8,"a"],[1,"b"],[4,"a"]]
The compressed version is turned into a string:
compressed='[[8,"a"],[1,"b"],[4,"a"]]'
Finally,
If the compressed version is shorter than the original string, the function will return the compressed version.
Otherwise it will return the original string.
Example1:
string1="aaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaa"
output1='[[26,"a"],[1,"b"],[18,"a"]]'
Example2:
string2="abcde"
output2="abcde"
After you created the compression algorithm, create a decompression algorithm:
It gets a string (output1, output2, etc.).
If the string is comrpessed, it returns the uncompressed version,
If it is uncompressed, it returns the original string unchanged.
//output1='[[26,"a"],[1,"b"],[18,"a"]]'
uncompress(output1)
//returns
"aaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaa"
//output2="abcde"
uncompress(output2)
//returns
"abcde"
Note: The original string may not contain "[]" for obvious reasons.
Very Easy (Kyu 8)
Easy (Kyu 7-6)
Convert Color image to greyscale
Array Transformations
Basic Compression
Find Primes in Range
No Ifs No Buts
Medium (Kyu 5-4)
Identify Frames In An Image
Photoshop Like - Magic Wand
Scientific Notation
Vending Machine - FSA
Find Matching Parenthesis
Hard (Kyu 3-2)
Similar Kata:
Stats:
Created | May 11, 2017 |
Published | May 11, 2017 |
Warriors Trained | 1395 |
Total Skips | 18 |
Total Code Submissions | 4725 |
Total Times Completed | 458 |
JavaScript Completions | 396 |
Java Completions | 63 |
Total Stars | 34 |
% of votes with a positive feedback rating | 91% of 120 |
Total "Very Satisfied" Votes | 101 |
Total "Somewhat Satisfied" Votes | 16 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 6 kyu |