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
"Lossless Compression" by Projects
This is a public project. Anyone can view it.
Lossless Compression
Code Area
1
use Libraries.Containers.Array text value = input("Enter a number between 0 and 8 to use a preset text, or leave it blank to use the first default value. Alternatively, enter your own text (without numbers) to compress instead.") integer presetValue = -1 Array
presets presets:Add("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 ") presets:Add("So wake me up when it's all over When I'm wiser and I'm older All this time I was finding myself And I didn't know I was lost Didn't know I was lost I didn't know I was lost I didn't know I was lost I didn't know (didn't know, didn't know)") presets:Add("I Need a Dollar by Aloe Blacc I need a dollar, dollar A dollar that's what I need Well I need a dollar, dollar A dollar that's what I need Said I said I need dollar, dollar A dollar that's what I need And if I share with you my story would you share your dollar with me?") presets:Add("The Man by Aloe Blacc Well you can tell everybody Yeah you can tell everybody Go ahead and tell everybody I'm the man, I'm the man, I'm the man Well you can tell everybody Yeah you can tell everybody Go ahead and tell everybody I'm the man, I'm the man, I'm the man Yes I am, yes I am, yes I am I'm the man, I'm the man, I'm the man") presets:Add("Pitter patter pitter patter listen to the rain pitter patter pitter patter on the window pane") presets:Add("A tutor who tooted the flute Tried to tutor two tooters to toot Said the two to their tutor, 'Is it harder to toot Or to tutor two tooters to toot?'") presets:Add("I know an old lady who swallowed a bird How absurd! She swallowed a bird! She swallowed the bird to catch the spider That wriggled and jiggled and tickled inside her She swallowed the spider to catch the fly I don't know why she swallowed a fly Perhaps she'll die") presets:Add("Pease porridge hot Pease porridge cold Pease porridge in the pot Nine days old. Some like it hot Some like it cold Some like it in the pot Nine days old.") presets:Add("Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") check presetValue = value:ParseInteger() if presetValue < 0 or presetValue > 8 output "Error: To use a preset, enter a value between 0 and 8." return now end detect e is Error end if value = "" presetValue = 0 end if presetValue >= 0 and presetValue <= 8 value = presets:Get(presetValue) 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