22
5
You mission today is to invent a text compressor.
Task
You'll write two functions:
The packer is a function that accepts a string of ASCII characters (U+0000 to U+007F) and outputs a Unicode string (U+0000 to U+10FFFF), containing the fewest characters possible.
The unpacker is a function that accepts an encoded Unicode string and outputs exactly the original ASCII string.
Input
The only authorized input is the ASCII string (for the packer) and the packed Unicode string (for the unpacker). No user input, no internet connection, no use of file system.
Your functions can have access to this list of english words. You can use this list as a local txt file, or copy its content in your source code as a string or an array of strings.
You can't hardcode the snippets below in your functions.
Output
The only authorized output for both functions is a string.
The output of the unpacker must contain exactly the same characters as the input of the packer.
Your inputs and outputs can use any character encoding supporting all Unicode (UTF-8/16/32, GB18030, ...), as your score will only depend on the number of Unicode characters in the output. Please precise which encoding you're using, though.
To count the number of Unicode characters in your output, you can use this tool: http://mothereff.in/byte-counter
Scoring
Your entry must be able to pack and unpack the 10 following text snippets (that I took on this forum).
Your score will be the sum of the sizes of your 10 packed strings (in Unicode characters) + the size of your two functions (in Unicode characters, too)
Don't count the size of the dictionnary if you use it.
Please include in your entries the "score" of each snippet and their packed version.
Lowest score wins.
Data
Here are the snippets to encode to compute your score:
1: Rick Roll lyrics (1870b): We're no strangers to code golf, you know the rules, and so do I
We're no strangers to love You know the rules and so do I A full commitment's what I'm thinking of You wouldn't get this from any other guy I just wanna tell you how I'm feeling Gotta make you understand Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you We've known each other for so long Your heart's been aching but You're too shy to say it Inside we both know what's been going on We know the game and we're gonna play it And if you ask me how I'm feeling Don't tell me you're too blind to see Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you (Ooh, give you up) (Ooh, give you up) (Ooh) Never gonna give, never gonna give (Give you up) (Ooh) Never gonna give, never gonna give (Give you up) We've know each other for so long Your heart's been aching but You're too shy to say it Inside we both know what's been going on We know the game and we're gonna play it I just wanna tell you how I'm feeling Gotta make you understand Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you
2: The Golfer (412b): Golfing ASCII-art
'\ . . |>18>> \ . ' . | O>> . 'o | \ . | /\ . | / / .' | jgs^^^^^^^`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3: the number diamond (233b): Print this diamond
1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321 123456787654321 1234567654321 12345654321 123454321 1234321 12321 121 1
4: the alphabet four times (107b): Print the alphabet four times
abcdefghijklmnopqrstuvwxyz qwertyuiopasdfghjklzxcvbnm pyfgcrlaoeuidhtnsqjkxbmwvz zyxwvutsrqponmlkjihgfedcba
5: Old McDonald's lyrics (203b): Old MacDonald function
Old MacDonald had a farm, E-I-E-I-O, And on that farm he had a cow, E-I-E-I-O, With a moo moo here and a moo moo there, Here a moo, there a moo, everywhere a moo moo, Old MacDonald had a farm, E-I-E-I-O!
6: Rock around the clock lyrics (144b): Rock Around the Clock
1, 2, 3 o'clock, 4 o'clock rock, 5, 6, 7 o'clock, 8 o'clock rock, 9, 10, 11 o'clock, 12 o'clock rock, We're gonna rock around the clock tonight.
7: Hello World (296b): Say "Hello" to the world in ASCII art
_ _ _ _ _ _ _ | | | | ___| | | ___ __ _____ _ __| | __| | | | |_| |/ _ \ | |/ _ \ \ \ /\ / / _ \| '__| |/ _` | | | _ | __/ | | (_) | \ V V / (_) | | | | (_| |_| |_| |_|\___|_|_|\___( ) \_/\_/ \___/|_| |_|\__,_(_) |/
8: Irish blessing (210b): An Old Irish Blessing
May the road rise up to meet you May the wind be always at your back May the sun shine warm upon your face The rains fall soft upon your fields And until we meet again May God hold you in the hollow of His hand
9: There was an old lady lyrics (1208b): There Was an Old Lady
There was an old lady who swallowed a fly. I don't know why she swallowed that fly, Perhaps she'll die. There was an old lady who swallowed a spider, That wriggled and iggled and jiggled inside her. She swallowed the spider to catch the fly, I don't know why she swallowed that fly, Perhaps she'll die. There was an old lady who swallowed a bird, How absurd to swallow a bird. She swallowed the bird to catch the spider, She swallowed the spider to catch the fly, I don't know why she swallowed that fly, Perhaps she'll die. There was an old lady who swallowed a cat, Imagine that to swallow a cat. She swallowed the cat to catch the bird, She swallowed the bird to catch the spider, She swallowed the spider to catch the fly, I don't know why she swallowed that fly, Perhaps she'll die. There was an old lady who swallowed a dog, What a hog to swallow a dog. She swallowed the dog to catch the cat, She swallowed the cat to catch the bird, She swallowed the bird to catch the spider, She swallowed the spider to catch the fly, I don't know why she swallowed that fly, Perhaps she'll die. There was an old lady who swallowed a horse, She died of course.
10: gettysburg address (1452b): How random is the Gettysburg Address
Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us-that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion-that we here highly resolve that these dead shall not have died in vain-that this nation, under God, shall have a new birth of freedom-and that government of the people, by the people, for the people, shall not perish from the earth.
Total (uncompressed): 6135 chars/bytes.
Have fun!
Not immediately obvious how this is a programming language. The 'compiler' doesn't take source code. I guess rather it creates a program which is then interpreted – Claudiu – 2014-07-17T21:48:10.317
7This isn't a challenge to invent a language, this is a challenge to compress something. – Justin – 2014-07-17T21:56:57.147
2I think not including the size of the compiler/executor (compressor/decompressor) in the score makes this challenge a little open-ended. At some point, the line between dictionary and hard-coding will become very thin. – Dennis – 2014-07-17T23:12:13.750
2Darn, and here I was already typing
To make it a real language creation challenge, maybe specify that it has to be Turing-complete and the executor can't use "eval" or similar. – histocrat – 2014-07-18T02:36:24.317
Okay, I removed the mention of "language". now it's just a packer/unpacker. – xem – 2014-07-18T05:40:46.163
Hey guys, I've made the rules clearer (I hope) by providing an authorized dictionnary of english words. People can use it in their packer/unpacker, but they can't use any other external input. Hope this helps. – xem – 2014-07-18T17:37:34.830
1I don't think you've addressed Dennis' observation. – Peter Taylor – 2014-07-18T20:00:22.377
1@xem I think the post could be improved by organizing the information into sections such like #Task, #Input, #Output, #Scoring. I also think that the size of the source code for the compressor and the decompressor should be included in the score. This doesn't hurt anything, but it solves the problem Dennis pointed out. – Rainbolt – 2014-07-18T21:30:56.903
UTF8 to UTF32 correct? – Milo – 2014-07-19T00:52:56.183
@Milo I do not think so since the score is based on the number of unicode characters of the encoded output. UTF8 to UTF32 would have no effect on the score. – gxtaillon – 2014-07-19T01:40:33.893
@gxtaillon well it changes the characters we can use. Our input is 0-127 but our output is much larger because U+10FFFF is UTF-32 only I am pretty sure. Unless you use four UTF-8 unicode characters to make one UTF-32 – Milo – 2014-07-19T02:17:36.427
@xem what order should the snippets be output? better yet, instead of listing the links to the snippets, please provide the official expected output. – Moogie – 2014-07-19T04:16:21.320
Hi all, I've edited all the question, it's now a code-golf challenge. The size of your code counts in the score. I've clearly explained which input and output are expected and I've provided the dictionnary as an array of strings, if anyoune needs it. – xem – 2014-07-19T06:58:30.853
@moogie no particular order, you should pack them separately – xem – 2014-07-19T06:59:38.717
@Milo & gxtaillon, I've made this point clearer: use the encoding that you want. – xem – 2014-07-19T07:01:55.413