Origial Animation in CodePen.io

Braille Translation

Created: Dec 16, 2021

Last modified: Jun 25, 2025

TL, DR.

Braille Translation
===================

Because Commander Lambda is an equal-opportunity despot, she has several visually-impaired minions. But she never bothered to follow intergalactic standards for workplace accommodations, so those minions have a hard time navigating her space station. You figure printing out Braille signs will help them, and - since you'll be promoting efficiency at the same time - increase your chances of a promotion.

Braille is a writing system used to read by touch instead of by sight. Each character is composed of 6 dots in a 2x3 grid, where each dot can either be a bump or be flat (no bump). You plan to translate the signs around the space station to Braille so that the minions under Commander Lambda's command can feel the bumps on the signs and "read" the text with their touch. The special printer which can print the bumps onto the signs expects the dots in the following order:

1 4
2 5
3 6

So given the plain text word "code", you get the Braille dots:

11 10 11 10
00 01 01 01
00 10 00 00

where 1 represents a bump and 0 represents no bump. Put together, code becomes the output string 100100101010100110100010.

Write a function answer(plaintext) that takes a string parameter and returns a string of 1's and 0's representing the bumps and absence of bumps in the input string. Your function should be able to encode the 26 lowercase letters, handle capital letters by adding a Braille capitalization mark before that character, and use a blank character (000000) for spaces. All signs on the space station are less than fifty characters long and use only letters and spaces.

Test cases
==========

Inputs:
    (string) plaintext = "code"
Output:
    (string) "100100101010100110100010"

Inputs:
    (string) plaintext = "Braille"
Output:
    (string) "000001110000111010100000010100111000111000100010"

Inputs:
    (string) plaintext = "The quick brown fox jumped over the lazy dog"
Output:
    (string) "000001011110110010100010000000111110101001010100100100101000000000110000111010101010010111101110000000110100101010101101000000010110101001101100111100100010100110000000101010111001100010111010000000011110110010100010000000111000100000101011101111000000100110101010110110"

Commander Lambda never bothered to make her space station accessible, so some of her minions have a hard time finding their way around. Your plan: print every sign in Braille. The catch is that the printer doesn't understand letters, only a long string of 1s and 0s. Your job is to write the function that turns text into that string.

# Braille in 30 seconds

Braille is read by touch. Every character is a tiny grid of 6 dots: 2 columns and 3 rows. Each dot is either raised (1) or flat (0). The printer numbers the dots like this:

1 4
2 5
3 6

Here's the one detail that can trip you up: the numbers go down the columns, not across the rows. So to build the 6-digit code of a character, you read the left column from top to bottom, and then the right one. For example, the letter c has dots 1 and 4 raised, so its code is 100100.

The rest of the rules are short:

A lowercase letter is just its 6 dots.

A capital letter gets a special "capital" sign (000001) right before it.

A space is an empty cell: 000000.

# The trick: don't calculate, look it up

There's no formula hiding behind the Braille alphabet, each letter is simply a fixed pattern. So the easiest approach is a dictionary (a lookup table) from each letter to its 6 digits. Then you walk through the text, glue the codes together, and you're done. That's why this one is in Level 1!

# Try it yourself

Type anything you like in the box below. I left "code" in there to start, the same example the challenge uses.

This is exactly what the printer receives: one single string, just like the challenge asks for.

000001110010100010111000111000101010000000000001010111101010111010111000100110

Pretty hard to read, right? Here's the same thing split character by character. Switch between the dots and the grid of 1s and 0s to see how one turns into the other:

00 10 10 10 10 10 00 00 01 10 10 10 11 
00 11 01 10 10 01 00 00 11 01 11 10 01 
01 00 00 10 10 10 00 01 01 10 10 10 00 

Try typing a capital letter and watch the extra "capital" cell show up in front of it. As a little bonus (the challenge didn't ask for it), digits work too: Braille reuses the letters a to j for 1 to 0, with a "number" sign (001111) in front. A run of digits like 2024 only needs one number sign at the start.

# The code

Here's my solution in Python. A quick tour:

dct is the lookup table: every letter (and digit) with its 6 dots.

For each character: if it's uppercase, add the capital sign first. If it's a digit and the previous character wasn't one, add the number sign.

Finally, add the character itself. str.lower lets B use the same pattern as b, since the capital sign already did its job.

dct = {
    'a': "100000", 'b': "110000", 'c': "100100",
    'd': "100110", 'e': "100010", 'f': "110100",
    'g': "110110", 'h': "110010", 'i': "010100",
    'j': "010110", 'k': "101000", 'l': "111000",
    'm': "101100", 'n': "101110", 'o': "101010",
    'p': "111100", 'q': "111110", 'r': "111010",
    's': "011100", 't': "011110", 'u': "101001",
    'v': "111001", 'w': "010111", 'x': "101101",
    'y': "101111", 'z': "101011", ' ': "000000",
    '1': "100000", '2': "110000", '3': "100100",
    '4': "100110", '5': "100010", '6': "110100",
    '7': "110110", '8': "110010", '9': "010100",
    '0': "010110"
}
upper = "000001"
number = "001111"


def solution(s):
    output = ""
    for i, char in enumerate(s):
        if str.isupper(char):
            output += upper
        if str.isdigit(char):
            if i > 0 and str.isdigit(s[i - 1]):
                pass
            else:
                output += number
        output = output + dct[str.lower(char)]
    return output

# Wrapping up

Level 1 is a warm-up, and its lesson is simple but useful: some problems are just a lookup table plus a bit of formatting. The hardest part here isn't the code, it's reading the statement carefully, like noticing that the dots go down the columns. Don't overthink it!

An unhandled error has occurred. Reload ๐Ÿ—™