Draw an ASCII chess board!

44

3

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>

James

Posted 2016-10-10T02:40:27.473

Reputation: 54 537

1Surely an ASCII art chess board would have the full stop every other square? – Shaun Bebbers – 2019-09-09T09:55:07.200

Answers

16

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 used 6p instead of 7p before.
  • gUj: Capitalize the white pieces.

udioica

Posted 2016-10-10T02:40:27.473

Reputation: 2 381

1Best golf language there is! – ceased to turn counterclockwis – 2016-10-12T17:30:18.397

15

Jelly, 25 24 bytes

“.“.“p“rnbqkbn”ṁ€8µṚ;ŒuY

Try it online!

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.

Dennis

Posted 2016-10-10T02:40:27.473

Reputation: 196 637

11

Brainfuck, 224 bytes

+++++[>+++[>++++++<-]+<-]>>.[>>+>+<<<-]>>>[<<<+>>>-]<<<----.<+++[>---<-]>.>>-.------.<<.>>+++.++++.--<++++++++++>>++++++++++.<........>.[>+++++<-]>----<++++[>........<<<.>>-]<........<.>++.----.<<.>>+++.------.<<.>>+++.++++.

Took almost an hour to get this.

Hunter VL

Posted 2016-10-10T02:40:27.473

Reputation: 321

9

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"])

DLosc

Posted 2016-10-10T02:40:27.473

Reputation: 21 213

I improved this with Python 3 unpack syntax: https://codegolf.stackexchange.com/a/196543/2212

– JBernardo – 2019-12-01T02:47:56.460

8

05AB1E, 24 bytes

Uses CP-1252 encoding.

"rnbqkbnr"'p8×'.8×D)Âu«»

Try it online!

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

Emigna

Posted 2016-10-10T02:40:27.473

Reputation: 50 798

2I think this is the FIRST time I've ever golfed an answer without looking and matched you on 100% of the characters used. Gotta agree this is as good as it gets haha. – Magic Octopus Urn – 2017-02-10T20:23:30.510

I realize this might not have been available when you posted it, but -2 by compressing the string to .•jÒ°\Ö• and another -2 by using the list-prepend š like this: …p..S8×.•jÒ°\Ö•šÂu«». Or alternatively: …p...•jÒ°\Ö•š8δ∍Âu«».

– Kevin Cruijssen – 2020-02-05T12:25:41.120

Based on my second solution above, here also a 23 byter without the compressed string that most likely was also possible when you posted your solution: "rnbqkbnr"'p'.D)8δ∍Âu«» (@MagicOctopusUrn)

– Kevin Cruijssen – 2020-02-05T12:34:45.883

7

Actually, 26 bytes

'p8*"rnbqkbnr"│û@û4'.8*n((

Try it online!

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

Mego

Posted 2016-10-10T02:40:27.473

Reputation: 32 998

6

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

Downgoat

Posted 2016-10-10T02:40:27.473

Reputation: 27 116

5So you answered a question about 'chess' in 'ches'? – James – 2016-10-10T02:51:39.823

4@DJMcMayhem .................. did you just..... – Downgoat – 2016-10-10T02:52:27.290

1mm this is some beautiful cheese. nice abuse of default params – Conor O'Brien – 2016-10-10T03:03:28.217

6

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.

Level River St

Posted 2016-10-10T02:40:27.473

Reputation: 22 049

Remove the space before the string after the puts – TuxCrafting – 2016-10-10T17:33:34.960

6

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());
    }
}

adrianmp

Posted 2016-10-10T02:40:27.473

Reputation: 1 592

2"C# is a very verbose language...". You haven't tried VB.NET then... ;) – TyCobb – 2016-10-10T17:06:14.000

2You can save a byte by defining a and b as uppercase then you can get rid of the space after return: return(a+b).ToLower()+... – milk – 2016-10-10T19:15:51.817

@TyCobb I tried VB.NET quite some time ago. I didn't know about code golfing back then :P – adrianmp – 2016-10-10T19:42:28.280

can you use var instead of string ? – NibblyPig – 2016-10-11T11:27:28.213

@SLC I haven't programmed in C# for a while, so correct me if I'm wrong, but I don't think you can use var with multiple declarations on a single line. So string a="rnbqkbnr\n",b="pppppppp\n",c="........\n"; would become var a="rnbqkbnr\n";var b="pppppppp\n";var c="........\n";, which increases the byte-count. EDIT: It would give an "An implicitly typed local variable declaration cannot include multiple declarators" error.

– Kevin Cruijssen – 2016-10-11T12:07:03.753

@KevinCruijssen Exactly! You can't use var for declaring multiple variables simultaneously. – adrianmp – 2016-10-11T12:13:34.643

6

Pyke, 28 27 26 bytes

"rnbqkbnr"i"P..p"1c8m*Xil3

Try it here!

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

Blue

Posted 2016-10-10T02:40:27.473

Reputation: 26 661

6

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

Arnauld

Posted 2016-10-10T02:40:27.473

Reputation: 111 334

1Very clever! Maybe too clever, could save 4 bytes with 'rnbqkbnrnp....PRNBQKBNR'.replace(/p|\./ig,c=>c.repeat(8)+'\n') (change \n to a literal newline) – edc65 – 2016-10-10T19:35:56.543

5

MATL, 26 bytes

'rnbqkbnr' 'p..'!l8X"vtPXk

Try it online!

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

Luis Mendo

Posted 2016-10-10T02:40:27.473

Reputation: 87 464

5

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

AdmBorkBork

Posted 2016-10-10T02:40:27.473

Reputation: 41 581

Where are the new lines in the lines of points? " ,('.'8)4" it is the ',' I suppose... – RosLuP – 2016-10-11T15:48:39.807

@RosLuP The comma-operator ,, creates an array (in this case, an array of strings). The default Write-Output at program completion inserts a newline between elements left on the pipeline, including individual array elements. So, we're abusing the default output behavior to not need to write explicit newlines in the code. – AdmBorkBork – 2016-10-11T15:52:06.850

4

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

nimi

Posted 2016-10-10T02:40:27.473

Reputation: 34 639

4

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

DomPar

Posted 2016-10-10T02:40:27.473

Reputation: 61

Since z is only used once you can get rid of it and produce the dots in the print statement. – Karl Napf – 2016-10-14T01:59:17.637

4

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>

edc65

Posted 2016-10-10T02:40:27.473

Reputation: 31 086

I think (r=c=>c[0].repeat(8)+\n,b=r.)=> saves you a byte. – Neil – 2016-10-10T08:43:07.207

@Neil I don't see the saving. I tried to rewrite the code increasing readibility (a little), but the byte count stay the same – edc65 – 2016-10-10T09:23:21.537

Ah, I see what I did wrong there, somehow I lost a newline along the way. Sorry about that. – Neil – 2016-10-10T09:45:48.950

4

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

Roman Gräf

Posted 2016-10-10T02:40:27.473

Reputation: 2 915

Hmm... that would be a useful function, now wouldn't it... – Conor O'Brien – 2016-10-14T01:00:06.207

1Even the program is sad. = Sadly – None – 2019-09-13T06:16:57.613

4

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]

xnor

Posted 2016-10-10T02:40:27.473

Reputation: 115 687

3

J, 34 bytes

(tolower,|.)4 8$'RNBQKBNR',8#'P..'

Try it online!

FrownyFrog

Posted 2016-10-10T02:40:27.473

Reputation: 3 112

3

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.

Commodore 128 BASIC listing of PETSCII art chess board VIC-20 PETSCII chess board simulator

Shaun Bebbers

Posted 2016-10-10T02:40:27.473

Reputation: 1 814

3

V, 27, 26 bytes

i¸P
RNBQKBNRäkgujddppÒ.4Ä

Try it online!

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

James

Posted 2016-10-10T02:40:27.473

Reputation: 54 537

3

Brain-Flak, 366 350 + 3 = 353 bytes

Try it online!

(((((((((((()()())){}(((({}))){}{}(([((({})){}){}](([({}())](((((({}()){}){}){}()){})<>))<>)<>)<>)))<<>({}<>)<>({}<>)<>({}<>)([]()())>[()]))))))))(()()()()){({}[()]<((((((((((((()()()()()){})()){}()){}))))))))>)}{}(((()()()()()){})<((((((((([][]()()()()))))))))<>)<>>)(((((()()()))){})(({}{})(([{}({})](([{}()](<>({}()())<>)<>)<>)<>)<>))){<>({}<>)}{}

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.

(((()()()()()){})<((((((((([][]()()()()))))))))<>)<>>)(((()()()){})(({}()()())(([{}(()()())](([{}()](<>({}()())<>)<>)<>)<>)<>))){<>({}<>)}{}

Post Rock Garf Hunter

Posted 2016-10-10T02:40:27.473

Reputation: 55 382

You can push the first two lines with ((((((((((((((((((((()()()()()){}){}){}()){})[()()()()])[([][][]){}])[][][])[]()())[[][][]])[][])()()()())<([]()())>[()()])))))))) which I think would save you 16 bytes. This doesn't use the alternate stack at all, so it could probably be even shorter. – James – 2017-10-19T17:40:06.863

3

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

zawata

Posted 2016-10-10T02:40:27.473

Reputation: 141

1Welcome to the site! You could take two bytes off if you remove some extra spaces. E.g. [:8]for i in['rnbqkbn'.... – James – 2016-10-12T02:14:20.083

1Nice idea with unifying all the lines and reusing the rooks. You can write the list shorter as 'rnbqkbn p . . . . P RNBQKBN'.split(). – xnor – 2016-10-12T02:23:20.333

@DJMcMayhem didn't know those weren't necessary. thanks! – zawata – 2016-10-12T06:02:26.020

@xnor that is a great idea! ill have to add that trick to my "arsenal" haha – zawata – 2016-10-12T06:02:32.130

2

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.

user65167

Posted 2016-10-10T02:40:27.473

Reputation:

2

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!

Albert Renshaw

Posted 2016-10-10T02:40:27.473

Reputation: 2 955

You may remove ==0 from the first ternary and swap the return arguments to save 3 bytes – Ahemone – 2017-02-15T04:36:21.237

@Ahemone oh you're right! Rookie mistake haha – Albert Renshaw – 2017-02-15T05:06:41.917

1101 bytes – ceilingcat – 2019-04-24T21:49:42.097

2

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.

Kjetil S.

Posted 2016-10-10T02:40:27.473

Reputation: 1 049

2

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.

me'

Posted 2016-10-10T02:40:27.473

Reputation: 451

2

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

Conor O'Brien

Posted 2016-10-10T02:40:27.473

Reputation: 36 228

2

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

Kade

Posted 2016-10-10T02:40:27.473

Reputation: 7 463

2

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="")

Billywob

Posted 2016-10-10T02:40:27.473

Reputation: 3 363

1The black pieces come out wrong as this stands: the pawns should be in front of the other pieces. – JDL – 2016-10-10T08:45:31.517

@JDL You're of course correct, thanks. Silly mistake when doing last second changes. – Billywob – 2016-10-10T09:00:06.857

71 using newlines instead of \n – Giuseppe – 2019-09-10T13:50:53.930

2

Powershell, 82 73 bytes

$x=("rnbqkbnr",$("p"*8),$("."*8),$("."*8));$x+$x[3..0].ToUpper()-join"`n"

Chris J

Posted 2016-10-10T02:40:27.473

Reputation: 199

59 bytes – Veskah – 2019-07-08T19:56:24.533

@Veskah - how does that work? I've not seen the *per thing before, and a google isn't giving me any pointers. Have an explanation? – Chris J – 2019-07-09T22:08:40.850

Check here for the full writeup but |% can call properties/methods (with wildcards in the name) on what it's given – Veskah – 2019-07-10T00:39:34.230

2

Batch, 105 bytes

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

Batch is seriously verbose...

Neil

Posted 2016-10-10T02:40:27.473

Reputation: 95 035

2

GNU sed, 54 bytes

s:^:rnbqkbnr:p;h
s:.:p:gp;G
h;s:[^\n]:.:gp;G
s:.:\U&:g

Try it online!

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)

seshoumara

Posted 2016-10-10T02:40:27.473

Reputation: 2 878

2

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

Kevin Cruijssen

Posted 2016-10-10T02:40:27.473

Reputation: 67 575

What about this String f(){return"rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR";}.This is 100 bytes. – Numberknot – 2016-10-11T08:40:00.993

@Numberknot How boring.. but you're right, it is shorter. Btw, it's 99 bytes, not 100. – Kevin Cruijssen – 2016-10-11T08:53:21.793

2

C, 97 bytes

char *e="........\n";main(){printf("rnbqkbnr\npppppppp\n%s%s%s%sPPPPPPPP\nRNBQKBNR\n",e,e,e,e);}

Matthew Greci

Posted 2016-10-10T02:40:27.473

Reputation: 41

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) – tucuxi – 2016-10-11T10:31:41.933

Good to know for golfing thank you. – Matthew Greci – 2016-10-12T04:10:55.027

It's only 90 bytes like this e="........\n";main(){printf("rnbqkbnr\npppppppp\n%s%s%s%sPPPPPPPP\nRNBQKBNR\n",e,e,e,e); – cleblanc – 2016-10-12T19:46:46.537

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" – Matthew Greci – 2016-10-13T23:46:21.143

I think I beat you. – S.S. Anne – 2020-02-05T00:31:19.697

2

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"]))

DomPar

Posted 2016-10-10T02:40:27.473

Reputation: 61

2

q, 51 bytes

"\n"sv flip{x,"p...P","c"$("i"$x)-32}each"rnbqkbnr"

Boston Walker

Posted 2016-10-10T02:40:27.473

Reputation: 141

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! – streetster – 2017-07-19T16:18:38.780

2

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

NibblyPig

Posted 2016-10-10T02:40:27.473

Reputation: 141

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. :) – Kevin Cruijssen – 2016-10-11T11:53:04.307

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. :)

– Kevin Cruijssen – 2016-10-11T12:01:09.990

I have improved it further – NibblyPig – 2016-10-11T12:10:53.607

Gah I just realised that's not right – NibblyPig – 2016-10-11T12:13:45.717

1Nice approach! You can actually reduce it to 74 bytes: x=>"rnbqkbnr\npppppppp\nxxxxRNBQKBNR\nPPPPPPPP".Replace("x","........\n"); – adrianmp – 2016-10-11T12:23:00.557

2

Python 3, 60 bytes

print('rnbqkbnr','p'*8,*['.'*8]*4,'P'*8,'RNBQKBNR',sep='\n')

Tim Shaffer

Posted 2016-10-10T02:40:27.473

Reputation: 21

I get an error with this: SyntaxError: only named arguments may follow *expression – lbragile – 2019-12-01T02:21:35.227

What version of python are you using? This only works in python 3.x. – Tim Shaffer – 2019-12-02T11:56:04.580

2

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.

Lord Ratte

Posted 2016-10-10T02:40:27.473

Reputation: 111

1

Python 3, 83 Bytes

t="rnbqkbnr"
n="\n"
print((t)+n+("p"*8)+n+(("."*8+"\n")*4)+n+("P"*8)+n+(t.upper()))

Juntos

Posted 2016-10-10T02:40:27.473

Reputation: 41

2Welcome to the site! Some improvements I see: a lot of your parenthesis are redundant. Also, you used "\n" somewhere you could have used n – James – 2016-11-22T17:23:31.707

1

SmileBASIC, 52 bytes

?"rnbqkbnr
?"p"*8?("."*8+CHR$(10))*4;"P"*8?"RNBQKBNR

12Me21

Posted 2016-10-10T02:40:27.473

Reputation: 6 110

1

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

Chaos Manor

Posted 2016-10-10T02:40:27.473

Reputation: 521

1

Japt -R, 28 bytes

`rnbqkbnr p . .`¸m!î8
cUmu w

Test it

Oliver

Posted 2016-10-10T02:40:27.473

Reputation: 7 160

1

Keg, 43+1 40 39 37 bytes

rnbqkbnr
∑p)
(4|`.`8*
)(8|P)
RNBQKBNR

Try it online!

Answer History

39 bytes

rnbqkbnr
(8|p)
(4|`.`8*
)(8|P)
RNBQKBNR

Try it online!

40 bytes

rnbqkbnr
(8|p)
(4|(8|\.)
)(8|P)
RNBQKBNR

Try it online!

-4 bytes due to fixing a bug. That's new.

44 bytes

rnbqkbnr\
(8|p)\
(4|(8|\.)\
)(8|P)\
RNBQKBNR

Try it online!

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

Lyxal

Posted 2016-10-10T02:40:27.473

Reputation: 5 253

1

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

Try it online!

Explanation

Fn.new{          // New function
       "rnbqkbnr
"                // rnbqkbnr\n
+"p"*8           // pppppppp
+"
"                // \n
+("."*8          // ........
       +"
"                // \n
)*4              // above strings 4 times
   +"P"*8        // PPPPPPPP
         +"
RNBQKBNR"        // \nRNBQKBNR
}

user85052

Posted 2016-10-10T02:40:27.473

Reputation:

1

Python 3, 66 64 bytes

64 bytes:

print('rnbqkbnr','p'*8,('.'*8+'\n')*4,'P'*8,'RNBQKBNR',sep='\n')

Logic:

  1. Pieces remain the same as previously
  2. pawns and dots get repeated 8 times
  3. "." is appended a new line and the whole thing is repeated 4 times.
  4. entire print is separated with sep='\n'

66 bytes:

print('\n'.join(['rnbqkbnr']+[i*8for i in 'p....P']+['RNBQKBNR']))

Logic:

  1. create the piece arrays as is at first and last positions.
  2. create the middle 6 rows by list comprehension - using repetition i*8.
  3. Sum the lists to get 8 elements
  4. Join elements with a line break in between (\n)
  5. print()

Output:

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

lbragile

Posted 2016-10-10T02:40:27.473

Reputation: 111

1

I based my answer on original python 2 from years ago, but I see yours is quite similar except you didn't unpack the middle dots with Python 3.5+ syntax: https://codegolf.stackexchange.com/a/196543/2212

– JBernardo – 2019-12-01T02:43:54.937

1

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

JBernardo

Posted 2016-10-10T02:40:27.473

Reputation: 1 659

1

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

Embodiment of Ignorance

Posted 2016-10-10T02:40:27.473

Reputation: 7 014

1

C++ , 189 bytes v2 - compiles now

#include <iostream>
#define _E "........"<< '\n'<<
#define _F <<'\n'<<"........"<< '\n'<<

int main()
{
 std::cout << "rnbqkbnr" _F"pppppppp"_F _E _E _E _E "PPPPPPPP"_F"RNBQKBNR;";
}

Georgiy Chipunov

Posted 2016-10-10T02:40:27.473

Reputation: 11

Hello and welcome to PPCG. Could you possibly add your C++ version and compiler you used so that one can verify your solution? – Jonathan Frech – 2020-02-04T09:51:58.140

You can shorten it by reusing ........\n and #import<ios> and no newlines and no return 0; and using f instead of main. – S.S. Anne – 2020-02-05T00:28:59.847

yes theres is def some good revisions, also its like 10-11 ish C++ in version, try to also add more #define pppppp, can change to ppp char *p = ""; upper function can't use because need more lib. honestly I didn't know if this compiled when I submit. – Georgiy Chipunov – 2020-02-09T03:42:25.357

1

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!

S.S. Anne

Posted 2016-10-10T02:40:27.473

Reputation: 1 161

Your to-the-point 92 byte version could be 89: Try it online.

– Kevin Cruijssen – 2020-02-25T14:29:58.197

1

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

Ian Poe

Posted 2016-10-10T02:40:27.473

Reputation: 11

1

JavaScript (Babel Node), 89 81 bytes

console.log("rnbqkbnr\npppppppp\n"+"........\n".repeat(4)+"PPPPPPPP\nRNBQKBNR\n")

Try it online!

Sarreph

Posted 2016-10-10T02:40:27.473

Reputation: 111

1You know that ........ is shorter than ${'.'.repeat(8)}, right? – manatwork – 2020-02-25T10:53:58.750

:O, oops thanks manatwork! Edited... – Sarreph – 2020-02-25T13:27:14.227

1

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

Conor O'Brien

Posted 2016-10-10T02:40:27.473

Reputation: 36 228

1

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

ElPedro

Posted 2016-10-10T02:40:27.473

Reputation: 5 301

1

///, 52 bytes

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

Try it online!

Erik the Outgolfer

Posted 2016-10-10T02:40:27.473

Reputation: 38 134

1

Vim, 50 strokes

qairnbqkbnr<enter><esc>8ip<esc><enter><esc>q3@a3ggqaVr.gqj@aj@aj@ajgU$jgU$

Golfed out 8 bits thanks to @DJMcMayhem

永劫回帰

Posted 2016-10-10T02:40:27.473

Reputation: 131

A couple tips: 1) you could do <esc>8ip<esc> instead of pppppppp. 2) You could do Vr. or 8r. instead of :s/./\./ – James – 2016-10-10T13:26:32.593

1

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

rnso

Posted 2016-10-10T02:40:27.473

Reputation: 1 635

I count 7 '.' Not 8 '.' – RosLuP – 2016-10-11T15:05:46.670

Thanks for pointing out the error. I have corrected the code. I had missed the fact that each line has 9 characters (8 dots and 1 newline) and not 8. – rnso – 2016-10-11T16:18:36.273

Count the figure: 64+7 nl + 11 I count something as 81 or 82 – RosLuP – 2016-10-11T18:35:20.497

Its 82. I forgot to correct the byte count after correcting the code. – rnso – 2016-10-12T02:49:45.457

1

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.

ETHproductions

Posted 2016-10-10T02:40:27.473

Reputation: 47 880

1You too? – Conor O'Brien – 2016-10-14T00:11:18.640

1

Bash, 73 bytes

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

Matthew Greci

Posted 2016-10-10T02:40:27.473

Reputation: 41

65 bytes – GammaFunction – 2019-09-09T20:55:40.357

1

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.

xnor

Posted 2016-10-10T02:40:27.473

Reputation: 115 687

Really cool that you were able to shave off more bytes, the *6 should be *4 but that won't change anything. – DomPar – 2016-10-10T23:28:10.573

1

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'

Croer01

Posted 2016-10-10T02:40:27.473

Reputation: 11

You have to include the console.log(a) in your byte count, so this is 78 bytes. Welcome to PPCG! – Mego – 2016-10-11T01:22:25.863

1

CJam, 29 28 bytes

"rnbqkbnr"{"p.."+_W%eu+}%zN*

Try it online!


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

Linus

Posted 2016-10-10T02:40:27.473

Reputation: 1 948

1

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

XiKuuKy

Posted 2016-10-10T02:40:27.473

Reputation: 369

1

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

ASCII-only

Posted 2016-10-10T02:40:27.473

Reputation: 4 687

Does this have a custom code page? – Conor O'Brien – 2016-10-14T00:10:29.953

@ConorO'Brien Yes, but it's undocumented and requires a flag right now, so I have no idea if it counts – ASCII-only – 2016-10-14T00:21:20.017

I mean, that should be fine. That's how the file is read. – Conor O'Brien – 2016-10-14T00:48:24.977

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.

m-chrzan

Posted 2016-10-10T02:40:27.473

Reputation: 1 390

1

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.

XiKuuKy

Posted 2016-10-10T02:40:27.473

Reputation: 369

1

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(); })();

Bladimir Ruiz

Posted 2016-10-10T02:40:27.473

Reputation: 151

Wish i was better at ES6 D: – Bladimir Ruiz – 2016-10-11T14:03:47.253

1

Here are a few tips to get you started: 1) You don't need to call the function, just define it; you also don't need the braces around it, nor the semicolon: (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()) 2) You can replace "\n" with a literal newline between backticks, as shown here. 3) "........" is shorter than ".".repeat(8) (same with "pppppppp").

– ETHproductions – 2016-10-11T15:26:15.663

More tips: 4) In an arrow function without braces, a value is automatically returned, so you don't even need console.log. 5) t.split("") can be shortened to [...t], and .join("") to .join``. View the golfed version here. You can look through the Tips for golfing in ES6 thread for even more tips.

– ETHproductions – 2016-10-11T15:37:15.640

"p".repeat(8) would be 13 chats... It is better "pppppppp" 10 chars – RosLuP – 2016-10-11T18:28:19.953

1

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.

CSM

Posted 2016-10-10T02:40:27.473

Reputation: 219

Welcome to PPCG! I don't think you actually need the arguments to main though? – Martin Ender – 2016-10-11T18:54:09.017

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) – S.S. Anne – 2020-02-05T00:33:44.450

1

Pyth, 41 35 34 33 Bytes

K*z\p8J"rnbqkbnr"JKp*+*\.8b4rK1rJ1

Golfed a byte thanks to @daHugLenny

Try It Online

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

Dignissimus - Spammy

Posted 2016-10-10T02:40:27.473

Reputation: 449

You can replace "p" with \p. – acrolith – 2016-10-14T19:26:51.233

1

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

BNik

Posted 2016-10-10T02:40:27.473

Reputation: 11

1

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

corvus_192

Posted 2016-10-10T02:40:27.473

Reputation: 1 889

0

tcl, 86

proc R {s n\ 8} {string repe $s $n}
puts rnbqkbnr\n[R p]\n[R [R .]\n 4][R P]\nRNBQKBNR

demo

sergiol

Posted 2016-10-10T02:40:27.473

Reputation: 3 055

0

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

BradC

Posted 2016-10-10T02:40:27.473

Reputation: 6 099

0

Japt -R, 25 bytes

"rnbqkbnr"¬m+'.²ip)®+ÔuÃÕ

Test it

"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

Shaggy

Posted 2016-10-10T02:40:27.473

Reputation: 24 623

0

Zsh, 69 65 bytes

69bytes   try it online!!

build array, print it forwards, print it backwards+lowercase

D=........ X=(RNBQKBNR PPPPPPPP $D $D);printf %s\\n $X ${(Oa)X:l}

roblogic

Posted 2016-10-10T02:40:27.473

Reputation: 554

0

brainfuck, 248 bytes

There is probably a better way to do this.

++++++++++[>+>+++++++++++>++++++++>++++++++++>+++++<<<<<-]>>++++>>-->----<<<.----.>>.<<+++.------.>>.<<+++.++++.<.>--........<.>>>>>++++++[<........<<<<.>>>>>-]<<<........<<.>>++.----.------------.+++++++++++++++.------.---------.++++++++++++.++++.

Try it online!

The random guy

Posted 2016-10-10T02:40:27.473

Reputation: 1 262

0

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"

for Monica

Posted 2016-10-10T02:40:27.473

Reputation: 1 172

0

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.

lrn

Posted 2016-10-10T02:40:27.473

Reputation: 521

0

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_repeat str_pad.

Tweaks

  • Saved 3 bytes by replacing str_repeat with str_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

aross

Posted 2016-10-10T02:40:27.473

Reputation: 1 583

It looks to me like you can save a byte by changing ,~»»»»»»»»§¡▒¢«┤¢▒¡; to ?>PPPPPPPP\nRNBQKBNR (use an actual newline character) and making use of the fact that php just prints anything outside of the tags – user59178 – 2016-10-10T10:34:08.377

0

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.

ilkkachu

Posted 2016-10-10T02:40:27.473

Reputation: 181

0

SQL, 146 Bytes

declare @ char(8)='rnbqkbnr'
print 'pppppppp'
print '........'
print '........'
print '........'
print '........'
print 'PPPPPPPP'
print upper(@)

datagod

Posted 2016-10-10T02:40:27.473

Reputation: 151

This doesn't appear to print the first (lowercase) row. – BradC – 2019-09-09T16:35:40.417

I'd rather reuse ........ and then you can do the whole upper/lower thing if that saves any (probably not). – S.S. Anne – 2020-02-05T00:30:14.960

0

Microscript II, 56 bytes

"rnbqkbnr\npppppppp"P"........"PPPP"PPPPPPPP\nRNBQKBNR"

SuperJedi224

Posted 2016-10-10T02:40:27.473

Reputation: 11 342