65
\$\begingroup\$

...will you help me immortalize it?

enter image description here

I've had this pillow a few years now, and apparently it's time to get rid of it. Can you please write a function or program, that I can bring with me and use to recreate this pillow whenever I want to reminisce a bit.

It must work with no input arguments.

The output should look exactly like this (trailing newlines and spaces are OK).

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////

This is code golf, so the shortest code in bytes win!


Leaderboard

var QUESTION_ID=98701,OVERRIDE_USER=31516;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\$
  • 7
    \$\begingroup\$ I'm somewhat disappointed that the pattern isn't a little more complex, to represent the different line thicknesses of the pillow. \$\endgroup\$ – Sparr Nov 6 '16 at 11:29
  • 4
    \$\begingroup\$ @Sparr I tried, but I didn't manage to make it look good using only ASCII characters. Figured this was close enough :) \$\endgroup\$ – Stewie Griffin Nov 6 '16 at 11:37
  • 3
    \$\begingroup\$ I'd have just added spaces \$\endgroup\$ – Sparr Nov 6 '16 at 20:37
  • 1
    \$\begingroup\$ 'apparently' :P \$\endgroup\$ – Pysis Nov 7 '16 at 19:01
  • 7
    \$\begingroup\$ Now you can buy a blank pillow and print the winner snippet on it. \$\endgroup\$ – coredump Nov 7 '16 at 19:46

65 Answers 65

24
\$\begingroup\$

05AB1E, 18 15 bytes

Code:

„/\5×{4Å6×»6F=R

Explanation:

„/\               # Push the string "/\"
   5×             # Repeat 5 times: "/\/\/\/\/\"
     {            # Sort, resulting in: "/////\\\\\"
      4Å6         # Create a list of 6's with length 4: [6, 6, 6, 6]
         ×        # Vectorized string multiplication
          »       # Join by newlines
           6F     # Do the following six times..
             =    #   Print with a newline without popping
              R   #   Reverse the string

Uses the CP-1252 encoding. Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ Wow... two different takes, same byte count... \$\endgroup\$ – Oliver Ni Nov 6 '16 at 14:00
3
\$\begingroup\$

Canvas, 10 9 bytes

/54*╬6×3*

Try it here!

Explanation:

/          push "/"
 54*       extend horizontally 5 times and vertically 4 times
    ╬      quad-palindromize with 0 overlap
     6×    repeat horizontally 6 times
       3*  and again vertically, 3 times
\$\endgroup\$
1
\$\begingroup\$

Jstx, 21 bytes

♣/►\:►/;1BO♠/♦/!41o16

Not the shortest solution but I wanted to try this interesting challenge.

Explanation

♣  # Push literal 5
/  # Enter an iteration block over the first stack value.
►\ # Push literal \
:  # Push the sum of the second and first stack values.
►/ # Push literal /
;  # Push the difference of the second and first stack values.
1  # End an iteration block.
B  # Push five copies of the first stack value.
O  # Collapse all stack values into a string, then Push that string.
♠  # Push literal 6
/  # Enter an iteration block over the first stack value.
♦  # Push literal 4
/  # Enter an iteration block over the first stack value.
!  # Push a copy of the first stack value.
4  # Print the first stack value, then a newline.
1  # End an iteration block.
o  # Push the first stack value with characters in reverse order.
1  # End an iteration block.
6  # Ends program execution.

Try it online!

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

Excel (loaded with VBA), 70 62 bytes

Formula for each cell (A4 through BH27):

=IF(SIN(COLUMN()*0.62)*SIN(ROW()*0.8)>0,"\","/")

I'm not sure how to score this and I couldn't find a consensus. It's a 48 byte pure Excel formula, the same in every cell (but of course the fact that it should be in a particular range is also information). It takes 62 bytes to load it by executing this in the VBA Immediate window.

[A4:BH27]="=IF(SIN(COLUMN()*.62)*SIN(ROW()*.8)>0,""\"",""/"")" 

Output

Output

\$\endgroup\$
  • \$\begingroup\$ Saved 8 bytes by realizing I don't need .Formula in the VBA \$\endgroup\$ – Sophia Lechner Mar 30 '18 at 23:30
0
\$\begingroup\$

Pyth, 21 20 bytes

J*6S*5"/\\"V6V4J)=_J

Try it online!

Python 3 translation:
J=6*sorted(5*"/\\")
for N in range(6):
    for N in range(4):
        print(J)
    J=J[::-1]
\$\endgroup\$
30
\$\begingroup\$

///, 116 bytes

/a/\\\\\\\\\\\\\\\///b/\\\\\\\\\\\\\\\\//A/aaaaa//B/bbbbb//C/ABABABABABAB
//D/BABABABABABA
/CCCCDDDDCCCCDDDDCCCCDDDD

Try it online!

Edit: the \\\\\\\\\\\\\\\/ and \\\\\\\\\\\\\\\\ are actually a single / and \, respectively.

Edit: -3 because I thought of removing i. I think this can't be further golfed.

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

SOGL V0.12, 11 bytes

└5*5∙╬¡6*3∙

Try it Here!

Explanation:

└            push "/"
 5*          repeat 5 times
   5∙        repeat vertically 5 times
     έ      quad-palindromize with 0 overlap and mirroring characters
       6*    multiply 6 times horizontally
         3∙  multiply 3 times vertically
\$\endgroup\$
0
\$\begingroup\$

Python 2, 83 55 bytes

x=('/'*5+'\\'*5)*6;print((x+'\n')*4+(x[::-1]+'\n')*4)*3

Try it online!

-28 bytes thanks to Leaky Nun

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

T-SQL, 113 bytes

DECLARE @ INT=0L:IF @%8<4PRINT REPLICATE('/////\\\\\',6)ELSE PRINT REPLICATE('\\\\\/////',6)SET @+=1IF @<24GOTO L

Formatted:

DECLARE @ INT=0
L:
   IF @%8<4 PRINT REPLICATE('/////\\\\\',6)
   ELSE PRINT REPLICATE('\\\\\/////',6)
   SET @+=1
IF @<24 GOTO L

Using both string literals seems to be the shortest option, trying to REPLICATE(REPLICATE('/',5)+REPLICATE('\',5) is way longer, as is using additional variables.

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

R, 72 bytes

write(matrix(c(x<-rep(rep(c('/','\\'),e=5),24),rev(x)),24,60),'',60,,'')

builds a matrix of appropriate characters and writes it to stdout.

Try it online!

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

tcl, 97

proc r s\ n {string repe $s $n}
puts [r [r [r /////[r \\ 5] 6]\n 4][r [r [r \\ 5]///// 6]\n 4] 3]

My try to outgolf myself didn't go well :( :

tcl, 102

proc r s\ n {string repe $s $n}
proc R s\ t {r [r [r $s 5][r $t 5] 6]\n 4}
puts [r [R / \\][R \\ /] 3]

runnable on: http://rextester.com/live/HURDH99224

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

Ruby, 83 + 14 = 97 bytes

puts Zlib.inflate Base64.decode64"eNrTB4EYECCdxTVENSP4pLOGqubhE8+j8Twaz6PxDAA3Pofw"

Add 14 bytes for -rzlib and -rbase64 flags.

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

Perl, 51 50 bytes

Perl 5.10.0+:

perl -E 'say+((@_=("/"x5,"\\"x5)x6,$/)x4,(pop@_,@_,$/)x4)x3'

Perl before 5.10.0 (52 bytes):

perl -e 'print+((@_=("/"x5,"\\"x5)x6,$/)x4,(pop@_,@_,$/)x4)x3'

Ungolfed:

say(
    (
        (
            @_ = ('/' x 5, '\\' x 5) x 6,
            $/,  # new line symbol
        ) x 4,
        (
            pop(@_),
            @_,
            $/,
        ) x 4,
    ) x 3
);

Thanx to @DomHastings for 1 byte.

\$\endgroup\$
  • 2
    \$\begingroup\$ Didn't think to use an array to store the slashes, nice! You can save 1 byte dropping the outermost () and prepend +: perl -E 'say+((@_=('/'x5,'\\'x5)x6,$/)x4,(pop@_,@_,$/)x4)x3' \$\endgroup\$ – Dom Hastings Nov 7 '16 at 12:45
3
\$\begingroup\$

PHP, 142 124 bytes

<?=str_replace(['#','-'],['/////','\\\\\\\\\\'],wordwrap(str_repeat(str_repeat("#-",24).str_repeat("-#",24), 4),12,"\n",1));

Previous version:

<?for($i=1;$i<4;$i++)echo wordwrap(str_repeat("/////\\\\\\\\\\",24),60,"\n",1)."\n".wordwrap(str_repeat("\\\\\\\\\\/////",24),60,"\n",1)."\n";

Output:

C:\PHP\>php this-is-my-pillow.php
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////
\$\endgroup\$
2
\$\begingroup\$

Dyalog APL, 20 bytes

'/\'[4⌿5/2|+/¨⍳6 12] (requires ⎕IO=0)

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

Lithp, 166 characters

Line split for readability.

#::((def x #S,N::(invoke S repeat N))(var A (x "/" 5))(var B (x "\\" 5))
(var C (+ (x (+ A B) 6) (nl)))(var D (+ (x (+ B A) 6) (nl)))
(print (x (+ (x C 4) (x D 4)) 5)))

Sample usage:

% pillow.lithp
(
    (def f #::((def x #S,N::(invoke S repeat N))(var A (x "/" 5))(var B (x "\\" 5))(var C (+ (x (+ A B) 6) (nl)))(var D (+ (x (+ B A) 6) (nl)))(print (x (+ (x C 4) (x D 4)) 5))))
    (f)
)

Run with:

./run.js pillow.lithp

This is a fairly simple solution that repeats characters. There is no standalone repeat function yet, so invoke is used to call "string".repeat(N) and adds a bit to the count.

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

C++ 138

void P(){int i,j,k,l;for(i=0;i<3;i++)for(j=0;j<8;j++)for(k=0;k<12;k++)for(l=0;l<5;l++)cout<<((j/4)?(k%2)?'/':'\\':(k%2)?'\\':'/')<<'\n';} 

Ungolfed

#include<conio.h>
#include<iostream>
using namespace std;

void P()
{
    int i,j,k,l;
    for(i=0;i<3;i++)
        for(j=0;j<8;j++)
            for(k=0;k<12;k++)
                for(l=0;l<5;l++)
                    cout<<((j/4)?(k%2)?'/':'\\':(k%2)?'\\':'/')<<'\n';
}

int main()
{
    P();
    _getch();
    return 0;
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Why braces on the second for loop? \$\endgroup\$ – pinkfloydx33 Nov 6 '16 at 20:56
  • \$\begingroup\$ edited @pinkfloydx33 \$\endgroup\$ – Mukul Kumar Nov 9 '16 at 22:38
5
\$\begingroup\$

V, 22 21 bytes

Edit One byte won, thanks @DjMcMayhem:

5á\5á/05ä$4Ä5x$p4Ä3ä}

Changes are:

  • Y4P -> Use V duplicate line instead of Vim built-in command (this will add a blank line at the end of the paragraph)
  • 3äG -> 3ä} Duplicate the paragraph instead of the whole buffer (to avoid blank line generated by previous change)

Original post

5á\5á/05ä$Y4P5x$p4Ä3äG

Try it online

Decomposed like this:

5á\                    Write 5 \
   5á/                 Write 5 / after
      0                Go to the beginning of the line
       5ä$             Copy the text to the end of the line and repeat it 5 times
          Y4P          Copy the line and create 4 new copies
             5x$p      Delete the 5 first characters and put them at the end of the line
                 4Ä    Duplicate this line
                   3äG Duplicate the whole text
\$\endgroup\$
  • \$\begingroup\$ It's cool to see someone else using V! Up until recently, it's only been me. If you ever need help with it, feel free to ping me in the nineteenth byte \$\endgroup\$ – DJMcMayhem Nov 9 '16 at 15:39
  • \$\begingroup\$ @DrMcMoylex Yup your language seems fun to use :-) I had a problem on this one: initially I wanted to use 5á\5á/05ä$5Ä5x$p4Ä3äG i.e. replace Y4P by but for a reason that I don't understand it copies an additional blank line... If you can enlighten me on this one it would be nice. Also if I find some free time i'd gladly contribute to the language (especially issue #4) \$\endgroup\$ – statox Nov 9 '16 at 15:45
  • \$\begingroup\$ Ah, yes that has troubled me many times. It's a known issue. The problem is that Ä is a synonym for dd, not Y. This is usually not an issue, but it causes some problems if the buffer has only one line or if you're on the last line. \$\endgroup\$ – DJMcMayhem Nov 9 '16 at 15:48
  • \$\begingroup\$ Actually, I just realized, that approach would still work if you replaced 3äG with 3ä} since it won't yank that last newline. v.tryitonline.net/… \$\endgroup\$ – DJMcMayhem Nov 9 '16 at 15:49
  • \$\begingroup\$ Ok I think I get why it didn't work now. And nice way to win 1 byte, thanks! \$\endgroup\$ – statox Nov 9 '16 at 15:56
1
\$\begingroup\$

Julia, 56 bytes

a="////\\\\\\\\"^6*"\n";print((a^4*a[[48:-1:1,49]]^4)^3)
\$\endgroup\$
6
\$\begingroup\$

Brainfuck, 179 bytes

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

I know this isn't the best score in the thread but I wanted to try out brainfuck and give this a try.

Edit: I must've made an error while copypasting. This version should work

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! \$\endgroup\$ – DJMcMayhem Nov 7 '16 at 19:02
  • \$\begingroup\$ Does not work for me. Browser hang up with this interpreter, and personnal one show a non expected 5 line output: /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ four times, then infinite \ . \$\endgroup\$ – aluriak Nov 8 '16 at 23:34
  • \$\begingroup\$ Yes, it works :) \$\endgroup\$ – aluriak Feb 26 '17 at 22:47
3
\$\begingroup\$

Brainfuck, 168 bytes

++++++[>++++++++<-]>-<+++++++++[>>++++++++++<<-]>>++<<+++++[>>>++<<<-]>>>>+++[>++++[>++++++[<<<<<.....>.....>>>>-]<<<.>>-]++++[>++++++[<<<<.....<.....>>>>>-]<<<.>>-]<-]
\$\endgroup\$
2
\$\begingroup\$

MATLAB, 58 44 bytes

Thanks to @Stewie Griffin for saving a bunch of bytes ;)

[repmat(kron(['/\';'\/'],ones(4,5)),3,6),'']

Old version:

p=@()char(47+45*kron(ones(3,6),kron([0 1;1 0],ones(4,5))))

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

Powershell, 77 bytes

I must say I thought this would be easier with PowerShell, but it's quite hard to create something more condense than this.

$a=@("/","\");"$(1..6|%{1..3|%{1..6|%{$a[$b]*5;$a[!$b]*5};"rn"}; $b=!$b})"

More readable:

$a=@("/","\")
"$(1..6|%{
    1..3|%{ 
     1..6|%{
     $a[$b]*5
     $a[!$b]*5
        }
     "`r`n"}
    $b=!$b})"

I'm using the index numbers of the array in order to decide whether I should put \ or / and between every loop I simply toggle the variable.

\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG! I get your logic, but it doesn't seem to work quite right. With the code as-is, you're going to get a bunch of Index operation failed; the array index evaluated to null. errors since $b is uninitialized on the first inner loop of 1..6. Additionally, this will join the strings you're creating with spaces, since that's the default $OutputFieldSeparator when stringifying an array (what you're doing here). \$\endgroup\$ – AdmBorkBork Nov 8 '16 at 20:06
  • \$\begingroup\$ Additionally, you don't need both r and n -- just n will work for newlines. You've also got an extra space between ; and $b=. \$\endgroup\$ – AdmBorkBork Nov 8 '16 at 20:08
  • \$\begingroup\$ Must be ISE messing with me again. The host retains variables between each run, that's what got me here. Dammit. \$\endgroup\$ – Chavez Nov 8 '16 at 21:15
  • \$\begingroup\$ You can fix the array index by putting a + in front -- like $a[+$b] -- to force a cast to int. However, that doesn't eliminate the spaces between elements. :-/ \$\endgroup\$ – AdmBorkBork Nov 8 '16 at 21:31
6
\$\begingroup\$

Python 2.7 66 -> 56 -> 55 bytes

a="/"*5+"\\"*5;b=a[::-1];c=6*a+"\n";d=6*b+"\n";e=4*c+4*d;print e*3

new to code golfing

a="/"*5+"\\"*5;print(4*(6*a+"\n")+4*(6*a[::-1]+"\n"))*3

Thanks Stewie Griffin

Forgot a silly whitespace ;)

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to PPCG! Nice first answer :) Can you skip some of the intermediate variables? At least d and e, maybe more. I haven't tested this, but it should be close: print(4*c+4*(6*b+"\n"))*3. It's 5 bytes less. \$\endgroup\$ – Stewie Griffin Nov 7 '16 at 13:40
  • 3
    \$\begingroup\$ 55 bytes: a="/"*5+"\\"*5;print(4*(6*a+"\n")+4*(6*a[::-1]+"\n"))*3 \$\endgroup\$ – Stewie Griffin Nov 7 '16 at 13:44
6
\$\begingroup\$

Brainfuck, 149 bytes

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

The best interpreter EVAR!

This uses 6 cells (no wrapping, no modulo). Here they are:

0A 00 2F 00 5C 00

The 00 cells are used for the loop counters. Here, the counters are filled in with initial values:

0A 06 2F 04 5C 03

The leftmost counter is for the innermost loop (yes, I use nested loops of depth 3). Please note that the 4th cell (04 counter) is used twice, once for /////\\\\\..., and once for \\\\\/////... every time.

0A, 2F and 5C are the characters \n, / and \, respectively.

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

Pyth, 49 48 40 37 34 bytes

J60K*24+*5\/*5\\V24:*3+K_K*JN+J*JN

OK, I'm just learning Pyth so this is a direct port of my Python answer. Still a lot of golfing to do but it works so I am posting it anyway. Any hints gratefully received :)

1 byte saved with thanks to @Flp.Tkc

-8 by working out how to do it with a variable

-3 by moving the *24 to the assignment of K

-3 by getting rid of the quotes

\$\endgroup\$
  • 1
    \$\begingroup\$ I've never tried pyth apart from looking at the docs once or twice, but I think you can replace FN24 with V24 \$\endgroup\$ – FlipTack Nov 6 '16 at 12:37
  • \$\begingroup\$ Nice. Just tested and it works. Will check the docs on that. \$\endgroup\$ – ElPedro Nov 6 '16 at 12:39
6
\$\begingroup\$

Python 2, 86 80 76 74 73 bytes

for z in range(24):a=('/'*5+'\\'*5)*24;print((a+a[::-1])*3)[z*60:z*60+60]

Could probably golf a few more off it but it's a start.

Edit

Saved 6 by removing some unneeded brackets

Another 4 by using a single string and then reversing it

Thanks @Adnan. Had a late night last night and still not fully awake yet :p

-1 by moving the *24 to the variable instead of using it twice

\$\endgroup\$
  • 4
    \$\begingroup\$ I believe that *6*4 is the same as *24? :p \$\endgroup\$ – Adnan Nov 6 '16 at 9:38
12
\$\begingroup\$

05AB1E, 15 bytes

„/\5×{R6×6FR4F=

Try it online!

Explanation:

„/\             # Push "/\"
   5×           # Repeat string five times: "/\/\/\/\/\"
     {          # Sort: "/////\\\\\"
      R         # Reverse: "\\\\\/////
       6×       # Repeat string six times
         6F     # Repeat the following six times:
           R    #   Reverse
            4F  #   Repeat the following four times:
              = #     Print without popping

Uses the CP-1252 encoding.

\$\endgroup\$
5
\$\begingroup\$

Pyth, 22 bytes

V6V4V12p*5?%+bN2\\\/)k

Try it here.

Explanation:

V6                     Loop 6 times, with N from 0 to 5:
  V4                   Loop 4 times, with H from 0 to 3:
    V12                Loop 12 times, with b from 0 to 11:
      p                Print without newline
        *              The repetition
          5            5 times of
          ?            if
            %          the remainder
              + b N    when the sum of b and N
              2        is divided by 2
          \\           then the "\" character
          \/           else the "/" character
    )                  End
                       (implicitly print with newline)
  k                    k (empty string)
                       (implicit end)
                       (implicit end)

Sorry if the explanation is a little hard to understand, but it was kinda complicated.

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

Befunge-98, 76 bytes

'/\::2%0`!\4c*/2%0`!-> #0 #\ #\' $ #\_\3k:4k,1+:c%0`!> #0 #, #a_:cad+*\`!#@_

TryItOnline!

String processing/generation can be difficult with only a stack available...

A couple bytes may be able to be shaved off here or there, but I beat brainfuck, so I'm happy.

Explanation

Push '/' on the stack
Swap top two (at the beginning, zero will now be on top). Call top = iterator = n
Calculate (n % 2 == 0) != ((n / 48) % 2 == 0)
If true, swap top two, replace '/' with '\', swap again
Swap top two (so that we now have the character to print on top, followed by n)
Duplicate the char 4 times, and print 5 times
Increment n
If n % 12 == 0, print a newline character
If !(288 > n), end, else repeat
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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