skip to main content
Quorum
Learn
Hour of Code
Reference
Libraries
Download
Bugs
My Projects
Login
Quorum Login
Login
Cancel
Sign up for an account
"Text Compression" by Projects
This is a public project. Anyone can view it.
Text Compression
Code Area
1
use Libraries.Containers.Array text value = input("Enter text to compress, or leave this blank to use the default text instead. Do not use any numbers.") if value = "" value = "she sells sea shells on the sea shore the shells that she sells are sea shells i'm sure So if she sells sea shells on the sea shore i'm sure that the shells are sea shore shells" end value = value:ToLowerCase() number startSize = value:GetSize() number compressionRate = 0 Array
symbols text newLine = value:GetLineFeed() text compressionRules = "" text quote = newLine:GetDoubleQuote() boolean running = true repeat while running text toCompress = input(value + compressionRules + newLine + newLine + compressionRate + "%" + newLine + newLine + "Enter a portion of the text to compress, or leave this blank to finish.") if toCompress:IsEmpty() running = false else if compressionRules:IsEmpty() compressionRules = newLine end integer symbol = symbols:GetSize() symbols:Add(toCompress) repeat while value:Contains(toCompress) value = value:Replace(toCompress, "" + symbol) end integer symbolSize = 0 integer counter = 0 repeat while counter < symbols:GetSize() symbolSize = 1 + symbols:Get(counter):GetSize() counter = counter + 1 end compressionRate = 100 - 100 * ((value:GetSize() + symbolSize)/ startSize) compressionRules = compressionRules + newLine + symbol + ": " + quote + toCompress + quote if symbols:GetSize() >= 10 output "Reached maximum of 10 symbols in the dictionary, stopping." running = false end end end output "Final compression rate: " + compressionRate compressionRules = compressionRules:GetSubtext(1) output "Dictionary: " + compressionRules output "Final value: " output value
Build (CTRL+B)
Run (CTRL+R)
Stop Program
Save this Project
Project Name:
Save Project
Cancel
Load a Project
Load Project
Cancel
Save
Load
Embed
Output Area