盲文化字符串


22

不,这不是将ASCII文本转换为盲文的伪装

Unicode中有2 8 = 256个盲文模式。(“盲文”是指8单元电池)

W,等等。那里有多少个ASCII字符?

2 7 = 128?

那么,让我们将ASCII转换成盲文,因为绝对没有理由不这样做!


从ASCII到盲文的方式

我们可以看到每个单元格代表一个位,每个单元格是否被“打孔”。

现在,我们可以分配每个单元以将ASCII字符的位表示为二进制。

(1  )(16 )
(2  )(32 )
(4  )(64 )
(8  )( - )

* ( - )为空白

现在我们可以将ASCII转换为盲文了。例如,A(65 = 01000001)等于

例子

Input -> Output
Braille! -> ⠢⠺⠱⡱⡴⡴⠵⠑
(Upscaled)
.. .o o. o. .. .. o. o.
o. oo .o .o .o .o .o .o
.o .o .o .o oo oo oo ..
.. .. .. o. o. o. .. ..

当然a,不是(我认为是q)?
尼尔

@Neil的挑战不仅仅是“将字符代码+ 10240转换为字符”。是的,a
暴民埃里克(Erik the Outgolfer)'17

@EriktheOutgolfer我不建议这样做,但是无论哪种方式都将是错误的,因为它的打孔单元数错误。
尼尔

@Neil很好。我只是重新计算,发现你是对的。
马修·罗

LSB(右下)而不是MSB(左上)没有被使用,是否对其他人感到奇怪?
朱利安·沃尔夫

Answers:


14

果酱27 26字节

80qf{i2b7Te[4/~\)\@+++2bc}

在线尝试!

说明

盲文代码点排列整齐,因此各个点的确以二进制计。但是,代码点中的位顺序是不同的。我们需要以下顺序:

04
15
26
37

而字符按Unicode顺序排列:

03
14
25
67

(这很有意义,因为从历史上看,盲文仅使用前六个点。)请注意7,由于输入被保证在ASCII范围内,因此我们不需要点。因此,给定[6 5 4 3 2 1 0]输入字符的位列表,我们希望将它们重新排序为[3 6 5 4 2 1 0],以将代表左下角点的位拉到最高有效位置。

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.
}%


11

JavaScript(ES6),83个字节

f=
s=>s.replace(/./g,c=>String.fromCharCode((c=c.charCodeAt())&7|c*8&64|c/2&56|10240))
<input oninput=o.textContent=f(this.value)><pre id=o>


哦,是的,在使用AND并保存一个字节之前,我可能应该除以2。
Martin Ender

也许可以使用jQuery滥用?
马修·罗


5

CJam,27个字节

Neil盗取了1个字节。

q{i__8&8*@7&@2/56&++'⠀+}%

在线尝试!

说明

这使用与我的其他CJam答案相同的基本思想,但是使用按位算术而不是基本转换和列表操作来对位进行重新排序。

q        e# Read all input.
{        e# Map this block over each character...
  i__    e#   Convert the character to its code point and make two copies.
  8&     e#   AND 8. Gives the 4th bit, which we need to move to the 7th place.
  8*     e#   Multiply by 8 to move it up three places.
  @7&    e#   Pull up another copy and take it AND 7. This extracts the three
         e#   least significant bits which shouldn't be moved at all.
  @2/    e#   Pull up the last copy and divide by 2 to shift all bits down
         e#   by one place.
  56&    e#   AND 56. Extracts the three most-significant bits.
  ++     e#   Add all three components back together.
  '⠀+    e#   Add to the empty Braille character which is the offset for all
         e#   the code points and which converts the value to a character.
}%


2

Mathematica 100字节

FromCharacterCode[10240+#~Drop~{4}~Prepend~#[[4]]~FromDigits~2&/@ToCharacterCode@#~IntegerDigits~2]&

取消高尔夫:

ToCharacterCode["Braille!0"]
PadLeft@IntegerDigits[%,2]
Prepend[Drop[#,{4}],#[[4]]]&/@%
FromDigits[#,2]&/@%
FromCharacterCode[%+10240]

+60个字节用长函数名捆绑在一起。


1

果冻,21字节

O&€“¬®p‘æ.1,8,.+“'ṁ’Ọ

在线尝试!

怎么运行的

O&€“¬®p‘æ.1,8,.+“'ṁ’Ọ  Main link. Argument: s (string)

O                      Ordinal; map all characters to their Unicode code points.
   “¬®p‘               Yield the code points of the enclosed characters in Jelly's
                       code page, i.e., [1, 8, 112].
 &€                    Take the bitwise AND of each code point to the left and the
                       three code points to the right.
          1,8,.        Yield [1, 8, 0.5].
        æ.             Take the dot product of the array to the right and each flat
                       array in the array to the left.
                “'ṁ’   Yield 10240 = 250 × 39 + 239, where 39 and 239 are the
                       indices of ' and ṁ in Jelly's code page.
               +       Add 10240 to all integers to the left.
                    Ọ  Unordinal; convert all code points to their respective 
                       Unicode charcters.

0

视网膜,59字节

T`�-- -'0-7@-GP-W\`-gp-w--(-/8-?H-OX-_h-ox-`⠀-⡿

在线尝试!十六进制转储:

0000  54 60 00 2a 07 10 2a 17  20 2a 17 30 2a 17 40 2a  T`�-- -'0-7@-
0010  47 50 2a 57 5c 60 2a 67  70 2a 77 08 2a 0f 18 2a  GP-W\`-gp-w--
0020  1f 28 2a 2f 38 2a 3f 48  2a 4f 58 2a 5f 68 2a 6f  (-/8-?H-OX-_h-o
0030  78 2a 7f 60 e2 a0 80 2a  e2 a1 bf                 x-`⠀-⡿


0

芯片62 59个字节

h*
 Z~.
z.g+b
>xv<
||sf
Zx^<
Z< |
A/a/D
B/b
C/c
E/d
F/e
G/f

在线尝试!

我怀疑我还能打更多的高尔夫球,只是想知道如何...

芯片将输入的每个字节读取为一组位,由字母表的前八个字母(大写输入,小写输出)表示:

HGFEDCBA

我们只需要将输入的那些位映射到以下三个字节的输出:

11100010 101000hd 10gfecba

代码的上半部分完成所有排序,并生成前两个字节,下半部分生成第三个字节。

由于规范仅要求处理ASCII的7位,因此我们不进行检查H。要包含第八位,请将行更改B/bB/b/H

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.