如此真实的键盘,几乎可以品尝到


126

...不是那样的,对吧?任务很简单,输出以下文本:

 ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________ 
||` |||1 |||2 |||3 |||4 |||5 |||6 |||7 |||8 |||9 |||0 |||- |||= |||BS    ||
||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______||
|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|
 ________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ 
||TAB   |||Q |||W |||E |||R |||T |||Y |||U |||I |||O |||P |||[ |||] |||\ ||
||______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__||
|/______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
 _________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________ 
||CAPS   |||A |||S |||D |||F |||G |||H |||J |||K |||L |||; |||' |||ENTER ||
||_______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______||
|/_______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|
 ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________ 
||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    ||
||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|

这是将来的键盘,因为在将来,空格与空格键无关。


为了使事情变得简单一些:

  1. 0123456789ABC...XYZ-=[]\;',./ -这些字符位于长度为6(包括填充)的键上。
  2. TAB / BS / ENTER -这些键的长度为10(包括填充)。
  3. CAPS -此密钥的长度为11(包括填充)。
  4. SHIFT -此密钥的长度为13(包括两侧的填充)。

每个单独的键大致如下所示:

 ____ 
||* ||
||__||
|/__\|

但是,应注意两个连续的键不是:

 ____  ____ 
||* ||||* ||
||__||||__||
|/__\||/__\|

但是它们是“联合的”:

 ____ ____ 
||* |||* ||
||__|||__||
|/__\|/__\|

挑战不应该太糟,祝您好运;不要错过滥用重复的机会!但是也不要小看“特殊”键;)。


赢了吗

最短的代码获胜,因为它是您所知道的


49
总得承认,令我感到惊讶的是,没有多少人担心未来派的键盘不包含空格...
Magic Octopus Urn

97
我想太空毕竟不是最后的领域。
格雷格·马丁

48
“ TASTE”是“ key”的德语单词:)
QBrute

31
“ TASTE”是挪威语中的“打字” :)
Stewie Griffin

32
但这是英文单词“ flavor”。在这里
李斯特先生,2016年

Answers:


117

V189、179、175、164、161、157、155、149、145、141、135字节

¬19É`A0-=BS´ 
TAB³ qwertyuiop[]\
CAPS³ asdfghjkl;'ENTER 
SHIFT´ ÄJizxcvbnm,./Í„A-Z ]/Õ& 
ÍÓ«ü$/|||&
òÙÓ„|]/_
ÙÓ׫/Ü|¯
kkPÓ/_ _
kòÎx$x

在线尝试!

这个答案现在可以发布了!


观看它运行!这是一个经过稍微修改的版本,会在运行时进行更新,因此您可以对其进行排序。这是一个过时的版本,因为我还没有重新录制它,但是一般方法是相同的。

这可能是有史以来最长的V答案。V的解释器非常慢,这当然没有帮助。我花了一个小时左右的时间写了第一版,但我一直反复回到它的上面,每次都削了几个字节。由于全键盘为1215字节,因此当前的答案比输出短91%,因此我对结果非常满意。

由于其中包含一些不可打印的字符以及大量的非ASCII字符,因此这里有一个十六进制转储:

00000000: ac31 39c9 6041 302d 3d42 53b4 200a 5441  .19.`A0-=BS. .TA
00000010: 42b3 2071 7765 7274 7975 696f 705b 5d5c  B. qwertyuiop[]\
00000020: 0a43 4150 53b3 2061 7364 6667 686a 6b6c  .CAPS. asdfghjkl
00000030: 3b27 454e 5445 5220 0a53 4849 4654 b420  ;'ENTER .SHIFT. 
00000040: 1bc4 4a69 7a78 6376 626e 6d2c 2e2f 1bcd  ..Jizxcvbnm,./..
00000050: 8441 2d5a 205d 2fd5 2620 0acd d3ab fc24  .A-Z ]/.& .....$
00000060: 2f7c 7c7c 260a f2d9 d384 7c5d 2f5f 0ad9  /|||&.....|]/_..
00000070: d3d7 ab2f dc7c af0a 6b6b 50d3 2f5f 205f  .../.|..kkP./_ _
00000080: 0a6b f2ce 7824 78                        .k..x$x

到底是怎么工作的?

好吧,这种解释将是一个笨拙的事情。你准备好了吗?首先,我们需要输入字母,以便我们可以建立它们周围的键。这是

¬19É`A0-=BS´ 
TAB³ qwertyuiop[]\
CAPS³ asdfghjkl;'ENTER 
SHIFT´ <esc>ÄJizxcvbnm,./<esc>

哪个插入:

`1234567890-=BS    
TAB   qwertyuiop[]\
CAPS   asdfghjkl;'ENTER 
SHIFT    zxcvbnm,./SHIFT  

它输入起来非常简单,但是我们使用了一些技巧来保存字符。例如,¬19输入“ 123456789”,³输入三个空格,然后我们复制班次,这样就无需多次输入。

注意这里的字母是小写的。这样,我们可以轻松区分大写键(例如“ ENTER”)和单个字母。用这种方式编写它们可以更轻松地分辨出哪些字符放在了前面,并且只添加了一个字节即可将它们转换为小写字母。因此,我们执行了一条替换命令,将它们转换为大写,并在每一个后面添加一个空格:

Í               " Globally replace
 [^A-Z ]        " Anything but a uppercase alphabet character or a space
        /       " with
         Õ&     " The matched pattern made uppercase, followed by a space

现在,我们采用每个键序列(任何非空格运行),并在它们之前和之后放置三个小节:

Í           " Globally replace
 Ó«         "   Any number of non-space characters
   ü        "   or
    $       "   an end of line
     /      " with
      |||   "    Three bars 
         &  "    And the matched pattern

此时,缓冲区如下所示:

|||` |||1 |||2 |||3 |||4 |||5 |||6 |||7 |||8 |||9 |||0 |||- |||= |||BS    |||
|||TAB   |||Q |||W |||E |||R |||T |||Y |||U |||I |||O |||P |||[ |||] |||\ |||
|||CAPS   |||A |||S |||D |||F |||G |||H |||J |||K |||L |||; |||' |||ENTER |||
|||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    |||

实际上,在第一列和最后一列上具有三个小节非常方便,并且从长远来看最终可以节省很多字节。

这是我们运行一个大循环的地方。这将转换如下所示:

|||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    |||

变成这样的东西:

 ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________ 
||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    ||
||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|

在的两个实例之间的所有操作都ò将一直运行到发生错误为止,而当我们尝试进入一条确实存在的行时会发生这种情况。由于我们只运行了全局替换命令,因此光标位于最后一行,我们将逐步转换它们。

ò         " Recursively:
 Ù        "   Duplicate this line
  Ó       "   Substitute all on this line:
   [^|]   "     Anything but a bar
       /  "   With:
        _ "     An underscore

这是

|||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________|||

线。

Ù         "   Duplicate this line
 Ó        "   Subsitute all on this line:
  ׫      "     A run of *non-word characters* (that is, [^0-9A-Za-z_])
    /     "   With:
     Ü|¯  "     '\|/'

这是

\|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|/

线。

kk        "   Move up two lines (to the original text with "SHIFT")
  P       "   Paste the last line we duplicated (the one with all the underscores)
   Ó      "   Substitute:
          "     Since we don't give any regex here, it re-uses the last one 
          "     (a run of *non-word* characters)
    /     "   With:
     _ _  "     '_ _'

这是:

_ ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________ _

线。

k         "   Move up a line (this will throw an error, breaking the loop when we're done)
 ò        " Endwhile

现在我们有了完整的键盘,但是每一行都包含一个额外的小节,一个额外的斜杠(正向或反向)或一个额外的下划线。超级容易修复

Î             " On every line:
 x            "   Delete a character
  $           "   Move to the end of the line
   x          "   and delete another character

疯狂之后,缓冲区被隐式打印。


1
在输出右侧的空白处似乎还有4个下划线?
ErikE

7
您低估了这个答案的真实程度。
魔术章鱼缸

1
@carusocomputing哈哈,我想你是对的。我为这个答案感到骄傲,我的语言是击败泡泡糖的唯一答案。:)
DJMcMayhem

2
@DJMcMayhem如果在1/3/2017之前没有人击败您,则将您标记为获胜者;)。
魔术章鱼缸

7
顺便说一句,到目前为止,这仍然是我在网站上最喜欢的答案。我无法计数我观看GIF的次数。
Magic Octopus Urn

41

Lua的5.3,416个 394字节。

k="` 1 2 3 4 5 6 7 8 9 0 - = BS|TAB Q W E R T Y U I O P [ ] \\|CAPS A S D F G H J K L ; ' ENTER|SHIFT Z X C V B N M , . / SHIFT"S={TAB=6,BS=6,ENTER=6,CAPS=7,SHIFT=9}for v in k:gmatch"[^|]+"do for i=1,4 do for s in v:gmatch"%S+"do l=S[s]or 2j=("_"):rep(l)io.write(i==1 and" _"..j.."_"or i==2 and"||"..s..(" "):rep(l-#s).."|"or i==3 and"||"..j.."|"or"|/"..j.."\\")end print(i>1 and"|"or"")end end

取消高尔夫,并带有注释。

keys="` 1 2 3 4 5 6 7 8 9 0 - = BS|TAB Q W E R T Y U I O P [ ] \\|CAPS A S D F G H J K L ; ' ENTER|SHIFT Z X C V B N M , . / SHIFT" -- Define a keyboard. Separated with |'s, there's probably a nicer way to do this, but I'm not sure about how to yet.
special_keys={TAB=6,BS=6,ENTER=6,CAPS=7,SHIFT=9} -- Special keys get special definitions
for v in keys:gmatch"[^|]+" do -- For each row on the keyboard...
    for i=1, 4 do -- Each of the 4 rows per key...
        for s in v:gmatch"%S+" do -- Match each individual key.
            l=special_keys[s]or 2 j=("_"):rep(l) -- l is the length of the key, j is "_" repeated length times, which is used a bit.
            io.write(i==1 and -- Lua needs Switch Statements!
                     " _"..j.."_" -- The top of the key is a Space, then j with two _'s around it.
                     or
                     i==2 and
                     "||"..s..(" "):rep(l - #s).."|" -- Second row is || then the key, then the remaining whitespace, and then one more |, which chains together.
                     or
                     i==3 and
                     "||"..j.."|" -- Third row is like the second, but without the key. Instead of whitespace, uses j, which is the underlines.
                     or
                     "|/"..j.."\\") -- Last row is like the third row, but with "|/" and "\" instead of "||" and "|"
        end
        print(i>1 and"|"or"") -- First line is the only line that doresn't need a "|", everything else gets a "|" before the newline.

    end
end

输出量

 ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________
||` |||1 |||2 |||3 |||4 |||5 |||6 |||7 |||8 |||9 |||0 |||- |||= |||BS    ||
||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______||
|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|
 ________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
||TAB   |||Q |||W |||E |||R |||T |||Y |||U |||I |||O |||P |||[ |||] |||\ ||
||______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__||
|/______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
 _________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________
||CAPS   |||A |||S |||D |||F |||G |||H |||J |||K |||L |||; |||' |||ENTER ||
||_______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______||
|/_______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|
 ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________
||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    ||
||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|

我将被其他语言破坏,但我想我会尝试一下。相当复杂,而且比键盘还短!


15
拧其他语言,您是第一个使用稀有语言的人!令人印象深刻,尽管我确定您绝对不需要在每个字母上都使用管道作为分隔符。注意“特殊”键仅在行的开头和结尾。我确信该提示可以某种方式为您节省宝贵的字节。
魔术章鱼缸

您正在使用哪个版本的Lua?在Lua 5.1上,它给了我一个语法错误:stdin:1:“ 2j”附近的格式错误
brianush1

5
@ Brianush1 Lua 5.3,它允许数字常量坐在不是十六进制数字或'x'的任何字母的旁边(如果是0的话
。– ATaco 2016年

29

泡泡糖,191字节

0000000: ad d2 35 7a c6 30 10 06 e1 5e a7 50 15 66 fe 99  ..5z.0...^.P.f..
0000010: c1 8c 61 50 0e b2 87 8f 27 24 f7 eb af 78 2b e3  ..aP....'$...x+.
0000020: 3c b2 ae 99 1a 66 8d c8 a7 15 91 73 b8 80 4b b8  <....f.....s..K.
0000030: 82 6b b8 81 5b b8 83 1e 9c c1 31 8c 60 5e d9 66  .k..[.....1.`^.f
0000040: 22 46 c4 39 d1 c2 78 d6 a9 73 6f 5a d8 9b 18 ff  "F.9..x..soZ....
0000050: bb 5a e8 55 cf e6 fc ae 48 01 8f b0 82 12 6a 78  .Z.U....H.....jx
0000060: 86 7b 08 20 83 1c 5e e1 1d de e8 e5 7f 57 b4 d0  .{. ..^......W..
0000070: 8b a9 9b f9 5e 5d 9d af c5 2c af 7e 82 cd a0 82  ....^]...,.~....
0000080: 25 ac 61 03 5b 08 21 82 18 06 b0 0b ab b4 5e 95  %.a.[.!.......^.
0000090: ad 5e 5d 9d 2f d6 e9 f9 d2 c4 f2 bd aa 6d b0 ae  .^]./........m..
00000a0: ed 4f b1 17 78 82 05 3c c0 1c 52 48 e0 08 4e e0  .O..x..<..RH..N.
00000b0: 14 5a 77 fb 5e aa 58 be 97 aa 98 bf db 7c 01     .Zw.^.X......|.

在线尝试!


1
Bubblegum不公平。
约书亚

7
@Joshua最好为解决方案设定基准。如果没有什么能击败泡泡糖,那就是问题所在。
Sarge Borsch

19

Haskell,263个字符(353个字节,UTF-8)

import Data.List
main=mapM_ putStrLn$transpose.foldr k[g]=<<
 [s"`1234567890-="%"   ←"
 ,"↹   ":s"𝑄𝑊𝐸𝑅𝑇𝑌𝑈𝐼𝑂𝑃[]\\"
 ,"⇩    ":s"𝐴𝑆𝐷𝐹𝐺𝐻𝐽𝐾𝐿;'"%"     ↵"
 ,"⇧       ":s"𝑍𝑋𝐶𝑉𝐵𝑁𝑀,./"%"       ⇧"]
r%e=r++[e]
g=" |||"
k s r=g:"_||/":['_':c:"__"|c<-s]%"_||\\"++r
s=map(:" ")

该键盘的屏幕截图

由于针对这些unicode字符进行了很多讨论,因此...这是同一程序,简化为全ASCII:

Haskell,263个字符(263个字节的UTF-8)

import Data.List
main=mapM_ putStrLn$transpose.foldr k[g]=<<
 [s"`1234567890-="%"BS  "
 ,"TAB ":s"QWERTYUIOP[]\\"
 ,"CAPS ":s"ASDFGHJKL;'"%"ENTER "
 ,"SHIFT   ":s"ZXCVBNM,./"%"SHIFT   "]
r%e=r++[e]
g=" |||"
k s r=g:"_||/":['_':c:"__"|c<-s]%"_||\\"++r
s=map(:" ")

3
Unicode键盘?有趣的选择(在那里看起来很好看数学字母),但我认为这违反了竞争规则。
马里奥·卡内罗

@MarioCarneiro公平地说,它根本不影响程序的长度。
pydsigner

1
@pydsigner这样做,因为的单词ENTER长于的字符↩︎
timothymh '16

5
但是您正在比较ENTER ↩︎ ,空格填充使它的长度相同。
CodeMonkey '16

2
实际上,我希望unicode可以使程序的字节数更长,因为高unicode在UTF8中的字节数要比ASCII多。
马里奥·卡内罗

18

PHP,303字节

懒但是有效。:)

<?=gzinflate(base64_decode('rdO5DoJAEIDhnqegs/G+jbEAvA88wBuzPsg8vPyLZo3tOMUXmt1k/iy+ycfXYj88kacvIg1oQgva0IEu9KAPA6hDBUYQJn4+IvldxogWhrtqxmRamEw8t66afMc0CO26soczTOAAKVzhCAvYwg7u8IDs06tYVx3Oc+uqw7lef3lfUbBLimABJDCGKcxgDktYwRqGULJ143Ry+O71r/elDvb7vnSx3r2S+WKaFn+U3OACEZzs7wYxbKAMVajZvO6066WK9dNLFcuefgE'));

1
真好 烦人的是,我无法使用compress / gzip / bzip2 / 7z获得相同级别的压缩,否则Bash版本会短很多。就目前而言,它是318个字符。
康拉德·鲁道夫

14
我很确定禁止或至少不赞成在您的程序中使用外部压缩算法。它违背了问题的目的。
没人

1
@KonradRudolph据我了解,gzdeflate()使用与gzip命令行相同的压缩方式,但是会跳过文件头和校验和,因此它总是会短一些。
Alex Howansky '16

300个字节:<?=gzinflate(base64_decode('rdO5DoJAEIDhnqegs/G+jbHA+0QEvDHrg8zDy79EMbTDFF+3m8yfXdek42phHJG3KyItaEMHutCDPgxgCCNoQg0mMI3cdETSu4wRLQx3NYxJtDCJOL9t1cnSFWNvareVE1xhASHEcIczbOAIATzhBck3V7atupuTb6vulucq43XNvCDKenkQwRyWsII1bGEHexhDxcb140X4n6us16XuVXxdulZZrmi9WcbZd5IH3GAGF/vXwIcDVKEODVs3P53nUrUq5FK1sqc/'));。压缩机:sandbox.onlinephpfunctions.com/code/...解压缩:sandbox.onlinephpfunctions.com/code/...
伊斯梅尔·米格尔

4
@Nobody外部没有任何东西,gz是PHP默认编译​​的一部分,因此被隐式允许。
Alex Howansky '16

18

Python 3.5 +,239个字节

s="SHIFT   "
for k in[(*"`1234567890-=","BS   "),("TAB  ",*"QWERTYUIOP[]\\"),("CAPS  ",*"ASDFGHJKL;'","ENTER"),(s,*"ZXCVBNM,./",s)]:
 for f in"{1}__ ,|{} ||,|{1}||,/{1}\|".split(","):print(f[-1]+"".join(f.format(c,"_"*-~len(c))for c in k))

元组中的splat是否需要Python 3.5+?
mbomb007 '16

1
如果反转每个键的结构并"".join(...) + f[0]在内部循环中使用,则可以节省一个字节。format在字符串中交换参数顺序和相应的占位符还会节省另外两个字节。
dfernan '16

['{1}__ ','|{} ||','|{1}||','/{1}\\|']比使用短split
亚历克斯·霍尔

16

批处理,465452字节

@echo off
call:c _ ` 1 2 3 4 5 6 7 8 9 0 - "=" "BS   " _____
call:c _____ "TAB  " Q W E R T Y U I O P [ ] \ _
call:c ______ "CAPS  " A S D F G H J K L ";" ' ENTER _____
call:c ________ "SHIFT   " Z X C V B N M "," . / "SHIFT   " ________
exit/b
:c
set t=%1_
set s=!!%~2 !!!%3 !!
:l
set t=%t%#__
set s=%s%!%~4 !!
shift
if not "%~5"=="" goto l
set t=%t%#%4_
for %%l in (" _%t:#=_ _%_" "%s:!=|%" "||%t:#=|||%||" "|/%t:#=\|/%\|")do echo %%~l

:c子例程处理一行键。含有多余的空格键需要被引用,因为这样做=;,钥匙,可能是因为在一个错误shift的命令。第一个和最后一个参数是与_第一个和最后一个键具有相同长度的字符串,以帮助级联。t然后_以第一行,第三行和第四行的公共s 结尾,以#s标记联接,在添加前导字符和尾随字符之前对其进行了适当替换,而s第二行则是|s ,但随着行的!减少,s更改为s "我需要的s 数。编辑:通过在一条语句中打印所有四行节省了1个字节,通过优化分配s变量的方式节省了12个字节。


14

Ruby,226个字节

16.times{|i|puts (([[?`,'TAB  ','CAPS  ',s='SHIFT   '][j=i/4]]+%w{1234567890-= QWERTYUIOP[] ASDFGHJKL;' ZXCVBNM,./}[j].chars+[['BS   ',?\\,'ENTER',s][j]]).map{|e|e.tr('^|'[-i%4/3,2],?_)}*3*"__ _ |||_|||_\\|/"[i%4*4,4])[72,75]}

改进如下:

1.在数组的开头和结尾没有空的字符串元素。取而代之的是将阵列一式三份制作3个并排的键盘。转换为字符串后,我们有3个缺少外边缘的键盘。这被截断以仅显示中间的一个,带有边缘。

2.更改了Ruby版本。使用Ideone而不是在我的计算机上安装1.9.3。这意味着.chars.to_a可以缩短为公正.chars

Ruby,239个字节

还有更多字节可以使用。明天看。

16.times{|i|puts ((['']+[[?`,'TAB  ','CAPS  ',s='SHIFT   '][j=i/4]]+%w{1234567890-= QWERTYUIOP[] ASDFGHJKL;' ZXCVBNM,./}[j].chars.to_a+[['BS   ',?\\,'ENTER',s][j]]+['']).map{|e|e.tr('^|'[-i%4/3,2],?_)}*"__ _ |||_|||_\\|/"[i%4*4,4])[2..-2]}

不打高尔夫球

16.times{|i|                                                            #iterate throug 16 lines of output
  puts ((['']+[[?`,'TAB  ','CAPS  ',s='SHIFT   '][j=i/4]]+              #build row from blank element plus left special key
    %w{1234567890-= QWERTYUIOP[] ASDFGHJKL;' ZXCVBNM,./}[j].chars.to_a+ #plus regular keys
   [['BS   ',?\\,'ENTER',s][j]]+['']).map{|e|                           #plus right special key and another blank element
                                      e.tr('^|'[-i%4/3,2],?_)}*         #if i%4 != 1, replace the keytop legend with _ characters 
   "__ _ |||_|||_\\|/"[i%4*4,4])[2..-2]                                 #join the middle parts of the keys with ends. truncate spurious outer ends before printing.
}

13

C#,357个字节(在一行中,并且包含了大多数建议)


var s="";
foreach(var r in@"`|1|2|3|4|5|6|7|8|9|0|-|=|BS   ~TAB  |Q|W|E|R|T|Y|U|I|O|P|[|]|\~CAPS  |A|S|D|F|G|H|J|K|L|;|'|ENTER~SHIFT   |Z|X|C|V|B|N|M|,|.|/|SHIFT   ".Split('~'))
for(int i=0;i<4;s+=i>0?"|\n":"\n",i++)
foreach(var k in r.Split('|'))
{
var u=new string('_',k.Length+1);
s+=i<1?" "+u+"__"
:i<2
?"||"+k+" |"
:i<3
?"||"+u+"|"
:"|/"+u+@"\";
}
Console.Write(s);

或者,带有字符串插值的353和所有其他建议

var s="";foreach(var r in@"`|1|2|3|4|5|6|7|8|9|0|-|=|BS   ~TAB  |Q|W|E|R|T|Y|U|I|O|P|[|]|\~CAPS  |A|S|D|F|G|H|J|K|L|;|'|ENTER~SHIFT   |Z|X|C|V|B|N|M|,|.|/|SHIFT   ".Split('~'))for(int i=0;i<4;s+=i>0?"|\n":"\n",i++)foreach(var k in r.Split('|')){var u=new string('_',k.Length+1);s+=i<1?$" {u}__":i<2?$"||{k} |":i<3?$"||{u}|":$@"|/{u}\";}Console.Write(s);

取消高尔夫(无字符串插值):

var solution = "";
foreach (var row in @"`|1|2|3|4|5|6|7|8|9|0|-|=|BS   ~TAB  |Q|W|E|R|T|Y|U|I|O|P|[|]|\~CAPS  |A|S|D|F|G|H|J|K|L|;|'|ENTER~SHIFT   |Z|X|C|V|B|N|M|,|.|/|SHIFT   ".Split('~'))
for (int i = 0; i < 4; solution += i > 0 ? "|\n" : "\n", i++)
foreach (var key in row.Split('|'))
{
   var underscores = new string('_', key.Length + 1);
   solution += i < 1 ? " " + underscores + "__"
                     : i < 2
                     ? "||" + key + " |"
                     : i < 3
                     ? "||" + underscores + "|"
                     : "|/" + underscores + @"\";
}
Console.Write(solution);

5
您可以保存很多字节来将高尔夫球代码格式化为一行:foreach(var r in q){for(int i=0;i<4;i++){foreach...
Mario

1
@Mario我只是字节检查了一下,给定的值实际上是没有换行符的计数,因此从技术上讲它已经完成了
Alfie Goodacre

1
使用插值法将高尔夫球轻微降低至397字节,并替换==< s+=i<1?$" {u}__":i<2?$"||{k.PadRight(l)}|":i<3?$"||{u}|":$"|/{u}\\";
Alfie Goodacre

谢谢@Alfie Goodacre。根据您的建议,我用“ <”替换了“ ==”。我省略了插值,以使其版本特定性降低。
Klinger

@Klinger我同意,插值对任何在线编译器也不起作用,所以这是一个不错的选择!
Alfie Goodacre,2013年

10

PowerShell v2 +,465字节

($b=($a=' ____')*10)+$a*3+" "+($d='_'*8)
"||``@$(1..9-join'@')@0@-@=@BS    ||
||$(($f=,'__'*10-join'#'))#__#__#__#$(($g='_'*6))||
$(($c=($e='|/__\')*10))$e$e$e|/$g\|
 $d$b$a$a$a
||TAB  @Q@W@E@R@T@Y@U@I@O@P@[@]@\ ||
||$g#$f#__#__#__||
|/$g\$c$e$e$e|
 _$d$b$a $d
||CAPS  @A@S@D@F@G@H@J@K@L@;@'@ENTER ||
||_$g#$f#__#$g||
|/_$g\$c$e|/$g\|
 ___$d$b ___$d
||SHIFT   @Z@X@C@V@B@N@M@,@.@/@SHIFT    ||
||___$g#$f#___$g||
|/___$g\$c|/___$g\|"-replace'@',' #'-replace'#','|||'

考虑到PHP和Python答案的简短程度,我很尴尬地发布此答案,不要介意C#答案,但是我无法缩短此方法。其他方法可能会产生更好的结果。

它基本上只是一个巨大的多行字符串,用变量($a等)替换各种子字符串,-replace最后加几个s来完成它。$(...)在需要引入新变量的地方插入了脚本块。

在线尝试!


7

Python,493 458字节。

k=[['|']*75 for i in [0]*16]
v=' '
w='_'
y=0
def a(s,x,o):k[y+o][x:x+len(s)]=list(s)
def p(s,i,x):a(s+v*(i-len(s)),x+2,1);a(v+w*(i+2)+v,x,0);a(w*i,x+2,2);a(w*i,x+2,3);a('/',x+1,3);a('\\',x+i+2,3);return x+i+3
def q(s,x):return reduce(lambda a,b:p(b,2,a),list(s),x)
p('BS',6,q('`1234567890-=',0))
y=4
q('QWERTYUIOP[]\\',p('TAB',6,0))
y=8
p('ENTER',6,q('ASDFGHJKL;\'',p('CAPS',7,0)))
y=12
p('SHIFT',9,q('ZXCVBNM,./',p('SHIFT',9,0)))
for l in k:print''.join(l)

功能等效,但可读性更高:

k=[['|']*75 for i in range(16)]
def a(s,x,y):k[y][x:x+len(s)]=list(s)
def p(s,i,x,y):
    a(s+' '*(i-len(s)),x+2,y+1)
    a(' '+'_'*(i+2)+' ',x,y)
    a('_'*i,x+2,y+2)
    a('_'*i,x+2,y+3)
    k[y+3][x+1]='/'
    k[y+3][x+i+2]='\\'
    return x+i+3
def q(s,x,y):return reduce(lambda a,b:p(b,2,a,y),list(s),x)
p('BS',6,q('`1234567890-=',0,0),0)
q('QWERTYUIOP[]\\',p('TAB',6,0,4),4)
p('ENTER',6,q('ASDFGHJKL;\'',p('CAPS',7,0,8),8),8)
p('SHIFT',9,q('ZXCVBNM,./',p('SHIFT',9,0,12),12),12)
for l in k:print ''.join(l)

不幸的是,它已经比Lua中提供的答案更长。


您可以将p函数中的行放在由分号分隔的一行上。另外,我还以为你不能做第一行k=[['|']*75]*16,你知道为什么吗?
nedla2004 '16

您还可以定义'_'' '一个变量,以节省一些字节。
nedla2004'2013/

感谢您的提示!我认为k = [['|'] * 75] * 16会创建16个对同一数组的引用,因此一行中的更改也会影响其他行。
科比

好的,那么您至少可以更改range(16)[0]*16
nedla2004'2013/

一个小问题是您的代码在技术上不会产生正确的输出,但是您可以通过更改for l in k:print ' '.join(l)为来解决此问题for l in k:print''.join(l)
nedla2004 '16

7

PHP,316312字节

foreach([($s=str_split)("`1234567890-=")+[13=>"BS   "],["TAB  "]+$s("_QWERTYUIOP[]\\"),["CAPS  "]+$s("_ASDFGHJKL;'")+[12=>ENTER],[$h="SHIFT   "]+$s("_ZXCVBNM,./")+[11=>$h]]as$r)for($y=-1;$y++<3;)foreach($r as$i=>$k)echo["\n".$a="| "[!$y]][$i],"_||/"[$y],str_pad($y-1?_:$k,strlen($k)+1,$y-1?_:" "),"_||\\"[$y],$a;

我很确定这种方法不能再推广了。但是,如果有人发现10个以上的字节...:D
运行-r

分解

foreach([                       // loop through rows
    ($s=str_split)("`1234567890-=")+[13=>"BS   "],
    ["TAB  "]+$s("_QWERTYUIOP[]\\"),
    ["CAPS  "]+$s("_ASDFGHJKL;'")+[12=>ENTER],
    [$h="SHIFT   "]+$s("_ZXCVBNM,./")+[11=>$h]
]as$r)
    for($y=-1;$y++<3;)          // loop through lines 0..3
        foreach($r as$i=>$k)    // loop through keys
            echo["\n".$a="| "[!$y]][$i],// first key in row: leading NL + space/pipe
                "_||/"[$y],             // key edges
                str_pad(
                    $y-1?_:$k,          // line 1: key label; else underscore
                    strlen($k)+1,       // pad to length+1
                    $y-1?_:" "),        // with spaces for label, underscores else
                "_||\\"[$y],            // more key edges
                $a                      // joining edges
            ;

6

Bash(在OSX上),12 8 + 221 +1 = 234230字节

是的,我知道,压缩。但这有效,不是吗?

gunzip<f

在当前目录中需要一个具有以下内容的文件“ f”(出于对PPCG友好的考虑,将其放入base64中-您可以首先将其解码为文件“ f”。):

H4sIAHbPT1gAA63TuQ6CQBCA4Z6noLPxvo2xALwPPMAbsz7IPLz8i2aN7TjFFxo2mT+7vsnH12I/PJGnLyINaEIL2tCBLvSgDwOoQwVGECZ+PiL5WcaIFoazasZkWphMPLeumnzHNAjturKHM0zgAClc4QgL2MIO7vCA7NOrWFcdznPrqsO5Xn+5X1GwS4pgASQwhinMYA5LWMEahlCydeN0cvju9a/7pQ72e790sd69kvlimhYvSm5wgQhO9rlBDBsoQxVqNq/72/VSxfrppYpV9HoBoNfjQcAEAAA=

4
可以通过写来缩短gunzip<f
Konrad Rudolph

@KonradRudolph优秀点。谢谢。
Addison Crump

您可以使用节省2个字节zcat f,并通过删除两个结尾的空字节来节省2个字节(gzip抱怨但产生了所需的输出)。
吉尔斯(Gilles)2016年

@Gilles并没有真正为我节省字节-我必须重命名文件“ fZ”(至少在OSX上)。删除尾随的空字节不仅使gzip抱怨-还使它出错并且不打印任何内容。
Addison Crump

@VoteToClose哦,对了zcat<f。在Linux上,zcat不带结尾的零将使gzip抱怨(“ gzip:stdin:文件的意外结尾”),但仅在打印所需的输出之后。
吉尔斯(Gilles)2016年

5

JavaScript(ES6),286

没有参数的匿名函数

_=>[..."`1234567890-=~~QWERTYUIOP[]\\~ASDFGHJKL;'~~ZXCVBNM,./~"].map(x=>(o+=`/${b='_'.repeat(w=x<y?2:' 667699'[x=["BS","TAB","CAPS","ENTER"][p++]||'SHIFT',p])}\\|`,m+=y+(x+'    ').slice(0,w)+y+y,n+=y+b+y+y,l+=' __'+b)[73]&&(k.push(l,m,n,o),l='',m=n=o=y),m=n=o=y='|',p=l=k=[])&&k.join`
`

少打高尔夫球

_=>[..."`1234567890-=~~QWERTYUIOP[]\\~ASDFGHJKL;'~~ZXCVBNM,./~"]
  .map(x=>
      (
        w = x < y // special chars are marked '~' that is > '|'
            ? 2 // normal key, width 2
            : ( // else special key, set x and width
                // p should be incremented at next step, but I need to make it numeric as it starts as []
                x = ["BS","TAB","CAPS","ENTER"][p++]||'SHIFT',
                ' 667699'[p], // value for w (note p is off by 1)
              ),
        b = '_'.repeat(w), // bottom border (and top, almost)
        o +=`/${b}\\|`, //  line 4
        n += y+b+y+y,   //  line 3
        m += y+(x+'    ').slice(0,w)+y+y, // line 2
        l += ' __'+b    // top line, the border must be longer
      )[70] && // check if at end of row (check position in l)
         (
            k.push(l, m, n, o), // add lines to list
            l = '', // reset all
            m = n = o = y
         )
    , // initial setup
    // y stays fixed to '|', lines 2,3,4 start as '|'
    m = n = o = y ='|',
    // k is the lines array, l will become as string and starts empty
    // p is the index of current special key and will become numeric
    p = l = k = [] 
  ) 
  && k.join`\n` // return lines as a single string

F=_=>[..."`1234567890-=~~QWERTYUIOP[]\\~ASDFGHJKL;'~~ZXCVBNM,./~"].map(x=>(o+=`/${b='_'.repeat(w=x<y?2:' 667699'[x=["BS","TAB","CAPS","ENTER"][p++]||'SHIFT',p])}\\|`,m+=y+(x+'    ').slice(0,w)+y+y,n+=y+b+y+y,l+=' __'+b)[73]&&(k.push(l,m,n,o),l='',m=n=o=y),m=n=o=y='|',p=l=k=[])&&k.join`
`

O.textContent=F()
<pre id=O></pre>


5

Swift,777字节

func b(_ c:String,_ d:Int,_ e:Int)->[String]{var f=Array(" __ |||||||||/\\|".characters),g=[String]()
for h in 0..<4{var i="";for j in e..<4{i.append(f[j+h*4])
if j==1{var k="_",l=0;if h==1{k=" ";l=c.characters.count;i += c}
for _ in l..<d{i+=k}}};g.append(i)};return g}
func c(_ d:String)->[(String,Int)]{return Array(d.characters).map{("\($0)",2)}}
func d(_ e:String,_ f:Int)->[(String,Int)]{return [(e,f)]}
var e=[c("`1234567890-=")+d("BS",6),d("TAB",6)+c("QWERTYUIOP[]\\")]
e+=[d("CAPS",7)+c("ASDFGHJKL;'")+d("ENTER",6),d("SHIFT",9)+c("ZXCVBNM,./")+d("SHIFT",9)]
var f="";for g in 0..<e.count{let h=e[g]
var i=[[String]]();for j in 0..<h.count{
let k=h[j],l=b(k.0,k.1,(j>0 ? 1:0));i.append(l)}
for k in 0..<4{if g>0||k>0{f+="\n"}
for l in i{f+=l[k]}}};print(f,separator:"")

斯威夫特通常不是打高尔夫球的理想选择,因此,比目前的最小答案(快)要少两倍是一个很好的挑战!

取消高尔夫:

func createKeyboard() {
    func createKey(_ text: String, _ middleWidth: Int, _ startingColumn: Int) -> [String] {
        var keyTempalte = " __ |||||||||/\\|"
        var keyTemplateCharacters = Array(keyTempalte.characters)

        var output = [String]()

        for y in 0 ..< 4 {
            var line = ""
            for x in startingColumn ..< 4 {
                line.append(keyTemplateCharacters[x + y*4])

                if x == 1 {
                    var spacingCharacter = "_"
                    var startingOffset = 0
                    if y == 1 {
                        spacingCharacter = " "
                        startingOffset = text.characters.count
                        line += text
                    }

                    for _ in startingOffset ..< middleWidth {
                        line += spacingCharacter
                    }
                }
            }
            output.append(line)
        }

        return output
    }

    func stringToCharacterStrings(_ str: String) -> [(String, Int)] {
        return Array(str.characters).map {("\($0)",2)}
    }

    func specialKey(_ str: String, _ middleWidth: Int) -> [(String, Int)] {
        return [(str, middleWidth)]
    }

    var keys = [stringToCharacterStrings("`1234567890-=") + specialKey("BS", 6),
                specialKey("TAB", 6) + stringToCharacterStrings("QWERTYUIOP[]\\")]
    keys += [specialKey("CAPS", 7) + stringToCharacterStrings("ASDFGHJKL;'") + specialKey("ENTER", 6),
                specialKey("SHIFT", 9) + stringToCharacterStrings("ZXCVBNM,./") + specialKey("SHIFT", 9)]

    var output = ""
    for r in 0 ..< keys.count {
        let row = keys[r]
        var rowKeys = [[String]]()
        for i in 0 ..< row.count {
            let elem = row[i]
            let key = createKey(elem.0, elem.1, (i>0 ? 1 : 0))
            rowKeys.append(key)
        }

        for y in 0 ..< 4 {
            if r > 0 || y > 0 {
                output += "\n"
            }

            for key in rowKeys {
                output += key[y]
            }
        }
    }

    print(output)
}

createKeyboard()

2
至少不是applescript
艾迪生·克伦普

1
现在我要做Java吗
CAD97,2013年

4

SOGL V0.12131个 128 127 字节竞争?

⅟]y‘9Δø∑"`ŗ0-=”čΚ"TAB  ”QWERTYUIOP[]\”č+"oF«▒Β²‘⁷Ο‘ASDFGHJKL;'”čΚ+"_№K³‘ZXCVBNM,./”č⁴++¹{"^쳑č;{U;"_||/”┼;{"_ŗ__”┼}"Ο  ψ¦℮³‘┼}O

SOGL确实有2*2/2/2*怪癖,但这些感觉太像是内置于此挑战中的了。
在这里尝试!

...‘               push "BS   "                                            ["BS   "]
    9Δ             push an array of numbers up to 9                        ["BS   ", [1,2,3,4,5,6,7,8,9]]
      ø∑           join into a single string (without ø it results to 45)  ["BS   ", "123456789"]
        "`ŗ0-=”    push "`ŗ0-=" with ŗ replaced with the digits            ["BS   ", "`1234567890-="]
               č   chop that into an array of characters                   ["BS   ", ["`","1","2","3","4","5","6","7","8","9","0","-","="]]
                Κ  add the first "BS   " to the end of the array           [["BS   ","`","1","2","3","4","5","6","7","8","9","0","-","="]]

"TAB  ”            push "TAB  "                  [[..], "TAB  "]
       Q..P[]\”    push "QWERTYUIOP[]\"          [[..], "TAB  ", "QWERTYUIOP[]\"]
               č   chop that                     [[..], "TAB  ", ["Q","W","E","R","T","Y","U","I","O","P","[","]","\"]]
                +  prepend to the array "TAB  "  [[..], ["TAB  ","Q","W","E","R","T","Y","U","I","O","P","[","]","\"]]

"...‘             push "caps  "                       [.. , "caps  "]
     ⁷Ο‘          push "enter"                        [.. , "caps  ", "enter"]
        AL;'”     push "ASDFGHJKL;'"                  [.. , "caps  ", "enter", "ASDFGHJKL;'"]
             č    chop that                           [.. , "caps  ", "enter", ["A","S","D","F","G","H","J","K","L",";","'"]]
              Κ   append "enter" to the end of array  [.. , "caps  ", ["A","S","D","F","G","H","J","K","L",";","'","enter"]]
               +  prepend "caps  " to the array       [.. , ["caps  ","A","S","D","F","G","H","J","K","L",";","'","enter"]]

"..‘             push "shift   "                [..., "shift   "]
    ZM,./”       push "ZXCVBNM,./"              [..., "shift   ", "ZXCVBNM,./"]
          č      chop it                        [..., "shift   ", ["Z","X","C","V","B","N","M",",",".","/"]]
           ⁴     duplicate the shift            [..., "shift   ", ["Z","X","C","V","B","N","M",",",".","/"], "shift   "]
            ++   append and prepend the shifts  [..., ["shift   ","Z","X","C","V","B","N","M",",",".","/","shift   "]]
              ¹  get all the arrays into one big array
result: [[["BS   ","`","1","2","3","4","5","6","7","8","9","0","-","="], ["TAB  ","Q","W","E","R","T","Y","U","I","O","P","[","]","\"], ["caps  ","A","S","D","F","G","H","J","K","L",";","'","enter"], ["shift   ","Z","X","C","V","B","N","M",",",".","/","shift   "]]]
 - a 2D array of the keyboard characters

{                                    for each array in the array do
 "...‘                                 push " |||"
      č                                chop to chars
       ;                               get the main array ontop
        {                        }     for each string in the array
         U                               uppercase it (before lowercase was used for better compression)
          ;                              get the chopped array ontop
           "_||/”                        push "_||/"
                 ┼                       append vertically
                  ;                      get the string ontop
                   {       }             for each char in the string do
                    "_ŗ__”                 push "_ŗ__"
                          ┼                append vertically
                            "..‘         push "    _||\ |||"
                                ┼        append vertically-then horizontally
                                  O    output that in a newline

哇,这真是太棒了!还没有人能击败我,真是太好了!我可能会尝试让我的发言时间短一些,但没有希望。;)
DJMcMayhem

@dzamia,即使现在正在竞争,但不是的时候,我接受了答案。我应该切换答案吗?
魔术章鱼缸

@MagicOctopusUrn IMO由您决定。建议不接受答案是有原因的:p
dzaima

建议不接受答案?哦,还算公平。然后我想我将来会停止接受答案,而将一切保持原样。
魔术章鱼缸

@MagicOctopusUrn好的,也许不接受答案有点争议,但仍然是一个重大的积极意义
dzaima

4

Python 2中,394个 388 380字节

k=[4]*13+[8],[8]+[4]*13,[9]+[4]*11+[8],[11]+[4]*10+[11];m='`1234567890-=*','*QWERTYUIOP[]*',"*ASDFGHJKL;'*",'*ZXCVBNM,./*';c,d,e,n,u=0,'','|','\n','_'
for a in 0,1,2,3:
 f=s=t=o='';x=0
 for y in k[a]:g=y-2;f+=' '+u*y;s+=e*2+m[a][x].replace('*','%s')+' |';t+=e*2+u*g+e;o+='|/'+u*g+'\\';x+=1
 d+=f+n+s+e+n+t+e+n+o+e+n
l='SHIFT   ';print d%('BS   ','TAB  ','\\','CAPS  ','ENTER',l,l)

只需构建一个代表整个键盘的大字符串,将%s替换为*,即可使用特殊键,然后使用字符串格式来更新特殊字符。

编辑

现在输出末尾有换行符,但我看不到任何不允许的地方。

在线尝试!


我认为您应该删除输出,因为它不会添加任何相关内容。
sergiol

1
@ sergiol-好点。发布时尚未通知TIO。现在更新。
ElPedro

3

C#,376个字节(在一行中)


var s="";foreach(var r in@"`|1|2|3|4|5|6|7|8|9|0|-|=|BS   ~TAB  |Q|W|E|R|T|Y|U|I|O|P|[|]|\~CAPS  |A|S|D|F|G|H|J|K|L|;|'|ENTER~SHIFT   |Z|X|C|V|B|N|M|,|.|/|SHIFT   ".Split('~'))for(int i=0,l;i<4;i++){foreach(var k in r.Split('|')){l=k.Length+1;var u=new string('_',l);s+=i<1?" "+u+"__":i<2?"||"+k.PadRight(l)+"|":i<3?"||"+u+"|":"|/"+u+@"\";}s+=i>0?"|\n":"\n";}Console.Write(s);

这完全基于Klinger的C#答案。我没有足够的代表对他的回答发表评论,否则我会发表评论。

通过修改初始的foreach循环并删除多余的括号,我能够将Klinger的代码缩减5个字节。

var s="";
foreach(var r in@"`|1|2|3|4|5|6|7|8|9|0|-|=|BS   ~TAB  |Q|W|E|R|T|Y|U|I|O|P|[|]|\~CAPS  |A|S|D|F|G|H|J|K|L|;|'|ENTER~SHIFT   |Z|X|C|V|B|N|M|,|.|/|SHIFT   ".Split('~'))
for(int i=0,l;i<4;i++)
{
foreach(var k in r.Split('|'))
{
l=k.Length+1;
var u=new string('_',l);
s+=i<1?" "+u+"__"
:i<2
?"||"+k.PadRight(l)+"|"
:i<3
?"||"+u+"|"
:"|/"+u+@"\";
}
s+=i>0?"|\n":"\n";
}
Console.Write(s);

好一个@Bence Joful。根据您的建议,我可以将其提高到367。我尚未将其纳入当前答案。
Klinger

无法抗拒。您的建议加上一些其他较小的更改使它达到361(或带字符串插值的358)。
Klinger

@Klinger-请使用我的调整!根据您的工作,我受到启发去玩转它。我在过程中学到了一些关于初始化的知识。
Bence Joful

您可以包括一线程序吗?在当前版本中,您不会完全失去可读性
Cyoce

@Cyoce,懂了,谢谢你的建议。尽管此时,Klinger已经发布了包含这些更改的新的较小版本。
Bence Joful

3

m4,456

changequote({,})define(d,{define($@)})d(p,{patsubst($@)})d(a,{{_}p({$1},.,_)_ })d(b,{|$1||})d(c,{|p({$1},.,_)||})d(e,{/p({$1},.,_)\|})d(f,{ifelse(len({$2}),0,,{indir({$1},{$2})f({$1},shift(shift($@)))})})d(g,{ f({a},$@)
|f({b},$@)
|f({c},$@)
|f({e},$@)
})g(` ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0 ,- ,= ,BS    )g(TAB   ,Q ,W ,E ,R ,T ,Y ,U ,I ,O ,P ,[ ,] ,\ )g(CAPS   ,A ,S ,D ,F ,G ,H ,J ,K ,L ,; ,' ,ENTER )g(SHIFT    ,Z ,X ,C ,V ,B ,N ,M ,{,} ,. ,/ ,SHIFT    )

取消高尔夫:

changequote({,})dnl
define(key1, {{_}patsubst({$1}, ., _)_ })dnl _______ 
define(key2, {|$1||})dnl                     |TAB  ||
define(key3, {|patsubst({$1}, ., _)||})dnl   |_____||
define(key4, {/patsubst({$1}, ., _)\|})dnl   /_____\|
define(rkey, {dnl
ifelse(dnl
len({$2}), 0, ,dnl terminate on empty argument
{dnl
indir({$1}, {$2})dnl
rkey({$1}, shift(shift($@)))dnl
}dnl
)dnl
})dnl
define(row, {dnl
 rkey({key1}, $@)
|rkey({key2}, $@)
|rkey({key3}, $@)
|rkey({key4}, $@)dnl
})dnl
row(` ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0 ,- ,= ,BS    )
row(TAB   ,Q ,W ,E ,R ,T ,Y ,U ,I ,O ,P ,[ ,] ,\ )
row(CAPS   ,A ,S ,D ,F ,G ,H ,J ,K ,L ,; ,' ,ENTER )
row(SHIFT    ,Z ,X ,C ,V ,B ,N ,M ,{,} ,. ,/ ,SHIFT    )

(这实际上是我第一次同时进行代码搜索和尝试m4。)


对于第一个答案来说还不错。欢迎光临本站!:)
DJMcMayhem

3

堆叠,228字节

在这里尝试!

[,{a:a size@n(' __' '_'n 1+:@k*LF'||'a' ' '|'LF'||' '_'k*:@o'|'LF'|/'o'\')sum}"!$hcat#/!' |||'hcat out]@:p$chars@:c'`1234567890-='c'BS   'p'TAB  ' 'QWERTYUIOP[]\'c p'CAPS  ' 'ASDFGHJKL;'''c,'ENTER'p'SHIFT   ':@q'ZXCVBNM,./'c,q p

或者,更具可读性:

{a:a size@n(' __' '_'n 1+:@k*LF'||'a' ' '|'LF'||' '_'k*'|'LF'|/' '_'k*'\')sum}"@:m
[,m$hcat#/!' |||'hcat out]@:p
'`1234567890-='chars'BS   'p
'TAB  ' 'QWERTYUIOP[]\'chars p
'CAPS  ' 'ASDFGHJKL;'''chars,'ENTER'p
'SHIFT   ':@q'ZXCVBNM,./'chars,q p

通过定义先生成p一个键的功能,然后再hcat输入多个键来实现。


2

哈斯克尔255

import Data.List;a#b=a++[b];e=" |||";s=map(:" ");k x=[e,"_||/"]++['_':c:"__"|c<-x]#"_||\\";t="SHIFT    ";main=mapM_ putStrLn$transpose.(#e).(k=<<)=<<[s"`1234567890-="#"BS    ","TAB   ":s"QWERTYUIOP[]\\","CAPS   ":s"ASDFGHJKL;'"#"ENTER ",t:s"ZXCVBNM,./"#t]

回顾一下,其概念与此Haskell答案相似,但生产的是ASCII键盘,并且打高尔夫球的方式略有不同。

格式化并重命名:

import Data.List

main :: IO ()
main = mapM_ putStrLn
  $ concatMap (transpose . (`append` end) . concatMap key)
  [ split "`1234567890-=" `append` "BS    "
  , "TAB   " : split "QWERTYUIOP[]\\"
  , "CAPS   " : split "ASDFGHJKL;'" `append` "ENTER "
  , shift : split "ZXCVBNM,./" `append` shift
  ]

key :: String -> [String]
key x
  = [end, "_||/"]
  ++ ['_' : c : "__" | c <- x]
  `append` "_||\\"

append :: [a] -> a -> [a]
append a b = a ++ [b]

split :: [Char] -> [String]
split = map (: " ")

end :: String
end = " |||"

shift :: String
shift = "SHIFT    "

2

tcl,368

http://textmechanic.com/text-tools/basic-text-tools/count-characters-words-lines/所计数,“计数换行符为空格”。设置为on,它占据505 496 452 451 439 403 401 396 391 388 385 384 382 379 378 377 369 368

proc N x {split $x @}
proc M a\ b {string map $a $b}
regsub -all \[^@|] [set b [M [N {||||@|||@$@BS   @%@TAB  @&@CAPS @? @ENTER  @*@SHIFT   }] [regsub -all {[^@]} "`1234567890-=$@%QWERTYUIOP\[\]\\@&ASDFGHJKL;'?@*ZXCVBNM,./*" {||& ||}]]] _ f
lmap x [N [M {\\ _ / _ | \ } [set g [M {||_ |/_ _|| _\\|} [M {||| \\|/} $f]]]]] y [N $b] z [N $f] w [N $g] {puts "$x
$y
$z
$w"}

演示:http//rextester.com/live/NTVAV88033

高尔夫:

http://rextester.com/live/UDO43692上进行实时合作

regsub -all {(\S)} "`1234567890-=←\n%QWERTYUIOP\[\]\\\n⇩ASDFGHJKL;'↵\n⇧ZXCVBNM,./⇧" {||\1 ||} b
set b [string map {|||| |||  ← "BS   " % "TAB  " ⇩ "CAPS  " ↵ "ENTER" ⇧ "SHIFT   "} $b]

regsub -all {[^\n|]} $b _ f

set g [string map {||| \\|/} $f]
set g [string map {||_ |/_  _|| _\\|} $g]
set h [string map {\\ _ / _ | " "} $g]

set H [split $h \n]
set B [split $b \n]
set F [split $f \n]
set G [split $g \n]

lmap x $H y $B z $F w $G {
puts $x
puts $y
puts $z
puts $w
}

任何人都是免费的,欢迎您在实时合作网站上改进我的版本,但是请:不要在此处编辑我的原始答案;只需说您已在评论中进行了编辑,其他人就会访问这些链接。

更新1:替换forforeach,因为后者生成的代码更短

更新2:替换foreachlmap,因为后者生成的代码更短

更新3:剃光了一个字符,因为我替换" "\

更新4:关于第一个注释,我将第一行的所有2字节Unicode占位符更改为1字节ASCII字符。

更新5:将puts行合并为一个

更新6:直接使用split命令在lmap调用时返回值,而不是使用中间列表变量

更新7:ENTER不需要引号

更新8: string map足够长并且重复了很多次,值得将其封装在proc

更新9: split $x \n足够长,并且重复了很多次,值得将其封装在proc

更新10:在“替换”字符串上可以使用&代替\1,因为在这种情况下,两者是重合的。这样做的另一个结果是它可以摆脱()“匹配”字符串。

更新11:使用@而不是\n作为行分隔符,用于进一步在使用split说明书。尽管“ match”字符串从\S到延长,[^@]但由于重复次数的影响,它得到了回报

更新12:替换第一regsub“匹配”的字符串{[^@|]}\[^@|]剃一个字符了。不幸的是,不能对第二个进行相同regsub的操作,因为该指令位于一对[]:(

更新13:剃光了两个Enter字符,方法是将lmap正文集中在自己的标题上。

UPDATE 14:用于将一个呼叫split的基于过程N,而不是直接调用的string map基于过程N,其允许通过3个字符,以缩短

更新15:有一个不需要的空格字符。删除它以剃掉一个字符。

更新16: set h可以嵌入以摆脱$h,剃掉一个字符。

更新17: set h确实可以删除该语句。

更新18: puts参数从...\n...\n...\n...格式更改为

"...
...
...
..." 

格式。

感谢帮助我缩短它的人,尤其是tcl IRC频道的evilotto和方面!


很好的答案,欢迎来到该网站!我对您的帖子进行了较小的修改,以便字节数显示在标题中,希望您不要介意。大家知道,我认为这实际上是469个字节,因为其中一些字符在UTF-8中是多个字节。我对tcl不太了解,它是否使用自定义编码(其中一个字节)?
DJMcMayhem

@DJMcMayhem我不知道它是基于字节数而不是字符数,但是这不是问题,因为仍然是一个字节符号的所有东西都可以被占位,并且我还有很多可用。
sergiol

@DJMcMayhem经过我的编辑后,您报告的非问题消失了!
sergiol

@DJMcMayhem为什么顶部的401的背景有一段时间是黄色的?
sergiol

2

tcl,369

最初基于tcl的sergiol版本。
(请注意,许多左空格是tcl的“自然”的一部分)

lmap z {S R M} w {set "regsub -all" "string map"} {interp alias {} $z {} {*}$w};lmap x {"`1234567890-=¿BS   ¿" "¿TAB  ¿QWERTYUIOP\[\]\\" "¿CAPS  ¿ASDFGHJKL;'¿ENTER¿" "¿SHIFT   ¿ZXCVBNM,./¿SHIFT   ¿"} {S h [M {\\ _ / _ | \ } [S g [M {||_ |/_  _|| _\\|} [M {||| \\|/} [S f [R {[^\n|]} [S b [M {|||| |||} [R {¿(\S+\s*)¿|(.)} $x {||\1\2 ||}]]] _ ]]]]]];puts $h\n$b\n$f\n$g}

@muddyfish编辑并修复。谢谢!
Alejandro Muzzachiodi

如果您直接用替换所有foreach出现的内容,则可以缩短更多时间lmap
sergiol

试图使用您的interp alias方法来缩短我的版本,但这样做时我能得到的最短时间是398 :( rextester.com/live/NTVAV88033
sergiol 2016年

我的最后一次尝试得到了395:lmap z {S R M N} w {set "regsub -all" "string map" split} {interp alias {} $z {} {*}$w};lmap y [N [S b [M [N {||||@|||@$@BS @%@TAB @&@CAPS @? @ENTER @*@SHIFT } @] [R {[^@]} "`1234567890-=$@%QWERTYUIOP\[\]\\@&ASDFGHJKL;'?@*ZXCVBNM,./*" {||& ||}]]] @] z [N [S f [R {[^@|]} $b _]] @] w [N [S g [M {||_ |/_ _|| _\\|} [M {||| \\|/} $f]]] @] x [N [M {\\ _ / _ | \ } $g] @] {puts $x\n$y\n$z\n$w}
sergiol 2016年

如果您删除了不需要的空间(例如上次更新),则可以保存一个字符!
sergiol

2

C(GCC) 378个 342 330字节

-10字节,感谢ceilingcat。

第一次刺中它。重复的g()表明有改进的余地。

编辑:我们去了。

char*k[]={"eZXCVBNM,./e","cASDFGHJKL;'d","bQWERTYUIOP[]\\","`1234567890-=a","BS","TAB","CAPS","ENTER","SHIFT"},*s;f(w,i,j){for(i=4;i--;)for(j=4;j--;puts(""))for(s=k[i];w=*s>96?"FFGFI"[*s-97]-64:2,*s;)printf("%s%s%-*.*s%.2s",L" |"+(s++-k[i]?2:j<3),L"/||"+j,w,j<2?w:j^3?w>2?w:1:w+2,j^2?"___________":w>2?k[*s-93]:s,"\\||||| "+j*2);}

在线尝试!


1

Python 2,672字节

使用压缩的zlib字符串:

print 'x\x9c\xad\xd3\xb9\x0e\x82@\x10\x80\xe1\x9e\xa7\xa0\xb3\xf1\xbe\x8d\xb1\x00\xbc\x0f<\xc0\x1b\xb3>\xc8<\xbc\xfc\x8bf\x8d\xed8\xc5\x17\x9a\xddd\xfe,\xbe\xc9\xc7\xd7b?<\x91\xa7/"\rhB\x0b\xda\xd0\x81.\xf4\xa0\x0f\x03\xa8C\x05F\x10&~>"\xf9]\xc6\x88\x16\x86\xbbj\xc6dZ\x98L<\xb7\xae\x9a|\xc74\x08\xed\xba\xb2\x873L\xe0\x00)\\\xe1\x08\x0b\xd8\xc2\x0e\xee\xf0\x80\xec\xd3\xabXW\x1d\xces\xeb\xaa\xc3\xb9^\x7fy_Q\xb0K\x8a`\x01$0\x86)\xcc`\x0eKX\xc1\x1a\x86P\xb2u\xe3tr\xf8\xee\xf5\xaf\xf7\xa5\x0e\xf6\xfb\xbet\xb1\xde\xbd\x92\xf9b\x9a\x16\x7f\x94\xdc\xe0\x02\x11\x9c\xec\xef\x061l\xa0\x0cU\xa8\xd9\xbc\xee\xb4\xeb\xa5\x8a\xf5\xd3K\x15\xcb\x9e~\x01r\xfc\xb9\xee'.decode('zlib')

2
那是672个字节,而不是232个字节。
nneonneo

进一步说明,我不了解您。@nneonneo
不论

1
如果将代码粘贴到文件中,则该文件的长度为672个字节。您似乎已经计数了len("print 'x\x9c...'")将使unscape \xs的代码,从而导致错误的字节数。通过计数可以得到正确的计数,len(r"print 'x\x9c...'")但是,与往常一样,最简单的解决方案是查看文本编辑器或文件系统的内容。
nneonneo '16

1

Powershell,249242字节

"``1234567890-=Bs   
Tab  QWERTYUIOP[]\
Caps  ASDFGHJKL;'Enter
Shift   ZXCVBNM,./Shift   "-split'
'|%{($u=($r=,''+($_-csplit'(.[a-z ]*)'-ne''|% t*per)+'')-replace'.','_')-join'__ _'
$r-join' |||'
$u-join'_|||'
$u-join'_\|/'}|%{-join$_[2..76]}

松散和解释

中间点·使用空格来澄清源字符串。

"``1234567890-=Bs···
Tab··QWERTYUIOP[]\
Caps··ASDFGHJKL;'Enter
Shift···ZXCVBNM,./Shift···"-split"`n"|%{        # split the string with rows by new line
$r=,''+($_-csplit'(.[a-z ]*)'-ne''|% t*per)+''  # split each row by key labels (any char plus small letters or spaces), 't*per' is shortcut for toUpper method
$u=$r-replace'.','_'                            # replace any char to _ to take an upper 
$u-join'__ _'                                   # join labels and push 4 strings to pipe
$r-join' |||'
$u-join'_|||'
$u-join'_\|/'
}|%{
    -join$_[2..76]                              # return substring for each string
}

# $r =
# ["","`","1","2","3","4","5","6","7","8","9","0","-","=","BS   ",""]
# ["","TAB  ","Q","W","E","R","T","Y","U","I","O","P","[","]","\",""]
# ["","CAPS  ","A","S","D","F","G","H","J","K","L",";","'","ENTER",""]
# ["","SHIFT   ","Z","X","C","V","B","N","M",",",".","/","SHIFT   ",""]
# $u =
# ["","_","_","_","_","_","_","_","_","_","_","_","_","_","_____",""]
# ["","_____","_","_","_","_","_","_","_","_","_","_","_","_","_",""]
# ["","______","_","_","_","_","_","_","_","_","_","_","_","_____",""]
# ["","________","_","_","_","_","_","_","_","_","_","_","________",""]
# before substring:
# __ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________ _
#  |||` |||1 |||2 |||3 |||4 |||5 |||6 |||7 |||8 |||9 |||0 |||- |||= |||BS    |||
# _|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______|||
# _\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|/
# __ ________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ _
#  |||TAB   |||Q |||W |||E |||R |||T |||Y |||U |||I |||O |||P |||[ |||] |||\ |||
# _|||______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||
# _\|/______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/
# __ _________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________ _
#  |||CAPS   |||A |||S |||D |||F |||G |||H |||J |||K |||L |||; |||' |||ENTER |||
# _|||_______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______|||
# _\|/_______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|/
# __ ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________ _
#  |||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    |||
# _|||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________|||
# _\|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|/
# final output:
#  ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________
# ||` |||1 |||2 |||3 |||4 |||5 |||6 |||7 |||8 |||9 |||0 |||- |||= |||BS    ||
# ||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______||
# |/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|
#  ________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
# ||TAB   |||Q |||W |||E |||R |||T |||Y |||U |||I |||O |||P |||[ |||] |||\ ||
# ||______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__||
# |/______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
#  _________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________
# ||CAPS   |||A |||S |||D |||F |||G |||H |||J |||K |||L |||; |||' |||ENTER ||
# ||_______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______||
# |/_______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|
#  ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________
# ||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||SHIFT    ||
# ||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
# |/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|

附加:带空格键和右对齐标签的键盘,278字节

我在正则表达式中添加了两个字节来处理空格键(旧的regexp (.[a-z ]*),新的~|(.[a-z ]*))。对于regexp来说,这只是一小步,对于解决方案而言,这是一个巨大的飞跃:您现在可以显示空格键和与右侧对齐的键标签(请参阅键盘右侧的SHIFT,CTRL和BS)。

"``1234567890-=~   bs
Tab  QWERTYUIOP[]\
Caps  ASDFGHJKL;'Enter
Shift   ZXCVBNM,./~   shift
Ctrl  Alt ~$(' '*34)Alt ~  ctrl"-split'
'|%{($u=($r=,''+($_-csplit'~|(.[a-z ]*)'-ne''|% t*per)+'')-replace'.','_')-join'__ _'
$r-join' |||'
$u-join'_|||'
$u-join'_\|/'}|%{-join$_[2..76]}

输出:

 ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________
||` |||1 |||2 |||3 |||4 |||5 |||6 |||7 |||8 |||9 |||0 |||- |||= |||   BS ||
||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______||
|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|
 ________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
||TAB   |||Q |||W |||E |||R |||T |||Y |||U |||I |||O |||P |||[ |||] |||\ ||
||______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__||
|/______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
 _________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________
||CAPS   |||A |||S |||D |||F |||G |||H |||J |||K |||L |||; |||' |||ENTER ||
||_______|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||______||
|/_______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/______\|
 ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________
||SHIFT    |||Z |||X |||C |||V |||B |||N |||M |||, |||. |||/ |||   SHIFT ||
||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|
 _________ _______ _____________________________________ _______ _________
||CTRL   |||ALT  |||                                   |||ALT  |||  CTRL ||
||_______|||_____|||___________________________________|||_____|||_______||
|/_______\|/_____\|/___________________________________\|/_____\|/_______\|

0

///,360字节

/f/!!//e/SHIFT   //d/\/\///c/ "db/ 
\|\|da/\\\|d@/#####d?/__d>/?\\\\a
c"d</aa
ad:/fffff!d&/ccccd%/ aaad#/?aaa?aaad"/??d!/?\\\\a\\\d&&&cc"b`%1%2%3%4%5%6%7%8%9%0%-%=%BS    <|@#?|||"?<\/:f">&&&cbTAB  %Q%W%E%R%T%Y%U%I%O%P%[%]%\\ <|"@#?|||?<\/":f>_&&&"bCAPS  %A%S%D%F%G%H%J%K%L%;%'%ENTER <|"_@#"?<\/"_:!">?_&&ccc"?_be%Z%X%C%V%B%N%M%,%.%\/%e <|""_|||@""_<\/"?_:""_\a

在线尝试!


0

Mathematica 323字节

Uncompress@"1:eJyt00luwjAUgGE2vUdYsWGeEeoiUGYIEKcTTWXEBXqBd3jy26CUYWe/xads8iT/sounv1gFL4VCoLNxxnyk9UZT5BiISAOa0II2dKALPejDAOpQgVcYqSAbEbtOa3GFuayraZ2mPmWyL5bnIZyxR0/CkQkhe/iECcSQwDe8wwK2sIMf+IV/IW0H56LXkJej+016E9LXlRyHO2VLhqDgDaYwgzksYQVrGELJZI+SSXxX0uOV9Jry2Y10q5iHVPPFNLGvUw7wBWP4ME8XIthAGapQM93zv29COlV8DOkrol10BmvF28U="

无聊又无聊。该字符串只是Compress应用于所需输出的内置命令的输出。


@Downvoted请指出我的程序出了什么问题。
伊恩·米勒

0

Wolfram语言(Mathematica),293字节

c=##&@@(#|2&/@Characters@#)&
r=StringRiffle
p=StringPadRight
Print/@{j=p["",#2,"_"]&@@@#;(" __"<>#&/@j)<>" ",r[p@@@#,i={l="||","|||",l}],j~r~i,j~r~{"|/","\|/","\|"}}&/@{{c@"`1234567890-=","BS"|6},{"TAB"|6,c@"QWERTYUIOP[]\\"},{"CAPS"|7,c@"ASDFGHJKL;'","ENTER"|6},{h="SHIFT"|9,c@"ZXCVBNM,./",h}}

在线尝试!

相对简单:将键行编码为 (key name)|(key width)

c=##&@@(#|2&/@Characters@#)&    (*converts a string into (key)|2 s*)
r=StringRiffle
p=StringPadRight
 Print/@
  {j=p["",#2,"_"]&@@@#;
   (" __"<>#&/@j)<>" ",         (*top of the keys*)
   r[p@@@#,i={l="||","|||",l}], (*key names*)
   j~r~i,                       (*space under key names*)
   j~r~{"|/","\|/","\|"}            (*bottom of the keys*)
  }
 &/@
{
 {c@"`1234567890-=","BS"|6},
 {"TAB"|6,c@"QWERTYUIOP[]\\"},
 {"CAPS"|7,c@"ASDFGHJKL;'","ENTER"|6},
 {h="SHIFT"|9,c@"ZXCVBNM,./",h}
}

0

Perl -MList::Util=pairmap 5,313字节

pairmap{$_=$b;s/\|{3}/|-|/g;y/-/_/c;y/-/ /;s/./ /;chop;say;$_=$b;for$r($a=~/./g){s/\| /|$r/}say;y/|/_/c;say;s,\|_,/_,g;s/_\|/_\\/g;say}"`1234567890-=",($;="||  |")x13 ."||BS    ||","QWERTYUIOP[]\\",'||TAB   |'.$;x13 .'|',"ASDFGHJKL;'","||CAPS   |".$;x11 ."||ENTER ||","ZXCVBNM,./",($s='||SHIFT    |').$;x10 ."$s|"

在线尝试!

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.