# Question
Title: A keyboard so real you can almost TASTE it
... Not that you would, would you? The task is simple, output the following text:

```
 ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ________
||` |||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    ||
||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|

```

This is the keyboard of the future because in the future spaces are irrelevant, so are spacebars.

---

To make things a little bit easier on you:

1. `0123456789ABC...XYZ-=[]\;',./` \- These chars are on keys of length 6 (including padding).
2. `TAB / BS / ENTER` \- These keys are of length 10 (including padding).
3. `CAPS` \- This key is of length 11 (including padding).
4. `SHIFT` \- This key is of length 13 (including padding, on both sides).

---

Each individual key looks more or less like this:

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

```

However, you should make note that two consecutive keys are not:

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

```

But they are "conjoined":

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

```

This challenge shouldn't be too bad, best of luck to you; don't miss out on abusing the repetition! But don't underestimate the "special" keys either ;).

---

# Winning?

Shortest code wins because it's you know.

# Answer
# , ~~189, 179, 175, 164, 161, 157, 155, 149, 145, 141~~, 135 bytes

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

```

Try it online!

*This answer is now tweetable!*

---

Watch it run! This is a slightly modified version that updates as it runs so you can sorta see how it works. This is an outdated version since I haven't gotten around to re-recording it yet, but the general approach is identical.

This is probably the longest V answer ever written. It certainly didn't help that V's interpreter is extremely slow. It took me around an hour to write the first revision, but I've been repeatedly coming back to it to shave a couple bytes off each time. Since the full keyboard is 1215 bytes, currently this answer is 91% shorter than the output, so I'm pretty happy with the results.

Since this contains some unprintable characters, and a lot of gross non-ASCII, here's a hexdump:

```
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

```

## How the heck does it work?

Alright, this explanation is gonna be a doozy. You ready? First off, we need enter the letters so we can build up the keys around them. This is

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

```

Which inserts:

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

```

It enters it pretty straightforward, but there are a few tricks that we use to save characters. For example, `¬19` enters "123456789", `³`  enters three spaces, and we duplicate the shift so that we don't need to enter it multiple times.

Note how the letters are lowercase here. This is so that we can easily distinguish between the uppercase keys like "ENTER" and the single letters. Writing them this way makes it easier to tell which characters to put a bar before, and only adds one byte to convert them to lowercase later. So we do a substitute command to convert these to uppercase, and add one space after each of them:

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

```

Now, we take each key sequence (any run of non-whitespace), and put three bars before and after them:

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

```

At this point, the buffer looks like this:

```
|||` |||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    |||

```

Having three bars on the first and last columns is actually very convenient and ends up saving many bytes in the long run.

And here is where we run one giant loop. This will convert something like this:

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

```

into something like this:

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

```

Everything between two instances of `ò` will run until an error happens, which will happen when we try to go up into a line that does exist yet. Since we just ran a *globally substitute* command, our cursor is on the last line, and we'll transform these working our way up.

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

```

This is the

```
|||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________|||

```

line.

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

```

This is the

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

```

Line.

```
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:
     _ _  "     '_ _'

```

This is the:

```
_ ___________ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___________ _

```

Line.

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

```

Now we have the full keyboard, but each line contains either an extra bar, an extra slash (forward or backward), or an extra underscore. *Super* easy fix

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

```

After all that madness, the buffer is implicitly printed.
> 126 votes

# Answer
# Lua 5.3, ~~416~~ 394 Bytes.

```
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

```

## Ungolfed and with comments.

```
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

```

## 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    ||
||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|

```

I'm going to get destroyed by other langauges, but I thought I'd give this a shot. Nice amount of complexity, and atleast it's shorter than the keyboard!
> 42 votes

# Answer
# Bubblegum, 191 bytes

```
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......|.

```

Try it online!
> 29 votes

# Answer
## Haskell, 263 chars (353 bytes 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(:" ")

```

As there has been a lot of discussion about the score in light of these unicode characters... here's the same program, reduced to all-ASCII:

## Haskell, 263 chars (263 bytes 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(:" ")

```
> 21 votes

# Answer
# PHP, 303 bytes

Lazy but effective. :)

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

```
> 19 votes

# Answer
# Python 3.5+, 239 bytes

```
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))

```
> 19 votes

# Answer
## Batch, ~~465~~ 452 bytes

```
@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

```

The `:c` subroutine handles a line of keys. Keys containing extra spaces need to be quoted, as do the `=`, `;`, `,` keys, possibly due to a bug in the `shift` command. The first and last parameters are strings of `_`s of the same length as the first and last key to aid concatenation. `t` then ends up as the `_`s common to the first, third and fourth rows, with `#`s marking the join, which are replaced appropriately before the leading and trailing characters are added, while `s` is the second row, but with `|`s changed to `!`s as they reduce the number of `"`s that I need. Edit: Saved 1 byte by printing all four lines in a single statement, and 12 bytes by optimising the way I assigned the `s` variable.
> 16 votes

# Answer
# Ruby, 226 bytes

```
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]}

```

Improvements as follows:

1.No empty string elements at the beginning and end of the array. Instead the array is triplicated making 3 side-by side keyboards. After conversion to string we have 3 keyboards with outer edges missing. This is truncated to only display the middle one, complete with edges.

2.Changed version of Ruby. Used Ideone instead of 1.9.3 installed on my machine. This means `.chars.to_a` can be shortened to just `.chars`.

# Ruby, 239 bytes

There's a few more bytes to be golfed out of this. Will look tomorrow.

```
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]}

```

**ungolfed**

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

```
> 14 votes

# Answer
# C#, 357 bytes (when in one line, and incorporating most suggestions)

---

```
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);

```

**Or, 353 with string interpolation and all other suggestions**

```
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);

```

Ungolfed (without string interpolation):

```
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);

```
> 13 votes

# Answer
## PowerShell v2+, 465 bytes

```
($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'#','|||'

```

I'm halfway embarrassed to be posting this answer, given how short the PHP and Python answers are, nevermind the C# answer, but I'm unable to get this method shorter. Other approaches may yield better results.

It's basically just a giant multi-line string, with variables (`$a` and the like) substituting for various substrings, and a couple `-replace`s at the end to finish it out. Script blocks `$(...)` are inserted where necessary to introduce new variables.

Try it online!
> 10 votes

# Answer
**Python, ~~493~~ 458 Bytes.**

```
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)

```

Functionally equivalent but somewhat more readable:

```
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)

```

Unfortunately it's already longer than the answer provided in Lua.
> 7 votes

# Answer
# PHP, ~~316~~ 312 bytes

```
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;

```

I´m pretty sure that this approach cannot be golfed any further. But if anyone finds 10 more bytes ... :D
Run with `-r`.

**breakdown**

```
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
            ;

```
> 7 votes

# Answer
# JavaScript (ES6), 286

An anonymous function with no parameters

```
_=>[..."`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`
`

```

*Less golfed*

```
_=>[..."`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>
```
> 7 votes

# Answer
# Bash (on OSX), ~~12~~ 8 + 221 + 1 = ~~234~~ 230 bytes

Yeah, I know, compression. But it works, no?

```
gunzip<f

```

Requires a file called "f" in the current directory with the following contents (put into base64 for PPCG-friendliness - you can decode this into the file "f" first.):

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

```
> 6 votes

# Answer
# Swift, 777 Bytes

```
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:"")

```

Swift is generally not a great language of choice for golfing, so being less than double the current smallest answer (that was fast) ~~is a good challenge here!~~

Ungolfed:

```
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()

```
> 5 votes

# Answer
# SOGL V0.12, ~~131~~ ~~128~~ 127 bytes (competing?)

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

```

SOGL does have the `2*2/` and `2/2*` quirks, but those feel too much like a built-in for this challenge.
Try it Here!

```
...‘               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

```
> 5 votes

# Answer
# Python 2, ~~394~~ ~~388~~ 380 bytes

```
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)

```

Just builds a big string representing the whole keyboard, replaces * with %s for the special keys then uses string formatting to update the specials.

**Edit**

Now has a trailing newline at the end of the output but I don't see anywhere that's not allowed.

Try it online!
> 4 votes

# Answer
# C#, 376 bytes (when in one line)

---

```
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);

```

This is based entirely on Klinger's C# answer. I don't have enough rep to comment on his answer, otherwise I would.

I was able to slim down Klinger's code by 5 bytes, by modifying the initial foreach loop, and removing extraneous brackets.

```
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);

```
> 3 votes

# Answer
# 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    )

```

Ungolfed:

```
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    )

```

(This is actually the first time I'm both code-golfing and giving m4 a try.)
> 3 votes

# Answer
# stacked, 228 bytes

Try it here!

```
[,{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

```

Or, slightly more readable:

```
{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

```

This works by defining a function `p` that makes a key, then `hcat`ing multiple keys.
> 3 votes

# Answer
# Haskell, 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]

```

In retrospect, similar in concept to this Haskell answer, but producing the ASCII keyboard, and with slightly different golfing.

Formatted and renamed:

```
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 votes

# Answer
# tcl, 368

As counted by http://textmechanic.com/text-tools/basic-text-tools/count-characters-words-lines/ with the "Count line breaks as spaces." set to on, it occupies ~~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"}

```

Demo: http://rextester.com/live/NTVAV88033

The ungolf:

Live cooperation on 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
}

```

Anyone is free and welcome to improve my version on live cooperation sites, but please: do not edit my original answer here; just say you've edited in the comments and people will visit the links.

**UPDATE 1:** Replaced `for` by `foreach`, because latter produces shorter code

**UPDATE 2:** Replaced `foreach` by `lmap`, because latter produces shorter code

**UPDATE 3:** Shaved one char because I Replaced `" "` by `\`

**UPDATE 4:** In respect to first comment, I changed all the 1st line 2 byte Unicode place holder characters to 1 byte ASCII ones

**UPDATE 5:** multiple `puts` line made into only one

**UPDATE 6:** use directly `split` commands return values on the `lmap` call instead of using intermediate list variables

**UPDATE 7:** Quotes around `ENTER` were not needed

**UPDATE 8:** `string map` is long enough and repeated a number of times that it is worth to encapsulate it in a `proc`

**UPDATE 9:** `split $x \n` is long enough and repeated a number of times that it is worth to encapsulate it in a `proc`

**UPDATE 10:** On "replacement" string can use `&` instead of `\1`, because in this case both coincide; another consequence of this is it allows to get rid of `()`on the "matching" string.

**UPDATE 11:** Use `@` instead of `\n`as line separator for further use on `split` instructions. Although the "match" string lengthens from `\S` to `[^@]` it pays off , due to number of repetitions

**UPDATE 12:** Replaced the first `regsub` "match" string `{[^@|]}` by`\[^@|]` to shave one character off. Unfortunately, could not do the same to the second `regsub`, because the instruction is inside a pair of `[]` :(

**UPDATE 13:** Shaved two Enter characters by concentrating the `lmap` body with its own heading.

**UPDATE 14:** Used a call to the `split` based procedure `N` instead of a direct call to the `string map` based procedure `N` which allows to shorten by 3 characters

**UPDATE 15:** There was an unneeded  space character. Removed it to shave one char off.

**UPDATE 16:** `set h` can be embedded to get rid of `$h`, to shave one character off.

**UPDATE 17:** `set h` statement can really be shaved off.

**UPDATE 18:** `puts` argument changed from the `...\n...\n...\n...` format to the

```
"...
...
...
..."

```

format.

Thanks to people that helped me to shorten it, especially evilotto and aspect of the tcl IRC channel!
> 2 votes

# Answer
## tcl, 369

Initially based in tcl's sergiol version.
(Note that many left spaces are part of tcl's "nature")

```
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}

```
> 2 votes

# Answer
# C (gcc), ~~378~~ ~~342~~ ~~330~~ 327 bytes

-10 -3 bytes thanks to ceilingcat.

A first stab at it. The repeated g()'s suggests room for improvement.

Edit: There we go.

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

```

Try it online!
> 2 votes

# Answer
# Python 2, 672 bytes

Using a compressed zlib string:

```
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')

```
> 1 votes

# Answer
## Mathematica 323 bytes

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

```

Boring and uncreative. The string is just the output of the built-in `Compress` command applied to the desired output.
> 1 votes

# Answer
# Powershell, ~~249~~ 242 bytes

```
"``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]}

```

## Ungolfed & Explained

The middot `·` uses instead spaces to to clarify the source string.

```
"``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    ||
# ||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
# |/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|

```

---

## Extra: keyboard with a space bar & right aligned labels, 278 bytes

I've added a couple of bytes to the regular expression to handle the space bar (old regexp `(.[a-z ]*)`, new one `~|(.[a-z ]*)`). That's one small step for the regexp, one giant leap for the solution: you can now display space bar and key labels aligned to the right (see SHIFT, CTRL and BS on the right side of the keyboard).

```
"``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]}

```

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 ||
||_________|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_________||
|/_________\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_________\|
 _________ _______ _____________________________________ _______ _________
||CTRL   |||ALT  |||                                   |||ALT  |||  CTRL ||
||_______|||_____|||___________________________________|||_____|||_______||
|/_______\|/_____\|/___________________________________\|/_____\|/_______\|

```
> 1 votes

# Answer
# ///, 360 bytes

```
/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

```

Try it online!
> 0 votes

# Answer
# Wolfram Language (Mathematica), 293 bytes

```
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}}

```

Try it online!

Relatively straightforward: encodes rows of keys as lists of `*(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 votes

# Answer
# Perl 5 `-MList::Util=pairmap`, 313 bytes

```
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|"

```

Try it online!
> 0 votes

# Answer
# Duocentehexaquinquagesimal, 3036 bytes

```
2Ôδuδÿôtõ¡¼Θ%ËÅтƶ¬HMdÆawçùSÂvíÓ'θg/["»Åø≠]nj‘®‘M9~¾ÉQüÝ–*9ζž«Â,LIû–Δ#]¹Ð1…Ñº.β`¯‚…àñY!∞·ŽÉ%(˜‰«xη²‘0ÂγXd.©ÅsÉ÷^oM-â®ι1Nà;´¨©ĆāócÒ₄§βV³ƒÈ¯¾“›'Û$€`þeƒi÷тßäºиRèÞÆÈ½εîÀŠ\sÅtó"eíi∞Ëζ₄ÙÌÕ_T¸¨ÈcyÏa#3->*Ý#üWë€›xÜàεqqFн;ā/Ñ‡"›¡¯¨]1ê²Ú`4ÜFzSÖ'∊/¼C‰ÞÙ†m’I¿¸{"в]иùиå;ßf@qZÖÐAΓ¸(ÙŒ‹Lãßk₁мΩè¾˜∞›ÑVãh¾;œвM[Ò¾æo‰ØΘ≠º©8|Ω1ε₁ǝΓθBƶb·hI¢¤¬ƒ‚-¶{∍α³h¯rāp¯†\ε ðþMŽU0ì₁‰4ýpW0zΩðàöŠ«ÍÏúиÿ,¸āIôê©Bn×DÖr¹‡ZSèΘ½Òì©Éƒ…åÔнlù¸ð£ùd₁Žζº©ûq’|q£pØÕ]Ë"ê74Wáƶε¥¬²Ú¬Σ8ì-‹иI˜¹U±+2eδòwεN+’{ćžz]LF—çÝ«—à!}„@uÆŒòβ3A|à2ΣÚªǝö-®θ¾ºнÞJ¦āò2Ćη"¨₅¡™ʒΛ!¬ºEî¦ú¼œG‰7NšŒ|∊–o Òθ“7{sÀÿ≠üTÂ\B7™YXÔµ0g9þs-+6»βˆÛç₁[γãqª ór¸1ʒi¿¡|Ê¨γ>ÉhβεX’“)ÁÿEŠaÅb?b6?ª˜oÝk™iŒmúÞðΓćq3ê-ƒÅáHA‰βĆjC’ê÷á
¼₅sqŒ¢œYnà₁<X/£NÀ0
—3âô&-â˜›`ÑC¡8ˆQêв˜äeØæé^δ2çªÕšât₆ʒÈ0á8®LaE₆ûAH6”§hΩqzã§1!î+hé¨ËΛú$₂ž‡Ð[1ÄDÅ©ε,8êβ₅Õ=ëgo∞vƒkü¤Dà^ßˆšjAøÚ3y₄αÔλà,üœ÷Ü”J8*òõÉi«‹‚Gè½/ǝ»/ÔÏm™Šfα…0Íþ®¶ιh–:öŒΘÙ₃ÇÌä1ÀðΣøƵH}º‹Θв´ʒ8ÎĀ>¨ÑŒÉ–¯hÌóOjB½ǝ…mĀ+àæ©ˆh;¼ƒΛʒìFá®3°é°-¯BÓ†Ç;ÎÛÜ(õ§°ζλ%{₁º]p₂ãý₅Ì#γIkÊößKšŒ%òÕÿ}₁p Såíóì<tç›æÍγ₃¶éûÂgÍV…eм”àúδ∍н;нä.“0nAx1yñ_=N6,∊‘\f²3[0¦₄,ù“h¯—ÂˆÅGŒ©ŽðZAαÙ·¾d¾À¿.c{šθ¿þ^ƵL‚àÜλÜá¹¤ºнžQâˆÀZÿƶ^ÿ»Δ¶1ùñgôǝ‘ĆŒт<=‚2ΩÄ™2-∍øuœ.yʒ®Û©]©6Uт€2™ε9₃≠ÞÖ‡¾Ï›Tλçá¿Ä¾ˆÜ∊QλGÆ^¦∊ÁåʒÍ³₅i{Õ₅#Î>hεX:₁₅ćy)‰?Á₃ˆêW-Ï²št‚îVÖвç±’1ËδgŽΣ}™¼‡þ‚÷üéʒË¿a™
™}&…Γ¿ÞÎη{₆sǝê?¤ÃçYŒõ¹ θÇ±øÕuóP}ÝùΓJ^êsZ>Aθ^&ƒ€¹4∞Ã@Y:Ë©-Ð≠¯AY>{W©”vEδ¡)Ć`(šð¦fиlGè₆ËÍ›Ω)Ë%šŠÂ¸м$Ü{·Á€‹¿p˜}₆\₃…"þYôµ&ü7нŠθþ¢¿Mµ*î<ƶмíë°!A§HAÊΓ6ĆÈê¡áÒ¶z%Î~ΛλCGðƶç®«þdGó<áKÇγQ‘V₅‡Ω>7m²àNCÁešØ“ï´žhÂÞºK5cX”ÛÛß×çÄÍÒx8¤›ã_Λõиâ8]µāÝн`rmbιoyøΩÈÏlÐâĀ„žÂäƶ₁δJËè?αò2à₃‘QtƵ$ËÿøΓ›C∞;xÔŸæ-<òÜz-{XüŸ'\D$Š'
N³S∞zƒ1õÅ›èǝVXzÀ₄LÄàJŒþ²ëB½5÷вékΓrª´^vαι7ít5т—ßŸ3¥ï*2õāǝLÀ+<¸Ω\ǝ$θõ∍º4¥ëqтTbœÑ[ǝδ§ζ^ Äиéù;zĆ^l≠]fgGā’¤QÔγÚ»Bÿ‹jçÅº₆þÆ'ε!ôšAñāžWÔm>Œ¤‹βÖ5óŸιûãΣη~¢ãêù…J4‡üвúw\^θm₂5,εƒ#ìŠCεiØA∍óåQôø'+ΓnBÔasGÏãâcLb1¹‰Ñ³™ΔŽscâ_‘÷ºΓ_™4~$ÀZ€Þñ$ƒ¾°}©ùœ1ΘÌD>8Λö”ƶ†_QØŠ¤ƶæf¡ïŽMË›-™‰FŠàç„ì:eηÇ4ŸLÿ›qÄ.-&@¹ʒβÃËāO™EÌ¤Ø~{öË‚∊¢₃т‚Î+Ïú#þgíŒn—¸±тþKŠyàöòêvn*ªвβWþM*ĀćÝ1V¸₆Rl÷qª"×—ÆƵ×₂’–∊åÑÌΩ#À¿!ø¿ƶÖÝ´÷/¦ε₃õ=¶³^нŸт₂&,θ—¡ǝ›ÅpgµjKx.c£λá=yΩaõSÒ[ΘÅ)®…CàŸË&C4é;Γ5ÚεyÈœîì₄K₄Ú&œÍ}Ωuò£δËÍγ₂m#{õ½Öç&ò∍Ó8£3¨7x8Ć®v½%x±×d>gÑ®¼м{EyÆP´ûM)λX½dàÉλVsÖq¡y¹·JG₆*≠[Ø¶^åŸ¤€K₅Ãa¶L‚Θ[Bć\Ïвǝw3'“R{₃\Eв‘1M°e`мjXÔfó)¢ïkθλ—ÉíÉo|½$₁p&™SÓδÏŸ*òaI.G¯1h2ŒB#hÐα±ÔWmм‹Ü¯@0g»íÀ²YÉ»ç9#ƒš,ÏÓjZ>Dé∍óFì™ηÙ0ØÕSαLíÍù†w,Γº¡t¾ ¥ŒCƶ‰B₄´×0*ŽΩ¡8т€úâóŽ› ‡Yćyηe“–š∊y$α]Yà7·Ñ?.Xh÷±F$8éCçÕ{ÔΘñˆÃÆ)…íú—(Ñ4àîÛ³Ì"âαÐå≠™V‹{àéC9н\fgδÝƵþ <W∊!|Ñć0Óc80¨Θ¿«_.ø†x D‰$ÑùmÆEÕΣ†.1Þ¥]м @›´áóÛ4ζ∊:1@>BTB)ˆß,„ÜkÌ¨c‹4xê*∍Òγ„¾eø9w#¹ÁF·³zê¡5¦è¬H]‚LÙvÔxbr ¤ôghÐr÷ǝ₁Ÿo#Nθ·Ù‹δ¸ÔØè«Âζ´ 2DVʒbÁï∊ƶdŽ.TΘ[¿pÂk¾ç¦¨Î>ä³hF-¤íŒe“½jG‚\8Øλεн∍èÝmºj²©ë¬àê[@9aˆÓôMêuMт∊yH'Ƶå∊F¼Ê„ÚoγË¢k—EÝUŠG´ʒÁìÀ–-Ýäƶ
β³ζмZìòÊ4´JM3«.ÕCÇõ©îÊŒ³ïO·ÕdÎ†„dδ"~˜¶€Æ†*ÿµ~†ζZÁ¼n₃ĆĆe5J÷;ò¹ô¡ìÂgΣYÞ»…=LÏxM—û'‘Aā£Iε®l¢¯ðcºí3‚iªs,HN’MY½’ƶ₂ŠcÍ¸kþã9–ý)˜ŸÌ¤z)ß∞3œH‘š₆ðEQâ_h¦0ºΔyćм5¡‘L5Ü„|
\]«Ú±"C¾èтÚт<;5D)/ÕðýćÊÙÔζÓ\Çq+“QP={ÊÒLÂиæïÚ₅¥£s½´\¡+ΩΘt†‹ε¿÷Ú[˜ìµβ.]в}Y_zÚ¢#?ïyS™úºb—Δ9Q<u7₅∞ùº’ý™.>àfMÃoY#‰ºƶ¢ΣÐ¶»øÓüć®>мKV>«©λÜĆ›%в’¦lËeÃ>Xãιβ.öāDŠ!°xëÆδ\α≠Ä«
ýÒªƶи®2Iê!9Ûš4N³f!vεв0 kÑ”λƶÇy}ß¹λ©b¨₅tóć¿Òθ3/Zsd∍∍{γ¯þýO±t!²ΘuÀ™û˜Θ¸Ç‹ζfý8G[2ΘÚ¦5ÌŒ_тWŠûΘ`'Ô∊™á!o‘в+±øαíζb<мû3p/Ô}N<‚ƵΔ%Lýmºçêη;äsÞs&€y©°x~KŸƒиß₃·<ǝθнÖγΣвX©(ΓÀý¨ιú{αΣт‚¾hY´=†×¾ÚNΛÈâò¸+s)(ǝæúnW₅ʒôk!ǝïœá—ÍíæΣÅ7£ηxjÑÖœyÒE°¬JÌs¼ˆíÝÁA{Pi†áÖ₂₅´Æe†,·õ[FK'u§<₃MŸï·ÙÞ<ê0+($qΘxZ!â„ô+8á₆2_ʒöyîÒµÀ₂₁Zl¶…ǝ¤â$¤»"Hd’

```

Try it online! Absolutely horrendous and enormous. But hey, it's a challenge out of the way.
> 0 votes

# Answer
# 05AB1E, 133 bytes

```
‘`¯¤¼Á®‹‘#žVžhÀš"-=
 []\ ;'
 ,./
"#)øεεD.u≠iS]ε˜ε¶‘»²®‹ ‡Á‘#¾è:©4U1V.ui•Aε/•¾èÌU•6©›•¾èV¼}'_X×ðì®ðY×«D„||ìĆDŠŠ'_XÍ×:D'/1ǝ¨'\«)}øJεĆu,

```

Try it online.

**Explanation:**

Step 1: Push the nested list of keyboard keys:

```
‘`¯¤¼Á®‹‘     # Push dictionary string "` TAB CAPS SHIFT"
         #    # Split it on spaces: ["`","TAB","CAPS","SHIFT"]
žV            # Push builtin ["qwertyuiop","asdfghjkl","zxcvbnm"]
  žh          # Push builtin "0123456789"
    À         # Rotate it once to "1234567890"
     š        # Prepend it to the keyboard list
"-=\n []\ ;'\n ,./\n"
              # Push this string
 #            # Split it on spaces as well: ["-=\n", "[]\", ";'\n", ",./\n"]
)             # Wrap everything on the stack into a list
 ø            # Zip/transpose; swapping rows/columns: [["`","1234567890","-=\n"],
              #  ["TAB","qwertyuiop","[]\"],["CAPS","asdfghjkl",";'\n"],["SHIFT",
              #  "zxcvbnm",",./\n"]]
εε            # Nested map over each inner string:
  D           #   Duplicate the current string
   .u≠i       #   Pop the copy, and if it's NOT an uppercase string:
       S      #    Convert it to a list of characters
]             # Close the if-statement and nested maps
ε             # Map over each inner list:
 ˜            #  Flatten it to a list of strings
  ε           #  Map over each inner string:
   ¶          #   Push a newline character "\n"
    ‘»²®‹ ‡Á‘ #   Push dictionary string "BS SHIFT  ENTER"
     #        #   Split it on spaces: ["BS","SHIFT","","ENTER"]
      ¾è      #   0-based modular index counter variable `¾` into it
        :     #   Replace the potential newline with this indexed string

```

Try just step 1 online.

Step 2: Convert it to the ASCII keyboard and output it:

```
   ©          #   Store this new string in variable `®` (without popping)
   4U         #   (Re)set variable `X` to 4
   1V         #   (Re)set variable `Y` to 1
   .ui        #   Pop, and if string `®` is uppercase:
      •Aε/•   #    Push compressed integer 667699
       ¾è     #    Index counter variable `¾` into it
         Ì    #    Increase it by 2
          U   #    Overwrite variable `X` with this
      •6©›•   #    Push compressed integer 433144
       ¾è     #    Index counter variable `¾` into it
         V    #    Overwrite variable `Y` with this
      ¼       #    Increase the counter variable `¾` by 1
     }        #   Close the if-statement
   '_X×      '#   Push a string of `X` amount of "_"
       ðì     #   And prepend a space " "
   ®          #   Push string `®`
    ðY×«      #   Append `Y` amount of spaces
        D     #   Duplicate this "®<spaces>" string
        „||ì  #   Prepend "||" to this copy
            Ć #   Enclose it; append its own first character "|"
   D          #   Duplicate this "||®<spaces>|" string
    ŠŠ        #   Triple-swap twice, so the duplicated "®<spaces>" is at the top
      '_XÍ×  '#   Push a string with `X-2` amount of "_"
           :  #   Replace the "®<spaces>" with this "_"-string in the "||®<spaces>|"
              #   copy
   D          #   Duplicate this "||_{X-2}|" string
    '/1ǝ     '#   Insert an "/" at 0-based index 1
        ¨'\« '#   Remove the last character "|", and append "\" instead
   )          #   Wrap all four strings into a list
  }           #  Close the inner map
   ø          #  Zip/transpose; swapping rows/columns
    J         #  Join each inner list together to a single string
     ε        #  Map over each string:
      Ć       #   Enclose; append its own first character "|"
       u      #   Convert any lowercase (keyboard) letters to uppercase
        ,     #   Pop and output this string with trailing newline

```

See this 05AB1E tip of mine (sections *How to use the dictionary?* and *How to compress large integers?*) to understand why `‘`¯¤¼Á®‹‘` is `"` TAB CAPS SHIFT"`; `‘»²®‹ ‡Á‘` is `"BS SHIFT ENTER"`; `•Aε/•` is `667699`; and `•6©›•` is `433144`.
> 0 votes

---
Tags: code-golf, ascii-art, kolmogorov-complexity
---


# Question
Title: Sum of the sum of all possible subsets raised to power k
You are given an array A of non-negative integers. You can pick any non-empty subset, S from the array A. The score of a subset S is the sum of the elements in S raised to the power of K, i.e. for a subset S={s1,s2,…,sm}, the score of S is (s1+s2+…,sm)K. Output the sum of scores over all possible non-empty subsets of A modulo 998244353.

**Input**

The first line consists of two integers N (1 ≤ N ≤ 1000) and K (1 ≤ K ≤ 300), Then N integers follow: a1,a2…,an (1 ≤ ai ≤ 109)

**Examples**

Input:

```
3 2
1 2 4

```

Output:

```
140

```

**Note**

There are 7 possible non empty subsets:

{1}, 12=1

{2}, 22=4

{4}, 42=16

{1,2}, 32=9

{1,4}, 52=25

{2,4}, 62=36

{1,2,4}, 72=49

The total of all of them is 140.

**Test Case 1**

Input:

```
200 33
586675996 834662638 582661564 801031252 368588510 481535057 299143636 154810868 748560222 444723881 594265644 271475209 483236369 825333010 838212251 941340273 181680951 475018532 725610690 980879808 290253341 255300094 222425864 305836905 309362719 673795903 526752784 272885696 498600892 541576513 293569958 586502788 546400101 932614930 922795145 738713347 627678736 854811027 599387102 172776156 368969197 453280296 317871960 878976720 860453033 510602497 926525753 419146537 830612914 980672268 468005306 166335891 911567226 922140110 434524807 424093053 590300567 371183659 721172742 600311592 210722614 317227418 793158971 401617057 449556863 501677314 892013630 839176022 524835881 940550248 839561467 764011513 989141930 192333644 484181005 785400847 674841029 209630134 964257438 941649848 836682055 640053044 493288668 662886952 142491554 659229917 884165257 346190427 135295371 636702497 710634145 170177475 893751212 553144583 498928648 173846992 274295496 676101828 165556726 499077801 920844845 446218268 371964528 518465222 701401156 687218925 309703289 579304688 823881043 802733954 252512484 579282959 844367812 695500833 748122407 825455122 386300070 502934300 179547526 934792800 783118124 441360402 356559179 327130654 998543269 475814368 713846691 788491645 617178564 384577123 166216557 684039923 651593797 821711021 704057885 243187642 943485338 885996539 369725079 504573341 230128629 304769483 940749404 725863600 460266942 378887332 700635348 115095533 583723838 352744521 560578526 984014856 678045467 988770077 470484548 380200831 349213692 849092703 695155761 125390576 970541165 842717904 202532794 848261409 892205344 324076314 401291603 958139378 960397596 669808951 333662236 895479878 866907097 938228867 851281251 333564143 552098658 371049021 356458887 441896629 907071903 336678292 857795316 302950189 898249304 663033041 993067004 494024812 140930107 733086617 107029928 909953444 616400129 799844902 322302802 644050662 253833551 636316553 633766994 300303396

```

**Scoring**

The goal for this challenge is the produce the fastest algorithm (i.e, the algorithm with the smallest asymptotic complexity), and as such you should include an short analysis of your algorithm alongside your code.

# Answer
> 9 votes
# Python, \\$\mathcal O(NK^2)\\$

```
from math import comb
from functools import lru_cache

M = 998244353

rec=lru_cache(None)(
lambda n,a,*A:(pow(a,n,M)+(len(A)and rec(n,*A)+sum(rec(n-j,*A)*pow(a,j,M)*comb(n,j)for j in range(n+1))))%M)

```

Attempt This Online!

\\$\mathcal O(NK^2)\\$ (length of list times exponent squared) assuming that binomial coefficients and powers are O(1) (which is not true for general random access but can be achieved when the values to compute are nearby because then one can be computed from a neighbouring cheaply, cf. comment by @Bubbler. To be clear, I did *not* implement this optimisation because I didn't find it worth the clutter.) and the overhead of memoisation is negligible.

Does the large testcase in a second or so.

Additional testcases taken from @bsoelch.

### How?

Let \\$f(K,S)\\$ denote the desired quantity for exponent K and set (or multiset) S. I write \\$2^S\\$ for the power set. The recursion formula is obtained by choosing an element \\$a\in S\\$ and separating the subsets into those that contain \\$a\\$ and those that do not.

$$f(K,S) = \sum\_{C \in 2^S}\left(\sum\_{x \in C}x\right)^K = \sum\_{C \in 2^{S-\\{a\\}}}\left(\sum\_{x \in C}x\right)^K + \sum\_{C \in 2^{S-\\{a\\}}}\left(a+\sum\_{x \in C} x\right)^K \\ = f(K,S-\\{a\\}) + \sum\_{C \in 2^{S-\\{a\\}}}\left(a+\sum\_{x \in C} x\right)^K \\ = f(K,S-\\{a\\}) + \sum\_{C \in 2^{S-\\{a\\}}}\sum\_{j=0}^K \begin{pmatrix} K\\j \end{pmatrix}a^j \left(\sum\_{x \in C} x\right)^{K-j} \\ = f(K,S-\\{a\\}) + \sum\_{j=0}^K \begin{pmatrix} K\\j \end{pmatrix}a^j \sum\_{C \in 2^{S-\\{a\\}}} \left(\sum\_{x \in C} x\right)^{K-j} \\ =f (K,S-\\{a\\}) + \sum\_{j=0}^K \begin{pmatrix} K\\j \end{pmatrix}a^j f(K-j,S-\\{a\\}) $$

# Answer
> 8 votes
# Python, \\$O(N K \log K)\\$

```
from functools import lru_cache
from sympy.discrete.convolutions import convolution_ntt

MOD = 998244353

@lru_cache(maxsize=None)
def factorial(n):
    return n * factorial(n - 1) % MOD if n else 1

@lru_cache(maxsize=None)
def inverse_factorial(n):
    return pow(factorial(n), -1, MOD)

def r(A, K):
    if len(A) == 0:
        return [1] + [0] * K
    p1 = r(A[1:], K)
    p2 = [pow(A[0], i, MOD) * inverse_factorial(i) % MOD for i in range(K + 1)]
    p = convolution_ntt(p1, p2, MOD)[:K + 1]
    rv = [(a + b) % MOD for a, b in zip(p1, p)]
    return rv

def f(A, K):
    return r(A, K)[-1] * factorial(K) % MOD

```

Attempt This Online!

Continuing from @loopy walt's recursion, we have $$f(K, S) = f(K, S - \\{a\\}) + \sum\_{j=0}^K {k! \frac{a^j}{j!} \frac{f(K-j, S-\\{a\\})}{(K-j)!}} $$ so we look at the EGF \\$f(S) = \sum\_{k=0}^{\infty} {f(k, S) \frac{x^k}{k!}}\\$ and we have \\$f(S) = (1 + e^{a x}) f(S - \\{a\\})\\$, so we evaluate this using NTT, cutting off the terms greater than \\$x^K\\$. We do \\$N\\$ convolutions on arrays of length \\$K\\$, so the time complexity is \\$O(N K \log K)\\$.

# Answer
> 3 votes
# Python, 428 bytes, \\$O(m^{k+1})\\$

*Ignores the input format requirements, `f` takes input `(l,k)` with `l` being the array and `k` being the power.
If it is really necessary I can add a parsing function (see 1), to the code, but this will not impact the total complexity and make it harder to check multiple cases at once*

```
from itertools import product
from math import comb

M=998244353

def prod(l): ## product over the list l
  P=1
  for x in l:
   P*=x
   if M:
     P%=M  ## only need result modulo M, so take mod M to make numbers smaller
  return P

def f(l,k):
  n=len(l)
  S=0
  for P in product(range(n),repeat=k):
   S+=prod(l[i] for i in P)*pow(2,(n-len(set(P))),M)
   if M:
     S%=M  ## only need result modulo M, so take mod M to make numbers smaller
  return S

```

Attempt This Online! (runs for ~30 seconds)

## Explanation

Idea: using the generalized binomial formula split the term for each subset into summands and count how often each combination of elements appears in the final sum.

Example:

```
{x,y,z}, 2 ->
0
x       -> x²
  y     ->    y²
x,y     -> x² y²    2xy
    z   ->       z²
x,  z   -> x²    z²     2xz
  y,z   ->    y² z²         2yz
x,y,z   -> x² y² z² 2xy 2xz 2yz

```

Each term appears (counting different orderings multiple times) \\$2^{len(l)-|\\{\text{different elements in term}\\}|}\\$ times (the number of subsets a term appears in halves with each unique letter used in the term). So we can get the total sum by summing up the term multiplied by their frequencies.

## Running time

Let \\$m\\$ be the length of the list and \\$k\\$ be the exponent. The program checks \\$O(m^{k})\\$ different terms, for each of terms the computation can be done in \\$O(m)\\$ elementary calculations. As each elementary computation modulo `998244353` can be done in \\$O(1)\\$ this gives a total running time of \\$O(m^{k+1})\\$

Combining all terms using the same elements and multiplying by the number of permutations would not reduce the running time as there are still \\${m \choose k} \in O(m^k)\\$ different terms

---

1parsing function:

```
def parse():
  _,k=[*map(int,input().split())]
  l=[*map(int,input().split())]
  return l,k

```

Attempt This Online!

# Answer
> 1 votes
# Rust, \\$\mathcal{O}(NK^2)\\$

A port of @loopy walt's Python answer in Rust.

---

### `src/main.rs`

```
use cached::proc_macro::cached;
use num::integer::binomial;
// use num::pow::pow;

const M: i64 = 998244353;

fn pow_mod(base: i64, exp: usize, m: i64) -> i64 {
    let mut result = 1;
    let mut base = base % m;
    let mut exp = exp;

    while exp > 0 {
        if exp % 2 == 1 {
            result = (result * base) % m;
        }
        exp >>= 1;
        base = (base * base) % m;
    }
    (result+m)%m
}

#[cached]
fn rec(n: u32, a: Vec<i64>) -> i64 {
    if a.is_empty() {
        return 0;
    }
    let mut result: i64 = pow_mod(a[0], n as usize, M);
    if a.len() > 1 {
        let mut rest = a.clone();
        rest.remove(0);
        result = ( result+ rec(n, rest))%M;
        for j in 0..=n {
            let mut rest_j = a.clone();
            rest_j.remove(0);
            result = (result + (rec(n - j, rest_j) * pow_mod(a[0] as i64, j as usize, M)%M * binomial(n, j) as i64 %M))%M;
        }
    }
    (result + M)% M
}

fn main() {
    println!("{}", rec(2, vec![1, 2, 4]));
    println!("{}", rec(2, vec![1, 2, 3]));
    println!("{}", rec(3, vec![1, 2, 3, 4]));
    println!("{}", rec(9, vec![3, 1, 4, 1, 5]));
    println!("{}", rec(33, vec![586675996,834662638,582661564,801031252,368588510,481535057,299143636,154810868,748560222,444723881,594265644,271475209,483236369,825333010,838212251,941340273,181680951,475018532,725610690,980879808,290253341,255300094,222425864,305836905,309362719,673795903,526752784,272885696,498600892,541576513,293569958,586502788,546400101,932614930,922795145,738713347,627678736,854811027,599387102,172776156,368969197,453280296,317871960,878976720,860453033,510602497,926525753,419146537,830612914,980672268,468005306,166335891,911567226,922140110,434524807,424093053,590300567,371183659,721172742,600311592,210722614,317227418,793158971,401617057,449556863,501677314,892013630,839176022,524835881,940550248,839561467,764011513,989141930,192333644,484181005,785400847,674841029,209630134,964257438,941649848,836682055,640053044,493288668,662886952,142491554,659229917,884165257,346190427,135295371,636702497,710634145,170177475,893751212,553144583,498928648,173846992,274295496,676101828,165556726,499077801,920844845,446218268,371964528,518465222,701401156,687218925,309703289,579304688,823881043,802733954,252512484,579282959,844367812,695500833,748122407,825455122,386300070,502934300,179547526,934792800,783118124,441360402,356559179,327130654,998543269,475814368,713846691,788491645,617178564,384577123,166216557,684039923,651593797,821711021,704057885,243187642,943485338,885996539,369725079,504573341,230128629,304769483,940749404,725863600,460266942,378887332,700635348,115095533,583723838,352744521,560578526,984014856,678045467,988770077,470484548,380200831,349213692,849092703,695155761,125390576,970541165,842717904,202532794,848261409,892205344,324076314,401291603,958139378,960397596,669808951,333662236,895479878,866907097,938228867,851281251,333564143,552098658,371049021,356458887,441896629,907071903,336678292,857795316,302950189,898249304,663033041,993067004,494024812,140930107,733086617,107029928,909953444,616400129,799844902,322302802,644050662,253833551,636316553,633766994,300303396]));
}

```

### `Cargo.toml`

```
[package]
name = "rust_hello"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cached = "0.26.2"
num = "0.4.0"

[profile.release]
lto = "y"
panic = "abort"
rand = "0.8.0"

```

### Build and run

```
$ cargo build --release
$ cargo run --release
140
100
3800
554473082
856382558

```

---
Tags: fastest-algorithm
---


title: Sine using square root

text:
# Question
Title: Sine using square root
Given input \\$x \in \left\\{0,3,6,...,90\right\\}\\$, output \\$\sin\left(x°\right)\\$ using integer and \\$+ - \times \div ( ) \sqrt{\cdot}\\$(square root), e.g. \\$\sin(45°)=\sqrt{1\div 2}\\$.

Flexible output format. You needn't do any simplification to output, aka. it's fine to output \\$\sin(0°)=\sqrt{42}-\sqrt{6\sqrt{-9+58}}\\$. Complex intermediate value is fine but please mention.

Shortest code wins.

# Answer
# Python, 89 bytes

```
c='s-1*'
y='/s+2/s++7s5s*6+5s522'
f=lambda d:d and'+*'+y+(x:=f(d-3))+'*'+c+x*2+c+y*2or'0'

```

Attempt This Online!

It times out when trying to run it in ATO when trying to run it for large degrees, but it should work in theory. It outputs in prefix notation, where `s` is the unary square root operator; all other operators are binary. Furthermore, in this notation, there are only single digits (e.g. `20` represents a `2` then a `0`).

It works by repeatedly applying the formula $$ \sin(a+3^{\circ}) = \sin(a) \cos(3^{\circ}) + \cos(a) \sin(3^{\circ}) \\ = \sin(a) \cos(3^{\circ}) + \sqrt{1-\sin(a)\sin(a)} \sqrt{1-\cos(3^{\circ})\cos(3^{\circ})}$$

where \\$\cos(3^\circ) = \sin(87^\circ)\\$ equals $$\frac12 \sqrt{2+\frac12 \sqrt{7+\sqrt{5}+\sqrt{6(5+\sqrt{5})}}}$$

(according to Wolfram-Alpha).
> 15 votes

# Answer
# Python 3, 75 bytes

```
lambda x:f"(1-1{(s:=x//3*'*(1+S(5)+S(S(20)-10))/(S(12)+S(-4))')})/S(-4{s})"

```

Try it online!

This produces an expression with complex numbers as intermediates that can be evaluated in Python with `S=cmath.sqrt`. For instance, `x=3` gives:

```
(1*S(1+S(5)+S(2*S(5)-10))/S(S(12)+S(-4))-1/(1*S(1+S(5)+S(2*S(5)-10))/S(S(12)+S(-4))))/S(-4)

```

The main idea is to work with complex numbers, in particular roots of unity. Since \\$e^{i \theta}\ = \cos(\theta) + i\sin(\theta)\\$ where \\$i = \sqrt{-1}\\$, we can work with multiples of \\$\theta\\$ as

$$\ \cos(k\theta) + i\sin(k\theta)= e^{i k\theta}\ = \left(e^{i \theta}\right)^k = \left( \cos(\theta) + i\sin(\theta)\right)^k$$

From there, we can extract just the sine with:

$$\sin(k \theta) = \frac{\left(e^{i \theta}\right)^k-1/\left(e^{i \theta}\right)^k}{2i}$$

We can take the \\$k\\$ power by multiplying \\$k\\$ times, that is concatenating \\$k\\$ copies of `*stuff` in the expression, since the challenge doesn't allow exponents in the formula.

So we express \\$e^{i \theta}\\$ for \\$\theta = 3^{\circ}\\$ (three degrees), and take its \\$k\\$-th power by multiplying it \\$k\\$ times, using string repetition.

It remains to express \\$e^{i \theta}\\$ for \\$\theta = 3^{\circ}\\$. We could directly write out its sine and cosine, but it's a bit shorter to express it in terms of 36 and 30 degrees:

$$e^{i (3^\circ)} = \sqrt{e^{i (6^\circ)}} = \sqrt{e^{i (36^\circ)}e^{i (-30^\circ)}} = \sqrt{(\cos(36^\circ)+i \sin (36^\circ))(\cos(30^\circ)-i \sin (30^\circ))}$$

These angles have relatively nice sines and cosines. A bit of tweaking and combining terms gives this in the code's notation as:

```
S((1+S(5)+S(2*S(5)-10))/(S(12)+S(-4)))

```

If we call `S(c)` the value above, the value we want to output is:

```
(S(c) - 1/S(c))/S(-4)

```

using that \\$\sqrt{-4} = 2i\\$. Finally, an improvement from @loopwalt that saved 6 bytes is to simplify this to

```
(1-c)/S(-4c)

```
> 13 votes

# Answer
# Vyxal, 39 bitsv2, 4.875 bytes

```
∆R∆sS

```

Try it Online!

Bitstring:

```
000100111011111001011001001010111111101

```

Outputs square root as `sqrt(...)`, and division as `/`. Uses sympy to calculate the exact sine value, and then casts to string.

## Explained

```
∆R∆sS
∆R     # Convert the input to radians
  ∆s   # find sine of that
    S  # cast to string, which stops conversion to float. Instead, it uses the exact representation, which is expressed in terms of integers.

```

Created with the help of Luminespire.
> 5 votes

# Answer
# Python 3 \+ SymPy, ~~41~~ 39 bytes

```
lambda n:sin(rad(n))
from sympy import*

```

Try it online! Link outputs all results from  to `90°`. Edit: Saved 2 bytes thanks to @loopywalt.
> 4 votes

# Answer
# Ruby, ~~132~~ 110 bytes

```
f=->x{(x%60-24).abs==6?%w{(s5-1)/4 1/2 (s(30+s180)+s5-1)/8 1}[x/30]:"s(1/2+#{q=x<=>45}*(#{f[q*(x*2-90)]})/2)"}

```

Try it online!

While existing answers are very clever (and shorter than this!), the output expressions are rather long. This recursive function uses the half-angle formulas to produce expressions that fit on a single line in all cases.

Half angle formulas (rules for determining correct sign in all quadrants are unnecessary and omitted):

`cos(a/2)=sqrt(1/2+(cos a)/2)` or `cos x=sqrt(1/2+(cos x*2)/2)`

`sin(a/2)=sqrt(1/2-(cos a)/2)` or `sin x=sqrt(1/2-(cos x*2)/2)`

Below is a development version of the code, showing how the half angle formula is used to recursively derive expressions for all inputs. There are four infinite cycles as follows: `30>30`, `90>90`, `18>54>18`, `78>66>42>6>78`. These are broken with explicit values for 30,90,18 and 78 (note even the fairly complex base expression for 78 is much simpler than the base expression for 3 used in other answers.)

**Development code with table showing how each value is derived by recursion**

```
f=->x{m=x%60
m==30?"1/2"[0,90/x]:m==18?"(sqrt5-1)/4/-2+(sqrt(30+sqrt180)/8"[0,x/13*11]:"sqrt(1/2+#{s=x<=>45}sin(#{s*(x*2-90)})/2)"}

```

Try it online!
> 4 votes

# Answer
# Mathematica/Wolfram, 27 bytes

```
f=FunctionExpand@Sin[#*°]&

```

Try it online (thx to @noodle man)

This is a function solution - `#` introduces a placeholder for argument and `&` says whatever comes before is a pure function. `°` is builtin for number of radians in a degree, `@` is function application without brackets. Beyond that just relying on the underlying symbolic computation engine.

The full list of answers can be generated via:

```
Table[f[i * 3], {i, 0, 30}]

```
> 3 votes

---
Tags: code-golf, math
---