-
12 votes
-
Coming of age in cohousing: Growing up communally brings exposure to the world of adults—and lessons in interdependence
7 votes -
Programming Challenge: Text compression
In an effort to make these weekly, I present a new programming challenge. The challenge this week is to compress some text using a prefix code. Prefix codes associate each letter with a given bit...
In an effort to make these weekly, I present a new programming challenge.
The challenge this week is to compress some text using a prefix code. Prefix codes associate each letter with a given bit string, such that no encoded bitstring is the prefix of any other. These bit strings are then concatenated into one long integer which is separated into bytes for ease of reading. These bytes can be represented as hex values as well. The provided prefix encoding is as follows:
char value char value ' ' 11 'e' 101 't' 1001 'o' 10001 'n' 10000 'a' 011 's' 0101 'i' 01001 'r' 01000 'h' 0011 'd' 00101 'l' 001001 '~' 001000 'u' 00011 'c' 000101 'f' 000100 'm' 000011 'p' 0000101 'g' 0000100 'w' 0000011 'b' 0000010 'y' 0000001 'v' 00000001 'j' 000000001 'k' 0000000001 'x' 00000000001 'q' 000000000001 'z' 000000000000 Challenge
Your program should accept a lowercase string (including the ~ character), and should output the formatted compressed bit string in binary and hex. Your final byte should be 0 padded so that it has 8 bits as required. For your convenience, here is the above table in a text file for easy read-in.
Example
Here is an example:
$> tildes ~comp 10010100 10010010 01011010 10111001 00000010 11000100 00110000 10100000 94 92 5A B9 02 C4 30 A0
Bonuses
- Print the data compression ratio for a given compression, assuming the original input was encoded in 8 bit ASCII (one byte per character).
2. Output the ASCII string corresponding to the encoded byte string in addition to the above outputs. - @onyxleopard points out that many bytes won't actually be valid ASCII. Instead, do as they suggested and treat each byte as an ordinal value and print it as if encoded as UTF-8.
- An input prefixed by 'D' should be interpreted as an already compressed string using this encoding, and should be decompressed (by inverting the above procedure).
Previous Challenges (I am aware of prior existing ones, but it is hard to collect them as they were irregular. Thus I list last week's challenge as 'Week 1')
Week 113 votes - Print the data compression ratio for a given compression, assuming the original input was encoded in 8 bit ASCII (one byte per character).
-
GOG Galaxy open source?
12 votes -
Sofar Sounds house concerts raises $25M, but bands get just $100
7 votes -
Twitter Bans #Resistance-Famous Krassenstein Brothers for Allegedly Operating Fake Accounts
4 votes -
Separated by design: How some of America’s richest towns fight affordable housing
6 votes -
Hurley Haywood on life as a gay racing champion: 'I didn't have any male role models'
6 votes -
Carefully, Japan reconsiders the trash can
9 votes -
“Billionaires, bombers, and bellydancers”: How the first Arab American movie star foretold a century of Muslim misrepresentation
6 votes -
Why Ditching Processed Foods Won't Be Easy — The Barriers To Cooking From Scratch
8 votes -
Attarazat Addahabia & Faradjallah - Al Hadaoui
2 votes -
YouTubers and record labels are fighting, and record labels keep winning
8 votes -
The boring intimacy of the all-day group chat
8 votes -
What it felt like: If “living history” role-plays in the classroom can so easily go wrong, why do teachers keep assigning them?
6 votes -
One Year Off, Every Seven Years: How about this for a demand? You work for six years and you get a whole paid year off to do whatever the hell you want.
18 votes -
A new Star Wars movie based on Knights of the Old Republic is in the works
11 votes -
How do you meet people?
I've been feeling lonely for quite a while now.. Sometimes I strike a conversation with someone seemingly randomly because I wonder who they are, what they're doing here but I always feel like I'm...
I've been feeling lonely for quite a while now..
Sometimes I strike a conversation with someone seemingly randomly because I wonder who they are, what they're doing here but I always feel like I'm doing something wrong, like, I shouldn't be doing this, I feel kind of.. creepy, awkward. I've only been able to do this online because in real life, I just freeze and my mind just races with stress and I just give up and just decided overtime to not attempt that and avoid it.
So well, I'm just left wondering, how? How are you supposed to meet new people?
32 votes -
Kenya court upholds ban on gay sex in major setback for activists
7 votes -
Colorado becomes first state in nation to cap price of insulin
11 votes -
Superman II - WTF happened to this movie?
6 votes -
Star Trek: Picard | Teaser
21 votes -
WikiLeaks founder Julian Assange charged in eighteen-count superseding indictment
19 votes -
Twelve Foot Ninja - Portrait #1 (2008)
3 votes -
Please don’t theme our apps
9 votes -
How to write about Africa
6 votes -
Beyond Blue is shaping up to be much more than Blue Planet: The Game
4 votes -
In a town shaped by water, the river is winning
4 votes -
‘Marx at the Arcade: Consoles, Controllers, and Class Struggle’: A new, sociological investigation of how videogames and gaming fit into contemporary capitalism
6 votes -
The Sims 4 is currently free on Origin
23 votes -
Impossible Foods’ rising empire of almost-meat
7 votes -
Theresa May has said she will quit as Conservative leader on 7 June, paving the way for a contest to decide a new prime minister
25 votes -
WebAssembly at eBay: A Real-World Use Case
9 votes -
Our fury over abortion was dismissed for decades as hysterical
22 votes -
ISI$ - Joyner Lucas ft Logic (2019)
4 votes -
The technology of Storytelling: Dolby Labs' Poppy Crum shares a glimpse of the future
5 votes -
A solution to psychology’s reproducibility problem just failed its first test
10 votes -
Archiving grief five years after the Isla Vista attacks
3 votes -
Canadian federal government reveals passenger bill of rights
6 votes -
Go is Google's language, not ours
15 votes -
McHive, the world’s smallest McDonalds (for bees)
4 votes -
Generating YouTube Titles Using Image Captioning
4 votes -
Facebook plans to launch 'GlobalCoin' currency in 2020
7 votes -
Rust Koans
10 votes -
The folly of climate change philanthropy
5 votes -
Announcing GitHub Sponsors: a new way to contribute to open source
19 votes -
Repair of iconic ’60s era synthesizer turns into long, strange trip for engineer
3 votes -
What impact has climate change or environmental degradation had on your life?
14 votes -
On exercising your rights in privacy policies
@swipp_it: 1/ So, I guess my new "hobby" over the past few years has become reading terms of service/privacy policies for things I want to use and then trying to enforce my rights as laid out in those policies. Unsurprisingly, companies are often not certain how to respond to this.
11 votes -
5G networks could throw weather forecasting into chaos
19 votes