CJam, 27 26 bytes
80qf{i2b7Te[4/~\)\@+++2bc}
Try it online!
Explanation
The Braille code points are neatly ordered so that the individual dots do count up in binary. However, the ordering of the bits in the code points is different. We want the following order:
04
15
26
37
Whereas the characters are laid out in Unicode in this order:
03
14
25
67
(Which kinda makes sense, because historically, Braille only used the first six dots.) Note that we don't need the 7
dot, since the input is guaranteed to be in the ASCII range. So given a list of bits [6 5 4 3 2 1 0]
of an input character, we want to reorder them into [3 6 5 4 2 1 0]
, to pull the bit representing the bottom-left dot to the most significant position.
80 e# Push 80... we'll need this later.
q e# Read all input.
f{ e# Map this block onto each character, putting a copy of the 80
e# below each character.
i e# Convert the character to its code point.
2b e# Get its binary representation.
7Te[ e# Pad it to 7 bits with zeros. We've now got some bit list
e# [6 5 4 3 2 1 0].
4/ e# Split into chunks of 4: [[6 5 4 3] [2 1 0]]
~ e# Dump them onto the stack: [6 5 4 3] [2 1 0]
\ e# Swap them: [2 1 0] [6 5 4 3]
) e# Pull off the last element: [2 1 0] [6 5 4] 3
\ e# Swap: [2 1 0] 3 [6 5 4]
@ e# Rotate: 3 [6 5 4] [2 1 0]
++ e# Concatenate twice: [3 6 5 4 2 1 0]
e# That's the reordering done.
+ e# Prepend the 80. That puts it in the 2^7 position of the
e# binary digit list, which gives it a value of 10240, which
e# is where the Braille characters start.
2b e# Convert the bits back to an integer.
c e# Convert the code point to the corresponding integer.
}%
Surely
a
is⠱
, not⠹
(which I think isq
)? – Neil – 2017-04-21T09:19:51.577@Neil The challenge isn't just "convert char codes + 10240 to chars." And yes,
a
is⠱
. – Erik the Outgolfer – 2017-04-21T09:41:35.597@EriktheOutgolfer I didn't suggest it was, but
⠹
would have been wrong either way, since it has the wrong number of punched cells. – Neil – 2017-04-21T10:05:39.977@Neil Oh nice. I just recalculated and found out you're right. – Matthew Roh – 2017-04-21T12:56:58.703
Does it feel weird to anyone else that the LSB (bottom right) is left unused, rather than the MSB (top left)? – Julian Wolf – 2017-04-21T22:51:42.067
Not really. The ordering is column-major little-endian. The missing bit, which would go at the bottom right, is the MSB (bit 7, the 128s bit). – Buster – 2017-04-21T23:49:39.807
Of course for real Braille the difficulties in discerning different one-dot values should be obvious. As for "reasons not to." :) – Wildcard – 2017-04-22T01:30:38.840
@SIGSEGV : Where can I find all Unicode Braille signs ? – LMD – 2017-04-22T16:25:27.020
@Buster, you're right. I guess my brain wanted the numbers to be descending, despite the clear diagram showing otherwise in the question ¯\_(ツ)_/¯ – Julian Wolf – 2017-04-22T22:46:45.953
@user7185318 The characters used in the question are
<U+2822><U+283A><U+2831><U+2871><U+2874><U+2874><U+2835><U+2811>
. Found using$ echo ⠢⠺⠱⡱⡴⡴⠵⠑ | iconv -t ascii --unicode-subst="<U+%04X>"
. – luser droog – 2017-04-22T22:59:21.403