| Bytes | Lang | Time | Link |
|---|---|---|---|
| 069 | AWK | 250506T202016Z | xrs |
| 020 | Vyxal 3 | 250501T184402Z | pacman25 |
| 020 | Vyxal 3 | 250501T183845Z | pacman25 |
| 071 | Atari 800 Standard Basic | 250429T080828Z | Lars |
| 077 | Swift 6 | 231231T192154Z | macOSist |
| 086 | Tcl | 170210T232259Z | sergiol |
| 070 | C gcc | 231230T040937Z | Nicholas |
| 113 | Swift | 231229T165404Z | Annett S |
| 075 | Python 3 | 231229T152650Z | Larry Ba |
| 036 | Vis editor | 231229T082158Z | ROGUH |
| 061 | Ex | 230104T172142Z | gildux |
| 080 | Python 3 | 230104T183339Z | Joao-3 |
| 058 | POSIX Shell + Utilities | 230104T181111Z | набиячлэ |
| nan | 230104T174546Z | The Thon | |
| 025 | Vyxal J | 210907T130952Z | SjoerdPe |
| 017 | Vyxal L | 210908T124905Z | emanresu |
| 025 | APLDyalog Unicode | 210908T144934Z | ovs |
| 026 | K ngn/k | 210819T161450Z | coltim |
| 065 | JavaScript V8 | 210907T113051Z | Eternal |
| 060 | Python | 201127T191924Z | garrison |
| 065 | Zsh | 190911T192953Z | roblogic |
| 159 | StupidStackLanguage | 200618T185913Z | Lebster |
| 086 | C | 200618T143437Z | anatolyg |
| 027 | Pyth | 200618T132258Z | Sok |
| 021 | Stax | 200617T164250Z | recursiv |
| 248 | brainfuck | 200226T123641Z | The rand |
| 081 | JavaScript Babel Node | 200224T142154Z | Sarreph |
| 064 | Python 3.8 | 200223T193858Z | Ian Poe |
| 081 | C gcc | 200205T002720Z | S.S. Ann |
| 023 | Japt | 191201T173407Z | Gymhgy |
| 058 | Perl | 170719T233256Z | Kjetil S |
| nan | Commodore BASIC V2/V7 Commodore C64/128 | 190909T162239Z | Shaun Be |
| 037 | Keg | 190913T054059Z | lyxal |
| 059 | Python 3 | 191201T023447Z | JBernard |
| 064 | Python 3 | 191201T021413Z | lbragile |
| 061 | Wren | 191201T002154Z | user8505 |
| 081 | x8664 Machine Code | 190913T111454Z | me' |
| 025 | Japt R | 190911T084642Z | Shaggy |
| 028 | Japt R | 190910T134640Z | Oliver |
| 070 | TSQL | 190909T170139Z | BradC |
| 052 | SmileBASIC | 170205T231259Z | 12Me21 |
| 034 | J | 171102T122903Z | FrownyFr |
| 074 | 8th | 170719T191300Z | Chaos Ma |
| 059 | Common Lisp | 170210T192906Z | user6516 |
| 109 | C | 170211T042942Z | Albert R |
| 083 | Python 3 | 161122T171345Z | Juntos |
| 069 | Python | 161110T174315Z | NeRoboto |
| 033 | Pyth | 161011T202527Z | Dignissi |
| 065 | Scala | 161014T100215Z | corvus_1 |
| 097 | C | 161010T183942Z | Matthew |
| 087 | C | 161013T072643Z | BNik |
| 056 | Microscript II | 161012T175020Z | SuperJed |
| 060 | Python 3 | 161012T142437Z | Tim Shaf |
| 075 | Python 3 | 161012T020700Z | zawata |
| 028 | CJam | 161011T082650Z | Linus |
| 082 | Racket | 161010T132005Z | rnso |
| 056 | Python 3.5 | 161012T023630Z | xnor |
| 092 | C | 161011T184825Z | CSM |
| nan | BrainFlak | 161011T030605Z | Wheat Wi |
| 099 | Jvascript 99 Bytes | 161011T140321Z | Esteru |
| 146 | SQL | 161011T165622Z | datagod |
| 046 | Gloo | 161010T044012Z | Kade |
| 049 | Perl 5 | 161011T151101Z | ilkkachu |
| 075 | JavaScript ES6 | 161010T234001Z | Croer01 |
| 074 | C# | 161011T113918Z | NibblyPi |
| 035 | Vim | 161011T130640Z | m-chrzan |
| 072 | Mathematica | 161010T082150Z | user5863 |
| 065 | SX | 161011T131815Z | XiKuuKy |
| 032 | Charcoal | 161011T130619Z | ASCII-on |
| 944 | Xasm | 161011T130438Z | XiKuuKy |
| 089 | Java 7 | 161010T125738Z | Kevin Cr |
| 026 | Vim | 161011T115340Z | udioica |
| 054 | GNU sed | 161010T122054Z | seshouma |
| 051 | q | 161011T040204Z | Boston W |
| 061 | Python 2 | 161010T231900Z | xnor |
| 064 | Python 3 | 161010T221425Z | DomPar |
| 024 | Jelly | 161010T030353Z | Dennis |
| 092 | C# | 161010T072950Z | adrianmp |
| 065 | JavaScript ES6 | 161010T095544Z | Arnauld |
| 044 | Ruby | 161010T032045Z | Level Ri |
| 050 | Vim | 161010T111151Z | 永劫回帰 |
| 089 | Emotinomicon | 161010T190343Z | Linnea G |
| 073 | Bash | 161010T183424Z | Matthew |
| 026 | V | 161010T024447Z | DJMcMayh |
| 052 | J | 161010T024813Z | Conor O& |
| 032 | Jolf | 161010T030231Z | Conor O& |
| 224 | Brainfuck | 161010T155033Z | Hunter V |
| 037 | Japt | 161010T144045Z | ETHprodu |
| 044 | PowerShell v2+ | 161010T134625Z | AdmBorkB |
| 024 | 05AB1E | 161010T093729Z | Emigna |
| 052 | /// | 161010T105100Z | Erik the |
| 062 | PHP | 161010T101456Z | aross |
| 026 | MATL | 161010T084015Z | Luis Men |
| 073 | JavaScript ES6 | 161010T081402Z | edc65 |
| 073 | Powershell | 161010T082800Z | Callie J |
| 075 | R | 161010T082151Z | Billywob |
| 105 | Batch | 161010T084858Z | Neil |
| 026 | Pyke | 161010T075734Z | Blue |
| 062 | Dart | 161010T083809Z | lrn |
| 069 | IBM/Lotus Notes Formula | 161010T082750Z | ElPedro |
| 068 | Python 2 | 161010T070805Z | DomPar |
| 063 | Python 2 | 161010T063531Z | DLosc |
| 053 | Haskell | 161010T050221Z | nimi |
| 056 | Cheddar | 161010T025119Z | Downgoat |
| 026 | Actually | 161010T024128Z | user4594 |
AWK, 69 bytes
$0=(a="rnbqkbnr\n")(b="pppppppp\n")(c="........\n")c c c toupper(b a)
Vyxal 3, 20 bytes
">⤻⑵u⎙„'p'.⎂8×:WæʁJ”
could save 2 bytes if flags existed but this new "both" modifier is pretty cool
">⤻⑵u⎙„'p'.⎂8×:WæʁJ”
">⤻⑵u⎙„ # compressed string "rnbqkbnr"
⎂ # apply to both
'p'. # the string 'p' and '.'
8× # repeat 8 times
: # duplicate the periods
W # wrap the stack
æ # bifurcate it (push a reverse copy)
ʁJ” # Uppercase it, join and print on newlines
💎
Created with the help of Luminespire.
Vyxal 3, 20 bytes
">⤻⑵u⎙„'p'.⎂8×:WæʁJ”
could save 2 bytes if flags existed but this new "both" modifier is pretty cool
Atari 800 - Standard Basic, 71 Bytes
The Atari computer system may be a little bit older, since 1979. This old home computer starts into Atari Basic if cartridge is present. On "newer" XL/XE systems the Atari computer starts into Basic per default. The trick is to set the right margin to 9. The left margin is set to 2 by the OS per default. Therefore no 'newline' is need. The ? is the short form for the PRINT command.
POKE83,9:?:?"rnbqkbnrpppppppp";:FORI=0TO31:?".";:NEXTI:?"PPPPPPPPRNBQKBNR"
74 Bytes.
It is possible to use some code abbreviations.
POKE83,9:?:?"rnbqkbnrpppppppp";:F.I=0TO31:?".";:N.I:?"PPPPPPPPRNBQKBNR"
71 Bytes.
Swift 6, 80 77 bytes
let d="........\n",c="rnbqkbnr\npppppppp\n\(d)\(d)\(d)\(d)PPPPPPPP\nRNBQKBNR"
Tcl, 86 bytes
proc R {s n\ 8} {string repe $s $n}
puts rnbqkbnr\n[R p]\n[R [R .]\n 4][R P]\nRNBQKBNR
C (gcc), 71 70 bytes
I would be really surprised if someone could make this any shorter (seems impossible to me, but who knows?).
Edit: The cat has one-upped me again.
*c=L"湲煢扫牮瀊灰灰灰ੰ⸮⸮⸮⸮⸊⸮⸮⸮ਮ⸮⸮⸮⸮⸊⸮⸮⸮ਮ偐偐偐偐刊䉎䭑乂ꁒ";main(){for(;printf(c++););}
Try it online (with explanation)
Explanation:
// The full output stored as wide characters.
// Each wide character stores 2 ASCII characters (represented as U+XXYY).
// For example, to store "rn" take the ASCII values (r => 0x72, n => 0x6E) and
// find the character U+6E72. Notice the order is reversed. I assume this is
// because x86 is little-endian.
*c=L"湲煢扫牮瀊灰灰灰ੰ⸮⸮⸮⸮⸊⸮⸮⸮ਮ⸮⸮⸮⸮⸊⸮⸮⸮ਮ偐偐偐偐刊䉎䭑乂ꁒ";
main(){
// printf() returns the number of characters printed. When 'c' contains
// '\0' at the end of the string, printf() will return 0. Resulting in
// the loop terminating.
for(;printf(c++););
}
Swift, 113 bytes
func p()->String{var m="rnbqkbnr";for c in "p....P"{m+="\n";for _ in 1...8{m+="\(c)"}};m+="\nRNBQKBNR";return m}
(Start with the first row, append 8 times p, . and P and then append the last row.)
Python 3, 75 bytes
lambda a="rnbqkbnr",b="p"*8:"\n".join([a,b,*["."*8]*4,b.upper(),a.upper()])
Vis editor, 36 bytes
irnbqkbnr<Escape>5o<Escape>4<Ctrl-k>:i8/.<Enter><Escape>08rpykGpddpVkU
irnbqkbnrX5oX4K:i8/.NX08rpykGpddpVkU
Sequences and are counted as 1 byte each.
i- Insert the first row.<E>5o<E>- Add 5 newlines under the first line, cursor is now at end of file.4<C-k>- Add 4 additional cursors above current cursor:i8/.- Use a Sam command to insert 8 periods at all 5 cursor locations. Still in NORMAL mode.<Esc>- Get rid of all but the primary cursor, which is conveniently located at the 2nd line. Still in NORMAL mode.08rp- Go to begining and replace the following 8 dots withp.yk- Yank current line and line above (j is down, k is up).G- Jump to end of file.pddp- Paste 1st and 2nd line, then swap them.VkU- Select entire last line and line above (as before, k is up), uppercase both.
I had a slightly shorter codegolf in vis, but this is more instructure because it uses a Sam expression :i8/ and multi cursors (including the location of the primary cursor).
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Ex, 66 61 bytes
(not a language per se, but reproductible line-oriented editor)
a
rnbqkbnr
.
t.
%t.
%t.
2s/./p/g
7s/./P/g
8s/./\u&/g
3,6s/././g
x
Second version, shorter, and sure there's room for improvement while staying POSIX.
a
rnbqkbnr
.
t.
%t.
%t.
2,7s/./p/g
7,8s/./\u&/g
3,6s/././g
x
usage notes
To try online, just launch ex yourfilename then paste the lines. The result will be viewable with cat yourfilename.
ungolfed/explanation
It's a line oriented editor (which will serve our purpose here as we operate line by line), with commands following the general syntax "line/range command parameters" (so 3 colomns plus one for comment following)
a " append following lines until line with dot only
rnbqkbnr
.
t . " duplicate current line
"rnbqkbnr
"rnbqkbnr
% t . " duplicate the whole buffer (2 lines)
"rnbqkbnr
"rnbqkbnr
"rnbqkbnr
"rnbqkbnr
% t . " copy the whole buffer (4 lines)
"rnbqkbnr
"rnbqkbnr
"rnbqkbnr
"rnbqkbnr
"rnbqkbnr
"rnbqkbnr
"rnbqkbnr
"rnbqkbnr
2,7 s/./p/g " from line 2 to 7, replace each character with lower P
"rnbqkbnr
"pppppppp
"pppppppp
"pppppppp
"pppppppp
"pppppppp
"pppppppp
"rnbqkbnr
7,8 s/./\u&/g " on lines 7 and 8, replace each character with its uppercase
"rnbqkbnr
"pppppppp
"pppppppp
"pppppppp
"pppppppp
"pppppppp
"PPPPPPPP
"RNBQKBNR
3,6 s/././g " from line 3 to 6, replace each character with a dot
"rnbqkbnr
"pppppppp
"........
"........
"........
"........
"PPPPPPPP
"RNBQKBNR
x " write the buffer into file and close the editor
Commands have a full name and a shortcut used here, as we're golfing.
aforappend, to switch into input mode until a sole dotsforsubstitute, with parameters /RegExp/replacement/flags where the flagghere means all occurrences (instead of default first only)tinitialy means transfer and is put forcopy(the letter C was already used to change/replace line) with as parameter the line after one should copy (and the.is for the current)xforxitand is put for exit (the letter E was already used to edit a file)
That's all.
Python 3, 80 bytes
print(*(l:=["rnbqkbnr",'p'*8,b:='.'*8,b]),*[m.upper()for m in l][::-1],sep='\n')
When you first look at this code, you might ask: why so many asterisks? 2 asterisks are splat operators, and the other 2 are string multiplication.
I'll first work from the inner-most layer of code and I'll work the way up, explaining everything.
We make a variable b, which is one of the blank lines. Which is the string '.' repeated 8 times. We put that and another copy of b.
That is inside a list, which has some more items before that. There's the top row and the pawn row ('p' repeated 8 times). That is saved into a variable l and splatted into print.
Then we have a comprehension, which makes every line in l have uppercase letters (white's side). We need to reverse that array and then splat it into print.
Finally, we use the new line as an argument separator and we are done!
POSIX Shell + Utilities, 58 bytes
printf rnbqkbnr%08d%32sPPPPPPPPRNBQKBNR|tr 0\ p.|fold -w8
Always nice to outdo a Bash-specific solution :)
$ cat cg; echo; wc -c cg
printf rnbqkbnr%08d%32sPPPPPPPPRNBQKBNR|tr 0\ p.|fold -w8
58 cg
$ ./cg
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Thunno N, \$28 \log_{256}(96) \approx\$ 23 bytes
(The leaderboard needs an integer, so I rounded it. It's actually 23.05 bytes)
"rnbqkbnr"'p8*'.8*DZMDrusA+r
Port of Emigna's 05AB1E answer.
"rnbqkbnr" # Push "rnbqkbnr" STACK: "rnbqkbnr"
'p8* # Push "pppppppp" STACK: "rnbqkbnr", "pppppppp"
'.8*D # Push "........" twice STACK: "rnbqkbnr", "pppppppp", "........", "........"
ZMD # Push the stack twice STACK: ["rnbqkbnr", "pppppppp", "........", "........"],
["rnbqkbnr", "pppppppp", "........", "........"]
ru # Reverse, uppercase STACK: ["rnbqkbnr", "pppppppp", "........", "........"],
["........", "........", "PPPPPPPP", "RNBQKBNR"]
sA+ # Concatenate STACK: ['RNBQKBNR', 'PPPPPPPP', '........', '........',
'........', '........', 'pppppppp', 'rnbqkbnr']
r # Reverse STACK: ['rnbqkbnr', 'pppppppp', '........', '........',
'........', '........', 'PPPPPPPP', 'RNBQKBNR']
# N flag joins by newlines
Vyxal J, 26 24 31 28 25 bytes
-2 bytes thanks to the j flag.
+7 bytes, added code to swap Q and K to make it valid.
-3 bytes thanks to Aaron Miller!
-3 bytes thanks to Kevin Cruijssen
«æ≠⁺tO«\p8*\.8*:W⁋Ḃ⇧‛KQḂV
Explanation
«æ≠⁺tO« - Push "rnbqkbnr"
\p8* - Push "pppppppp"
\.8*: - Push "........" twice
W⁋ - Listify, then join by \n
Ḃ⇧ - Bifurcate and uppercase the second half
‛KQḂV - Replace "KQ" with "QK"
<flag> - Join by newlines and print entire stack implicitly
Vyxal L, 17 bytes
«æ≠⁺tO«ƛ`p..`+Ḃ⇧+
-1 thqnks to Aaron Miller.
«...« # Compressed string `rnbqkbnr`
ƛ # Map...
`p..`+ # Append `p..` to each
Ḃ # Duplicate, reverse
⇧+ # Uppercase the reversed copy and append
# (L flag) vertical join (rotate 90°) at the end.
APL(Dyalog Unicode), 26 25 bytes SBCS
Taking some inspiration from coltim's K answer.
-1 byte thanks to Razetime!
(⎕C⍪⊖)'RNBQKBNR'⍪8/⍪'P..'
Try it on APLgolf! or Get some intermediate values
APL(Dyalog Unicode), 30 28 bytes SBCS
(⎕C∘⊖⍪⊢)⍉'..P'⍪⍤1⍪'RNBQKBNR'
⍪'RNBQKBNR' Make a 8x1 matrix of characters
'..P'⍪⍤1 Prepend three columns made from the characters from '..P'
⍉ Transpose to get the bottom half of the result
⎕C∘⊖ Mirror vertically and convert to lower case
⍪⊢ Stack this on top of the bottom half
K (ngn/k), 28 26 bytes
-2 bytes from @ngn's improvements
|a,_|a:+"RNBQKBNR",\:"P.."
"RNBQKBNR",\:"P.."prepend each of"RNBQKBNR"to"P.."a:+tranpose this, storing in variablea. this generates the capitalized half of the chess board.|a,_|append the lower-cased, reversed lines to the upper-cased lines. reverse again to put the lower-cased lines at the top and the upper-cased lines at the bottom
JavaScript (V8), 65 bytes
_=>`rnbqkbnr
pppppppp
`+`........
`.repeat(4)+`PPPPPPPP
RNBQKBNR`
Explanation :
_ => // beginning of function param is not needed so we do _ instead of ()
`rnbqkbnr
pppppppp
` // first two lines are written better than doing line1+\n+line2+\n
+ // add to it
`........
`repeat(4) // repeat this line of ........ 4 times
+`PPPPPPPP
RNBQKBNR` // last two lines
Python, 70 60 bytes
print("rnbqkbnr","p"*8,*["."*8]*4,"P"*8,"RNBQKBNR",sep='\n')
Also if someone could explain to me why this doesn't work, I'd appreciate it!
map(print,["rnbqkbnr","p"*8,*["."*8]*4,"P"*8,"RNBQKBNR"])
Zsh, 69 65 bytes
build array, print it forwards, print it backwards+lowercase
D=........ X=(RNBQKBNR PPPPPPPP $D $D);printf %s\\n $X ${(Oa)X:l}
StupidStackLanguage, 159 bytes
avvqimqvdflfqwwddflqiiifqwdfbblfbflfavvflddfffffffflfqvvvvvvvifffffffflflfffffffflflfffffffflflfffffffflflvvvvvvvdfffffffflfliifqwifqwwddfbldfldddfwwifvviifbif
Note: Due to StupidStackLanguage not being on tio.run, I have linked the python interpreter with the program loaded in. Close the header and footer tabs to hide the interpreter and only show the StupidStackLanguage program & output.
C, 86 bytes
k(x,y){for(y=x=8;y;putchar(!x--?--y,x=8,10:"RNBKQBNR.P"[y-3u<4?8:y%5^2?x:9]+y/7*32));}
Yet another attempt to golf a loop.
Pyth, 27 bytes
js.erbk_B+"rnbqkbnr"*L8"p..
js.erbk_B+"rnbqkbnr"*L8"p..
"p.. The string "p.."
*L8 Repeat each character 8 times, yields ["pppppppp", "........", "........"]
+"rnbqkbnr" Prepend "rnbqkbnr" to the list
_B Pair the list with itself, reversed
.e Map as b, with index k:
rbk Change case of elements of b
The r token converts to lower case if one of the arguments is 0, and
converts to uppercase if one of the arguments is 1.
s Concatenate the two halves of the output
j Join on newlines, implicit print
brainfuck, 248 bytes
There is probably a better way to do this.
++++++++++[>+>+++++++++++>++++++++>++++++++++>+++++<<<<<-]>>++++>>-->----<<<.----.>>.<<+++.------.>>.<<+++.++++.<.>--........<.>>>>>++++++[<........<<<<.>>>>>-]<<<........<<.>>++.----.------------.+++++++++++++++.------.---------.++++++++++++.++++.
JavaScript (Babel Node), 89 81 bytes
console.log("rnbqkbnr\npppppppp\n"+"........\n".repeat(4)+"PPPPPPPP\nRNBQKBNR\n")
Python 3.8, 64 bytes
I've just started code-golfing, so I'm not very good at it. This is what I got.
print('rnbqkbnr\n'+'p'*8+('\n'+'.'*8)*4+'\n'+'P'*8+'\nRNBQKBNR')
C (gcc), 81 bytes
f(){printf("rnbqkbnr\npppppppp\n%s%1$s%1$s%1$sPPPPPPPP\nRNBQKBNR","........\n");}
I'd try reusing more but that wouldn't beat the naive solution because there's no easy upper() or lower() functions.
C (gcc), 92 bytes
f(){puts("rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR");}
When not overthinking it, this is the best solution.
Japt, 23 bytes
`rnbqkbnr`y+"p.."
y_+Ôu
`rnbqkbnr` //String "rnbqkbnr"
y //Map each column
+"p.." // and add "p.." to the column
//Save to variable 'U'
y_ //Map each column again
Ôu //Reversed, then converted to uppercase
+ //Append that
Perl, 58 Bytes
say for map/../?$_:$_ x8,qw(rnbqkbnr p . . . . P RNBQKBNR)
Run like this:
perl -E'say for map/../?$_:$_ x8,qw(rnbqkbnr p . . . . P RNBQKBNR)'
For each elem in the list (qw), print (say) the element if its length is two (or more) or print the element eight times if just length of one.
Commodore BASIC V2/V7 (Commodore C64/128, VIC-20, TheC64Mini) - 129 tokenized and BASIC bytes
0n$=cH(13):a$="{clear}{ctrl+h}{ctrl+n}rnbqkbnr"+n$:p$="pppppppp"+n$:?a$p$;:fOi=0to3:?"........":nE:goS1:?p$a$:end
1a$="RNBQKBNR"+n$:p$="PPPPPPPP"+n$:reT
This should be entered into BASIC on a Commodore 128 and saved, it will then load into the VIC/C64 okay (you may need LOAD "CHESS",8,0 on the VIC-20), or use CBM PRG Studio. The reason for this is that I'm going over the 80/88 character limit in line 0 for the C64/VIC-20 respectively. The C128 allows a 160 PETSCII character limit, so with keyword abbreviations this could easily be > 160 character per BASIC line.
The {clear} character is achieved by SHIFT + CLR/HOME, whereas (in a string) CTRL+H disables the SHIFT+C= key to toggle between graphics and business mode, and CTRL+N changes the case to business mode in BASIC.
The resulting listing is as in the screen shot. Copy the listing above and paste it into WinVICE with a right-click on your mouse over the VICE window.
I've added the resulting output on the VIC-20 to prove that it'll load on that mighty micro as well.
Keg, 43+1 40 39 37 bytes
rnbqkbnr
∑p)
(4|`.`8*
)(8|P)
RNBQKBNR
Answer History
39 bytes
rnbqkbnr
(8|p)
(4|`.`8*
)(8|P)
RNBQKBNR
40 bytes
rnbqkbnr
(8|p)
(4|(8|\.)
)(8|P)
RNBQKBNR
-4 bytes due to fixing a bug. That's new.
44 bytes
rnbqkbnr\
(8|p)\
(4|(8|\.)\
)(8|P)\
RNBQKBNR
Run length encoding where possible. Implicitly print the result.
In depth:
rnbqkbnr #push rnbqkbnr
(8|p) #8 times, push the letter "p"
\ #escaped newline
(4| #4 times, do
(8|\. #8 times, push "."
)\ #then push a newline
)
(8|P) #8 times, push P
\ #escaped newline
RNBQKBNR #push RNBQKBNR
Python 3, 59 bytes
print('rnbqkbnr','p'*8,*['.'*8]*4,'P'*8,'RNBQKBNR',sep='\n')
Interesting that with better unpacking and print function, Python 3 can be much better than Python 2 for golf
This was based on https://codegolf.stackexchange.com/a/95758/2212
Python 3, 66 64 bytes
64 bytes:
print('rnbqkbnr','p'*8,('.'*8+'\n')*4,'P'*8,'RNBQKBNR',sep='\n')
Logic:
- Pieces remain the same as previously
- pawns and dots get repeated 8 times
- "." is appended a new line and the whole thing is repeated 4 times.
- entire print is separated with sep='\n'
66 bytes:
print('\n'.join(['rnbqkbnr']+[i*8for i in 'p....P']+['RNBQKBNR']))
Logic:
- create the piece arrays as is at first and last positions.
- create the middle 6 rows by list comprehension - using repetition
i*8. - Sum the lists to get 8 elements
- Join elements with a line break in between (
\n) print()
Output:
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Wren, 61 bytes
I suppose this is not a good way of programming, but this is worth it when it comes to code golf.
Fn.new{"rnbqkbnr
"+"p"*8+"
"+("."*8+"
")*4+"P"*8+"
RNBQKBNR"}
Explanation
Fn.new{ // New function
"rnbqkbnr
" // rnbqkbnr\n
+"p"*8 // pppppppp
+"
" // \n
+("."*8 // ........
+"
" // \n
)*4 // above strings 4 times
+"P"*8 // PPPPPPPP
+"
RNBQKBNR" // \nRNBQKBNR
}
x86-64 Machine Code, 81 bytes
57 push rdi
48 BA 52 4E 42 4B 51 42 4E 52 mov rdx,524E42514B424E52h
52 push rdx
BA 50 50 50 50 mov edx,50505050h
52 push rdx
89 54 24 04 mov dword ptr [rsp+4],edx
51 push rcx
5A pop rdx
6A 30 push 30h
59 pop rcx
48 2B E1 sub rsp,rcx
54 push rsp
5F pop rdi
B0 2E mov al,2Eh
F3 AA rep stos byte ptr [rdi]
0F 10 44 24 30 movups xmm0,xmmword ptr [rsp+30h]
0F 11 04 24 movups xmmword ptr [rsp],xmm0
54 push rsp
52 push rdx
56 push rsi
5A pop rdx
5F pop rdi
5E pop rsi
B1 10 mov cl,10h
80 74 8C FF 20 xor byte ptr [rsp+rcx*4-1],20h
E2 F9 loop addLoop (07FF66A5A13B8h)
B1 08 mov cl,8
B0 0A mov al,0Ah
48 A5 movs qword ptr [rdi],qword ptr [rsi]
AA stos byte ptr [rdi]
E2 FB loop addLoop+0Bh (07FF66A5A13C3h)
C6 07 00 mov byte ptr [rdi],0
48 83 C4 40 add rsp,40h
48 8B F2 mov rsi,rdx
5F pop rdi
C3 ret
Create using abuse of push/pop instructions. Could probably save a few bytes by using Linux calling conventions. Outputs to a pointer specified in the first parameter rcx.
Japt -R, 25 bytes
"rnbqkbnr"¬m+'.²ip)®+ÔuÃÕ
"rnbqkbnr"¬m+'.²ip)®+ÔuÃÕ
"rnbqkbnr" :String literal
¬ :Split
m+ :Map & append
'.² : "." repeated twice
ip : Prepend "p"
) :End map
®+ :Map & append
Ô : Reversed string
u : Uppercased
à :End map
Õ :Transpose
:Implicit output, joined by newlines
T-SQL, 70 bytes
PRINT REPLACE('rnbqkbnr
pppppppp
1111PPPPPPPP
RNBQKBNR',1,'........
')
SQL allows line breaks inside quotes, I used that in both the main and the replaced strings. Using a numeral instead of a symbol as my replacement character lets me save 2 additional bytes.
Tried to replace the other two strings, but couldn't find anything shorter than 80 bytes:
SELECT r+p+e+e+e+e+UPPER(p+r)FROM(SELECT'rnbqkbnr
'r,'pppppppp
'p,'........
'e)a
SmileBASIC, 52 bytes
?"rnbqkbnr
?"p"*8?("."*8+CHR$(10))*4;"P"*8?"RNBQKBNR
8th, 74 bytes
Code
"RNBQKBNR\n" dup lc . "PPPPPPPP\n" dup lc . ( "........\n" . ) 4 times . .
Output
ok> "RNBQKBNR\n" dup lc . "PPPPPPPP\n" dup lc . ( "........\n" . ) 4 times . .
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Common Lisp, 72 69 68 65 63 59 bytes
(format t"rnbqkbnr
~8@{p~}
~4@{~8@{.~}
~}~8{P~}
RNBQKBNR"1)
Ideas for improvement are welcomed.
C, 112 109
char *e="rnbqkbnr";main(a){for(;a<65;)putchar((a++-1)%9?a<11?e[a-3]:a<20?112:a<48?46:a<57?80:e[a-57]-32:13);}
Readable:
char *e="rnbqkbnr";
main(a){
for(;a<65;)
putchar((a++-1)%9?a<11?e[a-3]:a<20?112:a<48?46:a<57?80:e[a-57]-32:13);
}
Notes:
•char 13 = new line
•char 112 = 'p'
•char 46 = '.'
•char 80 = 'P'
•lowercase char-32 = UPPERCASE CHAR
Thoughts: It's annoying because this is very well golfed for a short solution, but at the same time I could have gone sub-100 in my byte count by just hard coding in most of the chess board and just repeating the . . . part with a puts loop. But that's a very boring answer
Thanks @Ahemone for 3 bytes off!
Python 3, 83 Bytes
t="rnbqkbnr"
n="\n"
print((t)+n+("p"*8)+n+(("."*8+"\n")*4)+n+("P"*8)+n+(t.upper()))
Python, 69 bytes
n='\n'
p,a='p'*8+n,'rnbqkbnr'+n
print a+p+('.'*8+n)*4+(p+a).upper()
There are two things that frustrate me with this code: the print and "upper". Wouldn't an up function be cool? Anyway, here's my first golf answer.
Pyth, 41 35 34 33 Bytes
K*z\p8J"rnbqkbnr"JKp*+*\.8b4rK1rJ1
Golfed a byte thanks to @daHugLenny
Explanation
K*\p8 K="pppppppp"
J"rnbqkbnr" J="rnbqkbnr"
J print The Variable J
K print The Variable K
p+*+*\.8b4 print"........\n" 4 times
rK1 print K but in uppercase
rJ1 print J but in uppercase
Scala, 65 bytes
Seq("rnbqkbnr","p",".",".",".",".","P","RNBQKBNR")map(_*8 take 8)
Really straightforward; makes use of the repeat 8 times and take the first 8 chars
C, 97 bytes
char *e="........\n";main(){printf("rnbqkbnr\npppppppp\n%s%s%s%sPPPPPPPP\nRNBQKBNR\n",e,e,e,e);}
C, 87 bytes
#define E "........\n"
main(){puts("rnbqkbnr\npppppppp\n"E E E E"PPPPPPPP\nRNBQKBNR");}
This uses preprocessor and string literal joining. Sorry, Matthew Greci and CSM, I don't have any reputation here to comment on your solution
Microscript II, 56 bytes
"rnbqkbnr\npppppppp"P"........"PPPP"PPPPPPPP\nRNBQKBNR"
Python 3, 60 bytes
print('rnbqkbnr','p'*8,*['.'*8]*4,'P'*8,'RNBQKBNR',sep='\n')
Python 3, 82 80 75 Bytes
Not the shortest answer in python but it's my first and i think its pretty good for a first time
print('\n'.join((i*8)[:8]for i in'rnbqkbn p . . . . P RNBQKBN'.split()))
CJam, 29 28 bytes
"rnbqkbnr"{"p.."+_W%eu+}%zN*
Explanation:
This new version saves a byte by doing the work on columns inside a map { }% instead of 8*-ing rows. An interesting feature is that the string (array of chars) becomes an array of strings which can then be transposed without splitting.
"rnbqkbnr" e# hard-coded pieces
{ e# do to each piece
"p.."+ e# append "p.."
_W% e# copy and reverse
eu+ e# capitalize and append
}%z e# transpose to rows
N* e# insert newlines
Racket 82 bytes
(display"rnbqknbr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKNBR")
Another version: 162 bytes
(display(string-append"rnbqknbr\n"(make-string 8 #\p)(list->string(for/list((i
(range 0 37)))(if(= 0(modulo i 9))#\newline #\.)))(make-string 8 #\P)"\nRNBQKNBR"))
Ungolfed:
(define (f)
(display (string-append
"rnbqknbr\n"
(make-string 8 #\p)
(list->string
(for/list ((i (range 0 37)))
(if(= 0 (modulo i 9)) #\newline #\.)))
(make-string 8 #\P)
"\nRNBQKNBR"))
)
Testing:
(f)
Output:
rnbqknbr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKNBR
Python 3.5, 56 bytes
for r in['rnbqkbn',*'p....P','RNBQKBN']:print((r*8)[:8])
This uses an idea by zawata to encode each line as (r*8)[:8], with a string repeated 8 times and trimmed to length 8. The pawns and empty rows are just 'p'*8, '.'*8, and 'P'*8, with no trimming. The first row uses 'rnbqkbn', with ('rnbqkbn'*8)[:8] including another rook on the right when multiplied and trimmed. The last row is the same but capitalized.
We express the list of row-parts compactly ['rnbqkbn','p','.','.','.','.','P','RNBQKBN'] using Python 3.5's generalized unpacking. We write out the first and last-entries, and the remaining single-character ones are unpacked from a string.
In Python 2, we could settle for split instead for 60 bytes:
for i in'rnbqkbn p . . . . P RNBQKBN'.split():print(i*8)[:8]
C, 113 92 bytes
main(){printf("rnbqkbnr\npppppppp\n%s%1$s%1$s%1$s%1$s%1$sPPPPPPPP\nRNBQKBNR","........\n");}
This makes use of the %1$s parameter-position to repeat the empty lines.
Sorry, Matthew Greci, I don't have any reputation here to comment on your solution (you could also have removed some whutespace to get yours down a bit.
Edit 1: Removed arguments (thanks Martin Ender), removed a few too many empty-square lines.
Brain-Flak, 366 350 + 3 = 353 bytes
(((((((((((()()())){}(((({}))){}{}(([((({})){}){}](([({}())](((((({}()){}){}){}()){})<>))<>)<>)<>)))<<>({}<>)<>({}<>)<>({}<>)([]()())>[()]))))))))(()()()()){({}[()]<((((((((((((()()()()()){})()){}()){}))))))))>)}{}(((()()()()()){})<((((((((([][]()()()()))))))))<>)<>>)(((((()()()))){})(({}{})(([{}({})](([{}()](<>({}()())<>)<>)<>)<>)<>))){<>({}<>)}{}
This gets a plus 3 because it requires the -A flag to run properly.
Explanation
First we push the last 5 letters to the active stack.
We also push copies of last 3 numbers to the inactive stack.
This is done with fairly simple methods I won't go into for the sake of brevity.
(((()()())){}(((({}))){}{}(([((({})){}){}](([({}())](((((({}()){}){}){}()){})<>)<><>)<>)<>)<>)))
We Move Everything from the offstack to the onstack.
The first 3 letters are the same as the last 3 letters in the first line
{<>({}<>)}{}
We push 10 for a new line
((()()()()()){})
Using the value of Q we create a P and push it 8 times
((((((((<...>[()]))))))))
We loop 4 times each time pushing 8 dots and a newline
(()()()())
{({}[()]<
((((((((((((()()()()()){})()){}()){}))))))))
>)}{}
We push the last two lines in a very similar way to the first two.
(((()()()()()){})<((((((((([][]()()()()))))))))<>)<>>)(((()()()){})(({}()()())(([{}(()()())](([{}()](<>({}()())<>)<>)<>)<>)<>))){<>({}<>)}{}
Jvascript 152 Bytes - 146 Bytes - 99 Bytes
Golfed code:
(n="rnbqkbnr",l=`
`,s=l+"........",t=n+l+"pppppppp"+s+s)=>t+l+[...t].reverse().join``.toUpperCase()
Ungolfed:
t = (n = "rnbqkbnr", l = "\n", s = l + ".".repeat(8), t = n + l + "p".repeat(8) + s + s) => {
console.log(t + l + t.split("").reverse().join("").toUpperCase());
}
(() => { t(); })();
SQL, 146 Bytes
declare @ char(8)='rnbqkbnr'
print 'pppppppp'
print '........'
print '........'
print '........'
print '........'
print 'PPPPPPPP'
print upper(@)
Gloo, 46 Bytes
Gloo is a very, erm, young language with very little stack manipulation implemented. I think this is probably the best I can do since there's also no uppercase function. The raw bytes are below, and can be run from the interpreter using gloo.py -f <file>.
Offset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
000000 22 72 6E 62 71 6B 62 6E 72 0A 22 22 70 22 38 2A "rnbqkbnr.""p"8*
000010 22 0A 22 22 2E 22 38 2A 22 0A 22 2B 34 2A 22 50 ".""."8*"."+4*"P
000020 22 38 2A 22 0A 52 4E 42 51 4B 42 4E 52 22 "8*".RNBQKBNR"
This doesn't count because it was updated after the challenge started, but now there's an easy 32 byte solution:
"rnbqkbnr"'p8*[_?¶Ä'.4*‘8*’;[¶jj
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 22 72 6E 62 71 6B 62 6E 72 22 27 70 38 2A 5B 5F "rnbqkbnr"'p8*[_
00000010 3F B6 C4 27 2E 34 2A 91 38 2A 92 3B 5B B6 6A 6A ?¶Ä'.4*‘8*’;[¶jj
Perl 5, 49 bytes
print join$/,$_=rnbqkbnr,"p"x8,("."x8)x4,"P"x8,uc
If only we had something like p instead of print, the remaining legible words could be removed.
print join $/, ... - print the items joined by the input
record separator, $/, which is "\n" by default
$_ = rnbqkbnr - set (and return) the default variable.
A bare string is taken as a string constant,
but gives a warning... but only if they're enabled
"p" x 8 - string multiplier
("."x8)x4 - string and list multiplier.
"P" x 8 - same
uc - uppercase, if no expression given, uses $_
Of course this depends on the order of evaluation of the parameters to join, as $_ needs to be set before uc is called. Also, this doesn't print a trailing newline, which makes it look ugly if executed from the command line.
JavaScript (ES6), 63 75 bytes
original
a=`rnbqkbnr
`;for(j of'p....P')a+=j.repeat(8)+`
`;a+='RNBQKBNR'
edited, with output integrated:
a=`rnbqkbnr
`;for(j of'p....P')a+=j.repeat(8)+`
`;console.log(a+'RNBQKBNR')
alternative version using throw but I think this is not valid because write extra output. Total 69 bytes:
a=`
rnbqkbnr
`;for(j of'p....P')a+=j.repeat(8)+`
`;throw a+'RNBQKBNR'
C#, 85 84 83 74 bytes
Edit: Accidentally had too many rows of blank spaces!
Edit: Freed an extra character and fixed the ordering (accidentally had it all reversed) many thanks to @KevinCruijssen
Edit: Reverted back to 83 cos I had the prawns on the wrong line
Edit: Thanks to @adrianmp who helped me shrink it further by omitting return
Using the same format as @adrianmp answer above:
x=>"rnbqkbnr\npppppppp\nxxxxRNBQKBNR\nPPPPPPPP".Replace("x","........\n");
Full program using the above function:
using System;
namespace DrawAnASCIIChessBoard
{
class Program
{
static void Main(string[] args)
{
Func<object, string> f =
x=>"rnbqkbnr\npppppppp\nxxxxRNBQKBNR\nPPPPPPPP".Replace("x","........\n");
Console.WriteLine(f(1));
}
}
}
Vim, 35 bytes
4irnbqkbnr<cr><esc>ddVkr.kVrpkyG:g//m0<cr>gUGP
4irnbqkbnr<cr><esc> # enter 4 lines, each containing the lowercase figures
dd # delete the empty line at the bottom
Vkr. # replace the bottom two lines with '.'s
kVrp # replace the next line up with 'p's
kyG # go up and copy all lines
:g//m0<cr> # move the lines with periods to the top
# now instead of the black half of the board, we have the white half
gUG # change all characters upper case
P # paste what we had copied before (the black half) above the current line
The :g//m0 trick is copied from this answer by Lynn.
Mathematica, 76 72 bytes
{"rnbqkbnr
","p"~(t=Table)~8,"
",t["."~t~8<>"
",4],"P"~t~8}<>"
RNBQKBNR"
Table is used to generate lists of strings. When lists of strings meet the concatenation operator <>, they get flattened into strings automatically, so the construction { ... , ... , ... }<>... is preferred over using <> throughout when there are sufficiently many strings to be concatenated.
Also 72 bytes:
{"rnbqkbnr
","p"~(t=Table)~8,"
",{"."~t~8,"
"}~t~4,"P"~t~8}<>"
RNBQKBNR"
In comparison, the direct string itself is 73 bytes:
"rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR"
SX, 65 bytes
我("""rnbqkbnr
pppppppp
"""+('.'*8+"\n")*4+"PPPPPPPP\nRNBQKBNR")
By the way, I am planning on making some radical changes to SX to make it better for code golfing.
Charcoal, 32 bytes
rnbkqbnr¶P×p⁸M⁵↓⁺×P⁸¶RNBKQBNRUB.
Explanation
rnbkqbnr¶ Print "rnbkqbnr\n"
P×p⁸ Print "p" * 8 without moving cursor
M⁵↓ Move cursor 5 characters down
⁺×P⁸¶RNBKQBNR Print "p" * 8 + "\nRNBKQBNR"
UB. Set background to '.'
Xasm, 944 Bytes
00000001 114
00000001 110
00000001 98
00000001 113
00000001 107
00000001 98
00000001 110
00000001 114
00000001 10
00000001 112
00000001 112
00000001 112
00000001 112
00000001 112
00000001 112
00000001 112
00000001 112
00000001 10
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 10
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 10
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 10
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 46
00000001 10
00000001 80
00000001 80
00000001 80
00000001 80
00000001 80
00000001 80
00000001 80
00000001 80
00000001 10
00000001 82
00000001 78
00000001 66
00000001 81
00000001 75
00000001 66
00000001 78
00000001 82
00000011
I just did this for novelty. I won't win shortest code but maybe longest! ^_^
Java 7, 103 99 89 bytes
String f(){return"rnbqkbnr\npppppppp\nxxxxPPPPPPPP\nRNBQKBNR".replace("x","........\n");}
10 bytes saved compared to hardcoded output thanks to @SLC's approach in his C# answer.
Output:
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Vim, 26 bytes
irnbqkbnr<Esc>Y6p5Vr.VrpYGPgUj
Relies on a fresh Vim, or else 5V may select the wrong area.
irnbqkbnr<Esc>: Write the top row. Easy enough.Y6p: Make the rest of the rows, except one. Of course all but the top and bottom rows contain the wrong characters.5Vr.: When you haven't used visual mode yet in the session, you can do things like this to select 5 lines. If you typed the same thing again right away, it would try to select 25 lines. Vim is weird like that.Vrp: We're already on line 2, so let's make a pawn line.YGP: Copy that pawn line into its place at the bottom. This is why I used6pinstead of7pbefore.gUj: Capitalize the white pieces.
GNU sed, 54 bytes
s:^:rnbqkbnr:p;h
s:.:p:gp;G
h;s:[^\n]:.:gp;G
s:.:\U&:g
Explanation:
The black pieces are printed first, saving the two associated board ranks in reverse order in the hold space. The white pieces are printed by converting the hold space to uppercase letters.
s:^:rnbqkbnr:p;h # change pattern and hold spaces to 'rnbqkbnr' and print string
s:.:p:gp # replace each pattern space letter with a 'p', then print
G;h # append hold space, then copy pattern space to hold space
s:[^\n]:.:gp # replace each pattern space letter with a '.', then print
G;s:.:\U&:g # append hold space and convert pattern space to uppercase
# (automatic printing of pattern space at the end)
q, 51 bytes
"\n"sv flip{x,"p...P","c"$("i"$x)-32}each"rnbqkbnr"
Python 2, 61 bytes
print'rnbqkbnr\npppppppp\n'+('.'*8+'\n')*4+'P'*8+'\nRNBQKBNR'
Very brute-force. The 'P'*8 is worth it on the right, but the left pppppppp is flanked by newlines that make it not worth doing as 'p'*8.
Python 3, 64 bytes
Based off DLosc answer to Python 2 as on mine I could not improve.
print(*["rnbqkbnr","p"*8]+["."*8]*4+["P"*8,"RNBQKBNR"],sep="\n")
1 byte less compared to using "\n".join
print("\n".join(["rnbqkbnr","p"*8]+["."*8]*4+["P"*8,"RNBQKBNR"]))
Jelly, 25 24 bytes
“.“.“p“rnbqkbn”ṁ€8µṚ;ŒuY
Thanks to @Lynn for golfing off 1 byte!
How it works
“.“.“p“rnbqkbn”ṁ€8µṚ;ŒuY Main link. No arguments.
“.“.“p“rnbqkbn” Yield [".", ".", "p", "rnbqkbnr"].
ṁ€8 Mold-each 8; reshape each string like the array
[1, 2, 3, 4, 5, 6, 7, 8], i.e., cyclically repeat its
contents to create strings of length 8.
This yields the upper half of the board in reversed
order, i.e., the string array
A := "........", "........", "pppppppp", "rnbqkbnr"].
µ Begin a new, monadic chain. Argument: A
Ṛ Reverse A.
Œu Convert all characters in A to uppercase.
; Concatenate the results to both sides.
Y Join the strings, separating by linefeeds.
C#, 94 92 bytes
Edit: Thanks to milk for saving 1 byte by changing string order to remove the return whitespace.
Edit: Saved 1 more byte by adding a dummy parameter (x instead of ()) for the anonymous function and calling it with any object.
x=>{string a="RNBQKBNR\n",b="PPPPPPPP\n",c="........\n";return(a+b).ToLower()+c+c+c+c+b+a;};
Full program using the above function:
using System;
namespace DrawAnASCIIChessBoard
{
class Program
{
static void Main(string[] args)
{
Func<object,string>f= x=>{string a="RNBQKBNR\n",b="PPPPPPPP\n",c="........\n";return(a+b).ToLower()+c+c+c+c+b+a;};
Console.WriteLine(f(1));
}
}
}
C# is a very verbose language...
C# full program, 131 bytes
class P{static void Main(){string a="rnbqkbnr\n",b="pppppppp\n",c="........\n";System.Console.Write(a+b+c+c+c+c+(b+a).ToUpper());}}
Ungolfed:
class P
{
static void Main()
{
string a="rnbqkbnr\n",
b="pppppppp\n",
c="........\n";
System.Console.Write(a+b+c+c+c+c+(b+a).ToUpper());
}
}
JavaScript (ES6), 69 65 bytes
Saved 4 bytes thanks to edc65
let f =
_=>`rnbqkbnr
p....PRNBQKBNR`.replace(/p|\./ig,c=>c.repeat(8)+`
`)
console.log(f());
Ruby, 45 44
1 byte saved thanks to tuxcrafting.
puts"rnbqkbnr",?p*8,[?.*8]*4,?P*8,"RNBQKBNR"
This is 45
puts s="rnbqkbnr",?p*8,[?.*8]*4,?P*8,s.upcase
Trying anything cleverer just seems to make it longer.
Vim, 50 strokes
qairnbqkbnr<enter><esc>8ip<esc><enter><esc>q3@a3ggqaVr.gqj@aj@aj@ajgU$jgU$
Golfed out 8 bits thanks to @DJMcMayhem
Emotinomicon, 89 bytes
Sadly Emotinomicon has nothing like an duplicate stack function. Would be usefull. But at least shorter than Java. :)
😭RNBKQBNR
PPPPPPPP
........
........
........
........
pppppppp
rnbkqbnr😲⏪⏬⏩
Explanation:
😭(...)😲⏪⏬⏩
😭(...)😲 String literal
⏪ ⏩ Loop
⏬ Pop one char and output
Bash, 73 bytes
e=........\\n
echo -e "rnbqkbnr\npppppppp\n$e$e$e${e}PPPPPPPP\nRNBQKBNR"
V, 27, 26 bytes
i¸P
RNBQKBNRäkgujddppÒ.4Ä
This contains some unprintable characters, so here is the readable version:
i¸P
RNBQKBNR<esc>äkgujddppÒ.4Ä
where <esc> represents 0x1B. Explanation:
i " Enter insert mode
¸P " Enter 8 'P' characters
" and a newline
RNBQKBNR<esc> " Enter the first row and escape to normal mode.
äk " Duplicate this line and the line above
guj " Convert this line, and the line below to lowercase
dd " Delete this line
pp " And paste it twice below us
Ò. " Replace this whole line with '.' chars
4Ä " And create four copies of this line
J, 55 52 bytes
'.rnbkqpPQKBNR'{~(+-@|.)8 8$1 2 3 4 5 3 2 1,8 48#6 0
Test and intermediate steps
'.rnbkqpPQKBNR'{~(+-@|.)8 8$1 2 3 4 5 3 2 1,8 48#6 0
rnbkqbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBKQBNR
8 48#6 0
6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 2 3 4 5 3 2 1,8 48#6 0
1 2 3 4 5 3 2 1 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8 8$1 2 3 4 5 3 2 1,8 48#6 0
1 2 3 4 5 3 2 1
6 6 6 6 6 6 6 6
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
(+-@|.)8 8$1 2 3 4 5 3 2 1,8 48#6 0
1 2 3 4 5 3 2 1
6 6 6 6 6 6 6 6
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
_6 _6 _6 _6 _6 _6 _6 _6
_1 _2 _3 _4 _5 _3 _2 _1
'.rnbkqpPQKBNR'{~(+-@|.)8 8$1 2 3 4 5 3 2 1,8 48#6 0
rnbkqbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBKQBNR
Jolf, 32 bytes
pη++γͺ"rnbqkbnr"*8'p*²*8'.6ΜγdBH
I oughta remake this language soon... Try it here!
Bonus: all-ascii version:
pη++on~."rnbqkbnr"*8'p*~:*8'.6ΜndBH
Explanation
pη++γͺ"rnbqkbnr"*8'p*²*8'.6ΜγdBH
ͺ pair
"rnbqkbnr" this string
*8'p and 8 p's
γ (call this γ)
+ add that with
*8'. 8 .'s
² wrapped in an array
* 6 repeated 6 times
+ add THAT with
Μγd γ mapped over
BH the uppercase version of H
pη and join all this with newlines
Brainfuck, 224 bytes
+++++[>+++[>++++++<-]+<-]>>.[>>+>+<<<-]>>>[<<<+>>>-]<<<----.<+++[>---<-]>.>>-.------.<<.>>+++.++++.--<++++++++++>>++++++++++.<........>.[>+++++<-]>----<++++[>........<<<.>>-]<........<.>++.----.<<.>>+++.------.<<.>>+++.++++.
Took almost an hour to get this.
Japt, 37 bytes
[A="rnbqkbnr"B='pp8 C='.p8 CCCBu Au]·
I really oughta remake this language soon... Test it online!
How it works
[ ] // Wrap all of the following in an array:
A="rnbqkbnr" // A = "rnbqkbnr",
B='pp8 // B = 8 "p"s,
C='.p8 // C = 8 periods,
CCC // 3 more copies of C,
Bu // B.toUpperCase(),
Au // and A.toUpperCase().
· // Join everything with newlines and implicitly print.
PowerShell v2+, 44 bytes
'rnbqknbr'
'p'*8
,('.'*8)*4
'P'*8
'RNBQKNBR'
Strings left on the pipeline are implicitly printed with Write-Output at program execution. We couple that with the default newline behavior for an array to produce the four lines of periods with the comma-operator.
PS C:\Tools\Scripts\golfing> .\draw-ascii-chess-board.ps1
rnbqknbr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKNBR
05AB1E, 24 bytes
Uses CP-1252 encoding.
"rnbqkbnr"'p8×'.8×D)Âu«»
Explanation
"rnbqkbnr" # push the string "rnbqkbnr"
# STACK: "rnbqkbnr"
'p8× # push the char "p" repeated 8 times
# STACK: "rnbqkbnr", "pppppppp"
'.8× # push the char "." repeated 8 times
# STACK: "rnbqkbnr", "pppppppp", "........"
D # duplicate
# STACK: "rnbqkbnr", "pppppppp", "........", "........"
) # wrap in list
# STACK: ["rnbqkbnr", "pppppppp", "........", "........"]
 # push a reversed copy of the list
# STACK: ["rnbqkbnr", "pppppppp", "........", "........"],
["........", "........", "pppppppp", "rnbqkbnr"]
u« # convert to upper-case and concatenate
# STACK: ['rnbqkbnr', 'pppppppp', '........', '........',
'........', '........', 'PPPPPPPP', 'RNBQKBNR']
» # join list by newline
PHP, 67 64 63 62 bytes
Note: uses IBM-850 encoding.
<?=~str_pad(ìæØÄöØæì§ÅÅÅÅÅÅÅÅ,54,§ÐÐÐÐÐÐÐÐ)?>PPPPPPPP
RNBQKBNR
Run like this:
echo '<?=~str_pad(ìæØÄöØæì§ÅÅÅÅÅÅÅÅ,54,§ÐÐÐÐÐÐÐÐ)?>PPPPPPPP
RNBQKBNR' | php 2>/dev/null;echo
And in "unencoded" form:
echo '<?=str_pad("rnbqkbnr\npppppppp",54,"\n........"),"PPPPPPPP\nRNBQKBNR";' | php 2>/dev/null;echo
Explanation
Unfortunately I couldn't find a more interesting approach (that actually saves bytes) than to just print the string, except for the 4 middle lines which are repeated using str_repeatstr_pad.
Tweaks
- Saved 3 bytes by replacing
str_repeatwithstr_pad. - Saved a byte by using closing tag, thx to user59178.
- Saved a byte by changing the pad string to start with a newline, so last newline can be dropped from the first argument of
str_pad
MATL, 26 bytes
'rnbqkbnr' 'p..'!l8X"vtPXk
Explanation
'rnbqkbnr' % Push this string (1×8 char array)
'p..'! % Push this string transposed (3×1 char array)
l8X" % Repeat 1×8 times: gives 3×8 char array
v % Concatenate the two arrays vertically into a 4×8 char array
tP % Duplicate and flip vertically
Xk % Convert to uppercase. Implicitly display the two 4×8 arrays
JavaScript (ES6), 73
.toUpperCase is simply too long
_=>`rnbqkbnr
${r=c=>c[0].repeat(8)+`
`,r`p`+(b=r`.`)+b+b+b+r`P`}RNBQKBNR`
O.textContent=(
_=>`rnbqkbnr
${r=c=>c[0].repeat(8)+`
`,r`p`+(b=r`.`)+b+b+b+r`P`}RNBQKBNR`
)()
<pre id=O></pre>
Powershell, 82 73 bytes
$x=("rnbqkbnr",$("p"*8),$("."*8),$("."*8));$x+$x[3..0].ToUpper()-join"`n"
R, 75 bytes
Edit: Fixed a silly error and simply write out the uppercase part of the board now.
cat("rnbqkbnr\npppppppp\n",rep("........\n",4),"PPPPPPPP\nRNBQKBNR",sep="")
Batch, 105 bytes
@set e=@echo ........
@echo rnbqkbnr
@echo pppppppp
%e%
%e%
%e%
%e%
@echo PPPPPPPP
@echo RNBQKBNR
Batch is seriously verbose...
Pyke, 28 27 26 bytes
"rnbqkbnr"i"P..p"1c8m*Xil3
I learned something new about my language today: 1c can be used as a 2 char way of splitting a string into a list of characters.
"rnbqkbnr"i - i = "rnbqkbnr"
stack = ["rnbqkbnr"])
"P..p"1c - chunk("P..p", 1)
stack = ["rnbqkbnr", ["P", ".", ".", "p"]]
8m* - map(8*>, ^)
stack = ["rnbqkbnr", ["PPPPPPPP", "........", "........", "pppppppp"]]
X - splat(^)
stack = ["rnbqkbnr", "pppppppp", "........", "........", "PPPPPPPP"]
il3 - i.changecase()
stack = ["rnbqkbnr", "pppppppp", "........", "........", "PPPPPPPP", "RNBQKBNR"]
- implicit join with newlines
rnbqkbnr
pppppppp
........
........
PPPPPPPP
RNBQKBNR
Dart, 62 bytes
f()=>"rnbqkbnr\n${"p"*8}\n${"........\n"*4+"P"*8}\nRNBQKBNR";
I am annoyed that I can't reduce the "........\n"*4 part further, but due to the newline being included in the multiplication, all rewrites come out at the same length as the original:
"${"."*8}\n"*4
("."*8+"\n")*4
"........\n"*4
Dart's string functions, like toUpperCase(), have too long names to use them in golfing.
IBM/Lotus Notes Formula, 69 bytes
A:="rnbqkbnr";B:="pppppppp";C:="........";A:B:C:C:C:C:@Uppercase(B:A)
Formula in a multi-value field with newline as the seperator.
Output:
Python 2, 68 bytes
Posting anyway although the above Python 2 version is shorter. It would not have to be a one liner for the amount of bytes, just played with it.
x,y,z="rnbqkbnr\n","p"*8+"\n","."*8+"\n";print x,y,4*z,(y+x).upper()
Python 2, 63 bytes
print"\n".join(["rnbqkbnr","p"*8]+["."*8]*4+["P"*8,"RNBQKBNR"])
Unfortunately, the fairly simple approach was much shorter than the "clever" stuff I tried at first...
Bonus answer, also 63 bytes:
print"\n".join(["rnbqkbnr"]+[c*8for c in"p....P"]+["RNBQKBNR"])
Haskell, 53 bytes
a="rnbkqbnr"
unlines$a:map(<$a)"p....P"++["RNBKQBNR"]
a is used as the first line and to determine the length of strings made of p, . and P (-> <$a). .
Cheddar, 56 bytes
a=['rnbqkbnr','p'*8]+['.'*8]*2->(a+a.rev=>@.upper).vfuse
Uses the new => feature.
Explanation
a= // set a to the first half
['rnbqkbnr','p'*8] + // First two rows
['.'*8]*2 // Next two dots
->(
a +
a.rev=>@.upper // Reverse and map all items to uppercase
).vfuse // Join on newlines
Actually, 26 bytes
'p8*"rnbqkbnr"│û@û4'.8*n((
Explanation:
'p8*"rnbqkbnr"│û@û4'.8*n((
'p8* "p"*8 ["pppppppp"]
"rnbqkbnr" that string ["rnbqkbnr", "pppppppp"]
│ duplicate stack ["rnbqkbnr", "pppppppp", "rnbqkbnr", "pppppppp"]
û@û uppercase the dupes ["RNBQKBNR", "PPPPPPPP", "rnbqkbnr", "pppppppp"]
4 '.8*n "."*8, 4 times ["RNBQKBNR", "PPPPPPPP", "........", "........", "........", "........", "rnbqkbnr", "pppppppp"]
(( move the uppercase strings to the bottom of the stack, implicitly print


