46
\$\begingroup\$

Here is a simple challenge for you: You must produce this ASCII representation of a chess board. White is represented by uppercase characters, and black is represented by lowercase. Empty tiles are represented by a .. Here is the full board:

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

Since this is a question, you may not take any input and you must output this board by any default method, for example, saving a file, printing to STDOUT or returning from a function. You may optionally produce one trailing newline. Standard loopholes apply, and the shortest program in bytes!

However, remember this is equally as much a competition between submissions in the same language. While it's unlikely that a languages like Java could beat a language like perl, or a golfing language like pyth or cjam, having the shortest Java answer is still really impressive! To help you track the shortest answer in each language, you may use this leaderboard, which will show the shortest submission by language and overall.

Leaderboards

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=95745,OVERRIDE_USER=31716;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Surely an ASCII art chess board would have the full stop every other square? \$\endgroup\$ Sep 9, 2019 at 9:55

96 Answers 96

3
\$\begingroup\$

Vyxal L, 17 bytes

«æ≠⁺tO«ƛ`p..`+Ḃ⇧+

Try it Online!

-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.
\$\endgroup\$
1
3
\$\begingroup\$

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.

  • a for append, to switch into input mode until a sole dot
  • s for substitute, with parameters /RegExp/replacement/flags where the flag g here means all occurrences (instead of default first only)
  • t initialy means transfer and is put for copy (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)
  • x for xit and is put for exit (the letter E was already used to edit a file)

That's all.

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Jan 4 at 17:22
  • \$\begingroup\$ Thanks. It's always funny to do such things within an editor. I wish people can try it online too. \$\endgroup\$
    – gildux
    Jan 4 at 17:32
2
\$\begingroup\$

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:

enter image description here

\$\endgroup\$
2
\$\begingroup\$

Batch, 105 bytes

@set e=@echo ........
@echo rnbqkbnr
@echo pppppppp
%e%
%e%
%e%
%e%
@echo PPPPPPPP
@echo RNBQKBNR

Batch is seriously verbose...

\$\endgroup\$
2
\$\begingroup\$

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="")
\$\endgroup\$
3
  • 1
    \$\begingroup\$ The black pieces come out wrong as this stands: the pawns should be in front of the other pieces. \$\endgroup\$
    – JDL
    Oct 10, 2016 at 8:45
  • \$\begingroup\$ @JDL You're of course correct, thanks. Silly mistake when doing last second changes. \$\endgroup\$
    – Billywob
    Oct 10, 2016 at 9:00
  • \$\begingroup\$ 71 using newlines instead of \n \$\endgroup\$
    – Giuseppe
    Sep 10, 2019 at 13:50
2
\$\begingroup\$

///, 52 bytes

/:/........
/rnbqkbnr
pppppppp
::::PPPPPPPP
RNBQKBNR

Try it online!

\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

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"]))
\$\endgroup\$
2
\$\begingroup\$

q, 51 bytes

"\n"sv flip{x,"p...P","c"$("i"$x)-32}each"rnbqkbnr"
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can shave off a few bytes with upper, and each-right. Also the following prints to stdout rather than returning a string with newlines: -1 flip"p...P"{y,x,upper y}/:"rnbqkbnr";. 40 bytes. Nice solution though! \$\endgroup\$
    – mkst
    Jul 19, 2017 at 16:18
2
\$\begingroup\$

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.

Try it here.

Output:

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
\$\endgroup\$
2
  • \$\begingroup\$ What about this String f(){return"rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR";}.This is 100 bytes. \$\endgroup\$
    – Numberknot
    Oct 11, 2016 at 8:40
  • \$\begingroup\$ @Numberknot How boring.. but you're right, it is shorter. Btw, it's 99 bytes, not 100. \$\endgroup\$ Oct 11, 2016 at 8:53
2
\$\begingroup\$

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));
        }
    }
}
\$\endgroup\$
5
  • \$\begingroup\$ Hi, welcome to PPCG! Hmm, the order of your pieces seems incorrect with the one of OP. Btw, you can save 1 byte by removing the space between return ", so it becomes: x=>{return"rnbqkbnr\npppppppp\nxxxxPPPPPPPP\nRNBQKBNR".Replace("x","........\n");};. Nice answer, so +1 from me. And enjoy your stay here. :) \$\endgroup\$ Oct 11, 2016 at 11:53
  • \$\begingroup\$ And thanks for your answer. I've ported the same approach to my Java 7 answer (of course crediting you), lowering the byte-count by 10. :) \$\endgroup\$ Oct 11, 2016 at 12:01
  • \$\begingroup\$ I have improved it further \$\endgroup\$
    – NibblyPig
    Oct 11, 2016 at 12:10
  • \$\begingroup\$ Gah I just realised that's not right \$\endgroup\$
    – NibblyPig
    Oct 11, 2016 at 12:13
  • 1
    \$\begingroup\$ Nice approach! You can actually reduce it to 74 bytes: x=>"rnbqkbnr\npppppppp\nxxxxRNBQKBNR\nPPPPPPPP".Replace("x","........\n"); \$\endgroup\$
    – adrianmp
    Oct 11, 2016 at 12:23
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to PPCG! I don't think you actually need the arguments to main though? \$\endgroup\$ Oct 11, 2016 at 18:54
  • \$\begingroup\$ I don't think you need main instead of just f, which is the only reason I beat you (that and you print two extra ........ lines) \$\endgroup\$
    – S.S. Anne
    Feb 5, 2020 at 0:33
2
\$\begingroup\$

Python 3, 60 bytes

print('rnbqkbnr','p'*8,*['.'*8]*4,'P'*8,'RNBQKBNR',sep='\n')
\$\endgroup\$
2
  • \$\begingroup\$ I get an error with this: SyntaxError: only named arguments may follow *expression \$\endgroup\$
    – lbragile
    Dec 1, 2019 at 2:21
  • \$\begingroup\$ What version of python are you using? This only works in python 3.x. \$\endgroup\$ Dec 2, 2019 at 11:56
2
\$\begingroup\$

C, 97 bytes

char *e="........\n";main(){printf("rnbqkbnr\npppppppp\n%s%s%s%sPPPPPPPP\nRNBQKBNR\n",e,e,e,e);}
\$\endgroup\$
5
  • \$\begingroup\$ You do not need to specify the #include (at least for gcc), nor the return-type of main or the void parameter. This shaves quite a few chars: main(){char*e="........\n";printf("RNBKQBNR\nPPPPPPPP\n%s%s%s%spppppppp\nrnbkqbnr\n",e,e,e,e);} (100 bytes) \$\endgroup\$
    – tucuxi
    Oct 11, 2016 at 10:31
  • \$\begingroup\$ Good to know for golfing thank you. \$\endgroup\$ Oct 12, 2016 at 4:10
  • \$\begingroup\$ It's only 90 bytes like this e="........\n";main(){printf("rnbqkbnr\npppppppp\n%s%s%s%sPPPPPPPP\nRNBQKBNR\n",e,e,e,e); \$\endgroup\$
    – cleblanc
    Oct 12, 2016 at 19:46
  • \$\begingroup\$ That code would not compile. Variable e needs a type (char *) and main is missing a } at the very end. But you are right that I could remove the "void" \$\endgroup\$ Oct 13, 2016 at 23:46
  • \$\begingroup\$ I think I beat you. \$\endgroup\$
    – S.S. Anne
    Feb 5, 2020 at 0:31
2
\$\begingroup\$

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.

\$\endgroup\$
0
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

Japt, 23 bytes

`rnbqkbnr`y+"p.."
y_+Ôu

Test it

`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
\$\endgroup\$
2
\$\begingroup\$

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.

Try it online!

C (gcc), 92 bytes

f(){puts("rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR");}

When not overthinking it, this is the best solution.

Try it online!

\$\endgroup\$
1
2
\$\begingroup\$

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

Try it online

\$\endgroup\$
2
\$\begingroup\$

StupidStackLanguage, 159 bytes

avvqimqvdflfqwwddflqiiifqwdfbblfbflfavvflddfffffffflfqvvvvvvvifffffffflflfffffffflflfffffffflflfffffffflflvvvvvvvdfffffffflfliifqwifqwwddfbldfldddfwwifvviifbif

Try it online!

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.

\$\endgroup\$
2
\$\begingroup\$

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"])
\$\endgroup\$
2
  • \$\begingroup\$ Welcome to the site! Nice first answer. \$\endgroup\$ Nov 27, 2020 at 19:28
  • \$\begingroup\$ The second program doesn't work because map is lazy in Python 3. \$\endgroup\$
    – xigoi
    Aug 22, 2021 at 7:39
2
\$\begingroup\$

K (ngn/k), 28 26 bytes

-2 bytes from @ngn's improvements

|a,_|a:+"RNBQKBNR",\:"P.."

Try it online!

  • "RNBQKBNR",\:"P.." prepend each of "RNBQKBNR" to "P.."
  • a:+ tranpose this, storing in variable a. 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
\$\endgroup\$
2
  • \$\begingroup\$ Oops, fixed (adding 1 byte). \$\endgroup\$
    – coltim
    Sep 6, 2021 at 23:54
  • 1
    \$\begingroup\$ -2: |a,_|a:+"RNBQKBNR",\:"P.." \$\endgroup\$
    – ngn
    Sep 7, 2021 at 18:33
1
\$\begingroup\$

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.
\$\endgroup\$
1
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

Bash, 73 bytes

e=........\\n
echo -e "rnbqkbnr\npppppppp\n$e$e$e${e}PPPPPPPP\nRNBQKBNR"
\$\endgroup\$
1
1
\$\begingroup\$

Vim, 50 strokes

qairnbqkbnr<enter><esc>8ip<esc><enter><esc>[email protected]@aj@aj@ajgU$jgU$

Golfed out 8 bits thanks to @DJMcMayhem

\$\endgroup\$
1
  • \$\begingroup\$ A couple tips: 1) you could do <esc>8ip<esc> instead of pppppppp. 2) You could do Vr. or 8r. instead of :s/./\./ \$\endgroup\$
    – DJMcMayhem
    Oct 10, 2016 at 13:26
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Really cool that you were able to shave off more bytes, the *6 should be *4 but that won't change anything. \$\endgroup\$
    – DomPar
    Oct 10, 2016 at 23:28
1
\$\begingroup\$

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! ^_^

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.