-
11 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 A0Bonuses
- 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).
-
Refugee suicide attempts up on Manus after Australia election
6 votes -
Facebook plans to launch 'GlobalCoin' currency in 2020
7 votes -
Generating YouTube Titles Using Image Captioning
4 votes -
The folly of climate change philanthropy
5 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 -
Repair of iconic ’60s era synthesizer turns into long, strange trip for engineer
3 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 -
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 -
Please don’t theme our apps
9 votes -
Rust Koans
10 votes -
Why Precompiled Headers do (not) Improve C++ Compile Times
4 votes -
Starlink - Low latency satellite internet
20 votes -
Jussie Smollett’s case file is unsealed by judge
8 votes -
What have you been listening to this week?
@Whom asked me to cover this post for today. What have you been listening to this week? You don't need to do a 6000 word review if you don't want to, but please write something! If you've just...
@Whom asked me to cover this post for today.
What have you been listening to this week? You don't need to do a 6000 word review if you don't want to, but please write something! If you've just picked up some music, please update on that as well, we'd love to see your hauls :)
Feel free to give recs or discuss anything about each others' listening habits.
You can make a chart if you use last.fm:
http://www.tapmusic.net/lastfm/
Remember that linking directly to your image will update with your future listening, make sure to reupload to somewhere like imgur if you'd like it to remain what you have at the time of posting.
13 votes -
For true sneakerheads, every shoe tells a story
5 votes -
EU leaders: We won't follow Trump's Huawei ban
12 votes -
My name is TotalBiscuit - the life and times of John Bain
15 votes -
Superman II - WTF happened to this movie?
6 votes -
Defeating the voters: Across the United States, state autocrats are spurning democratic majorities
15 votes -
Few-Shot Adversarial Learning of Realistic Neural Talking Head Models
4 votes -
The official history of Chex Quest
8 votes -
How does technology improve your quality of life? In what ways does it detract from it?
I think it's safe to say that, in our modern world, everyone has an individual and complex relationship with technology. We're all experiencing the growing pains of uncharted territory, as...
I think it's safe to say that, in our modern world, everyone has an individual and complex relationship with technology. We're all experiencing the growing pains of uncharted territory, as computers, phones, and the internet continually revolutionize experiences from the everyday to the extraordinary. Unfortunately, it can often feel like every step forward also brings regressions, and what's good for some is not always good for others.
I'm interested in hearing about the ways that technology works for you in your life, both the good and the bad. Some guiding questions:
- What's better in your life because of technology? What is worse?
- How does it impact your career, hobbies, and interpersonal relationships?
- Are there tradeoffs you have to make for incorporating or ignoring tech for certain tasks or aspects?
- Are there areas in which you hope for the increased presence of technology?
- Are there areas where you actively keep tech out?
- Do you think that the problems created for us by technology are design flaws in the tech itself, or are they merely a mirror for pre-existing issues at the human level?
I know "technology" as a term is very broad, but I've intentionally left it that way because I want people to self-select the things most important to them, whether that's their computer, the internet, a phone, an online platform, an assistive tech device, etc. Also, don't feel obligated to list out every piece of tech, as it's gotten so prevalent to be almost omnipresent. Instead, just focus on the things that have a significant impact on your day to day life.
22 votes -
What impact has climate change or environmental degradation had on your life?
14 votes -
The politics of going to the bathroom
3 votes -
David Milch’s third act
4 votes -
Bryce Harper’s brother makes $2,000 a month playing independent ball in Lancaster. He loves it.
3 votes -
By censoring Arthur’s same-sex wedding, Alabama Public Television betrayed Mr. Rogers’ legacy
7 votes -
Shady numbers and bad business: Inside the esports bubble
7 votes -
WikiLeaks founder Julian Assange charged in eighteen-count superseding indictment
19 votes -
Snapchat employees abused data access to spy on users
11 votes -
All remaining Telltale games will be removed from sale on GOG on Monday, May 27
7 votes -
Terminator: Dark Fate | Official trailer
9 votes -
Go is Google's language, not ours
15 votes -
Facebook's third Community Standards Enforcement Report, covering Q4 2018 and Q1 2019
2 votes -
Tildistas, what is your favorite poem?
there have been quite a few discussions on poetry on here and more than a few people post it from time to time, but i don't think anybody's asked this question recently if at all on this site, so...
there have been quite a few discussions on poetry on here and more than a few people post it from time to time, but i don't think anybody's asked this question recently if at all on this site, so let me be the first to do that.
alternative/bonus question for those of you who can't pick a singular poem: who is your favorite poet in general?
(also just to be clear, non-anglophone poetry/poets are of course welcome for the answer here. don't feel limited or obligated to confine yourself just to english poetry because most of the people here are anglophones)
19 votes -
Tfue’s fight against Faze Clan is new for e-sports, not YouTube
5 votes -
Woke-washing: How brands are cashing in on the culture wars
14 votes -
Star Trek: Picard | Teaser
21 votes -
I tried to sexually harass Siri, but all she did was give me a polite brush-off
5 votes -
Killer flu season sees record numbers of cases and deaths - and it's only just beginning
7 votes -
Man cons Apple out of 1,493 iPhones
7 votes -
Announcing GitHub Sponsors: a new way to contribute to open source
19 votes -
In Kenya, LGBTQ activists mobilize in support of historic court decision to decriminalize gay sex
8 votes -
11,000-year-old Turkish town about to be submerged forever
11 votes -
World Agroforestry Congress gathers huge group of global boosters in France
2 votes -
Tor Browser for Android 8.5 offers mobile users privacy boost
3 votes -
Why we're pressing pause on political polling at the Herald and the Age
6 votes -
Who begs to go to prison? California jail inmates
4 votes