73
\$\begingroup\$

Challenge

I need help building a brick wall! Throw together some code for me using no input and produce the following output wall shown below:

_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

Now, this wall is exactly 10 characters high and 70 characters wide.

As stated above, no inputs, only code. Least amount of bytes, we have to efficiently build this brick wall. Obviously, this program has to function to get the wall built..? or it obviously won't build itself! Good luck!


Winner

The winner goes to Marinus using the APL language, requiring a whole 12 bytes! https://codegolf.stackexchange.com/a/99028/61857


Thank you everyone for participating!

\$\endgroup\$
  • 2
    \$\begingroup\$ Related, Related, \$\endgroup\$ – FlipTack Nov 8 '16 at 18:42
  • 8
    \$\begingroup\$ Also Related. (odd that this should come up today, haha) \$\endgroup\$ – Conor O'Brien Nov 8 '16 at 18:43
  • 1
    \$\begingroup\$ That's OK. I'll let you know when I have a working interpreter. I'm working on it right now, actually :) \$\endgroup\$ – ETHproductions Nov 10 '16 at 14:20
  • 2
    \$\begingroup\$ Related! \$\endgroup\$ – RudolfJelin Nov 10 '16 at 17:49
  • 30
    \$\begingroup\$ For bonus points, make Mexico pay for it. \$\endgroup\$ – Dawood ibn Kareem Nov 11 '16 at 8:26

86 Answers 86

2
\$\begingroup\$

R, 78 bytes

    strwrap(gsub('(.{70})','\\1 ',paste(rep('___|',175),collapse='')),70)

How?

    x=paste(rep('___|',175),collapse='')   #Creates string on 1 line
    y=gsub('(.{70})','\\1 ',x)             #Adds spaces every 70 characters
    z=strwrap(y,70)                        #Creates a new line every space
    z                                      #Print the finished product
\$\endgroup\$
2
\$\begingroup\$

C, 61 bytes

TCC Version

main(i){for(;i+699;)printf("\n%c"+(--i%70||!i),"___|"[i&3]);}

GCC Version

main(i){for(;i+699;)printf("\n%c"+(i%70||!i),"___|"[--i&3]);}
\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! \$\endgroup\$ – DJMcMayhem Nov 11 '16 at 17:29
2
\$\begingroup\$

Befunge-93, 42 bytes

:4%1g,1+:"F"%!#v_0#@_
_|__~>:+#5,#:4#<1g*`^

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ Nice answer. Welcome to the site! \$\endgroup\$ – DJMcMayhem Nov 12 '16 at 1:43
2
\$\begingroup\$

Retina, 23 21 20 bytes


175$*_

_|_
!`.{70}

Try it online

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

Python 3, 40 bytes

p="_|__"*17
print((p+"_|\n__"+p+"\n")*5)
\$\endgroup\$
1
\$\begingroup\$

Python 2, 50 48 bytes

for b in range(10):print('_|__'*175)[b*70:][:70]

2 saved with thanks to @xnor but also thanks to @Shebang for the suggestion :)

\$\endgroup\$
  • 1
    \$\begingroup\$ b*70+70 -> -~b*70 saves a byte :) \$\endgroup\$ – Kade Nov 8 '16 at 18:33
  • 2
    \$\begingroup\$ Or [b*70:][:70]. \$\endgroup\$ – xnor Nov 8 '16 at 18:34
  • \$\begingroup\$ Thanks @xnor. Didn't know you could do that. may well go back and trim a couple off some of my other recent answers :) \$\endgroup\$ – ElPedro Nov 8 '16 at 18:41
1
\$\begingroup\$

Jolf, 17 bytes

RZc*"_|__"Τ755@FS

Try it here!

Explanation

RZc*"_|__"Τ755@FS
   *"_|__"         repeat this string:
          Τ755      7*5*5 = 175 times
 Zc           @F   chop into groups of 70 (F's charcode)
R               S  join by newlines
\$\endgroup\$
1
\$\begingroup\$

SOML, 16 bytes

_|__”’ø*L{:jjp»»

explanation:

_|__”             push "_|__"
     ’ø           push 18
       *          repeat the "_|__" 18 times
        L{        repeat 10 times:
          :       duplicate the sting
           jj     pop the last 2 letters off
             p    output it
              »»  put the last 2 characters at the start
\$\endgroup\$
1
\$\begingroup\$

GolfSharp, 38 bytes

c(r(175).s(n=>"_|__").j().S(70).j(N));
\$\endgroup\$
  • \$\begingroup\$ is it this language? \$\endgroup\$ – aloisdg Oct 25 '18 at 19:37
  • \$\begingroup\$ @aloisdg it is fellow typo corrector! You warmed my heart \$\endgroup\$ – downrep_nation Oct 25 '18 at 20:18
1
\$\begingroup\$

Pyth, 24 23 22 bytes

VT:*175"_|__"J*70N+70J

OK, I'm still learning. Any hints gratefully received :)

Edit

Saved a byte by moving the assignment of J to first use

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

Racket 159 bytes

(let p((n 2)(x 0)(t 0)(d display))(when(> x 69)(d"\n")(set! x 0))(cond[(> t 699)
(d"\n")][(> n 2)(d"|")(p 0(+ 1 x)(+ 1 t)d)][(d"_")(p(+ 1 n)(+ 1 x)(+ 1 t)d)]))

Ungolfed:

(define (f)
  (let loop ((n 2)   (x 0)   (t 0)  (d display))

    (when (> x 69)  (d "\n")
                    (set! x 0))
    (cond
      [(> t 699)    (d "\n")]

      [(> n 2)      (d "|")
                    (loop    0    (+ 1 x) (+ 1 t) d)]

      [else         (d "_")
                    (loop (+ 1 n) (+ 1 x) (+ 1 t) d)]
      )))

Testing:

(f)

Output:

_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
\$\endgroup\$
1
\$\begingroup\$

Ruby, 89 80 77 76 72 53 47 42 Bytes

puts (%w[___]*176*?|)[2..-1].scan(/.{70}/)

Demo:

>> puts (%w[___]*176*?|)[2..-1].scan(/.{70}/)
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

Update: I didn’t see there’s already an answer with 30 bytes.

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

PHP, 46 bytes

<?=wordwrap(str_repeat('_|__',175),70,"\n",1);

Output:

C:\PHP>php build-me-a-brick-wall.php
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
\$\endgroup\$
  • \$\begingroup\$ I think wordwrap()'s 3rd parameter should be "\n" as this currently keeps the string unwrapped in PHP 5.6. \$\endgroup\$ – manatwork Nov 9 '16 at 14:29
  • \$\begingroup\$ @manatwork In the "test online" link you can check the various versions of PHP, it seems working fine in PHP all versions. \$\endgroup\$ – Mario Nov 9 '16 at 14:37
  • \$\begingroup\$ Correct, “seems”. But the output is wrapped by the sandbox site, not by PHP. See with “Output: Raw”. \$\endgroup\$ – manatwork Nov 9 '16 at 14:49
  • \$\begingroup\$ @manatwork I thought the textbox output is acceptable too. I tryed with <?=wordwrap(str_repeat('_|__',175),70,"\n",1); and still no wraps in Raw output while it works fine if you save it in a PHP file and run in a browser. \$\endgroup\$ – Mario Nov 9 '16 at 14:58
  • \$\begingroup\$ Well, relying on the sandbox sounds similar to what was discussed in When is code that requires a REPL acceptable?. So if you add it to the post title, should be fine. (Honestly, I still not like the idea.) BTW, you can just wrap the line in that place instead of writing \n, to keep the code size at original 45. \$\endgroup\$ – manatwork Nov 9 '16 at 15:04
1
\$\begingroup\$

Java 8, 128

This code directly calculates each character and has no imports or dependencies.

Golfed:

()->{String s="";for(int x,y=0;y<10;++y){for(x=0;x<70;++x)s+=((y%2<1&(x+3)%4<1)|(y%2>0&(x+1)%4<1))?"|":"_";s+="\n";}return s;}

Ungolfed:

() -> {
  String s = "";
  for (int x, y = 0; y < 10; ++y) {
    for (x = 0; x < 70; ++x)
      s += ((y % 2 < 1 & (x + 3) % 4 < 1) | (y % 2 > 0 & (x + 1) % 4 < 1)) ? "|" : "_";
    s += "\n";
  }
  return s;
}
\$\endgroup\$
1
\$\begingroup\$

Swift 3, 69 bytes

(3...702).map{print($0%4<1 ?"|":"_",terminator:($0-2)%70<1 ?"\n":"")}

Output after compiling and running:

_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

Try online here (In this tool it run as script so it will produce a warning due the map result is unused.

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

Clojure, 117 110 bytes

(fn[](println(apply str(map #(str(apply str %)"\n")(partition 70(subs(apply str(repeat 175 "_|__"))0 700))))))

Basically creates a long string of "_|__"s 700 characters long, cuts it every 70 characters, then joins them with newline.

Managed to get rid of the calls to join!

Ungolfed:

(defn build-wall []
  (println
    (apply str
      (map #(str (apply str %) "\n")
        (partition 70
          (subs (apply str
                  (repeat 175 "_|__"))
                0 700))))))
\$\endgroup\$
1
\$\begingroup\$

C#, 106 102 101 118 107 106 100 96 bytes

Thanks shebang for saving 2 bytes and pointing out a mistake, Yodle for saving 6 bytes and Link Ng for saving 4 bytes.

var a="";int i;for(;i++<175;)a+="_|__";for(i=0;i<10;)Console.Write(a.Substring(i++*10,70)+"\n");

You can test it directly on http://csharppad.com/.

\$\endgroup\$
  • 1
    \$\begingroup\$ Change the a%2==0 to a%2<1 to save a byte :) \$\endgroup\$ – Kade Nov 8 '16 at 18:39
  • \$\begingroup\$ Also, you can remove the a++ in the for definition and change a%2 to a++%2! \$\endgroup\$ – Kade Nov 8 '16 at 18:41
  • \$\begingroup\$ You can save 4 bytes by declaring i outside the loop, incrementing i within the condition i<175, and using i in the second loop instead of a new integer b. \$\endgroup\$ – Yodle Nov 8 '16 at 19:45
  • \$\begingroup\$ @Yodle I could save 6 bytes by doing so (and not 4), thanks! \$\endgroup\$ – Ave Nov 8 '16 at 19:48
  • \$\begingroup\$ Ahh I guess they have a default value of 0 :P. In VS it won't let you declare local variables without initializing them, so the =0 made it only 4 for me. \$\endgroup\$ – Yodle Nov 8 '16 at 19:50
1
\$\begingroup\$

Java 8 + Guava, 81 106 bytes

25 bytes for import: com.google.common.base.*;

Lambda that takes no input and returns the required wall.

()->String.join("\n",Splitter.fixedLength(70).split(Strings.repeat("_|__",175)));

Same as many other solutions. Takes a repeating string of "_|__" 175 times, splits it into lengths of 70, then joins them on newline.

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

SAS, 68

option linesize=70;data;length w$700;w=repeat('_|__',174);put w;run;

The 174 is not a typo - in SAS the repeat function rather pedantically returns the original string plus n repeats.

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

Python 3, 43

print(("_|__"*17+"_|\n"+"__|_"*17+"_\n")*5)

Fixed to be more Trump-like.

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

Kotlin, 99 bytes

fun main(a:Array<String>){"_|__".repeat(999).split(Regex("(?<=\\G.{70})")).take(10).map(::println)}

Regex taken from here. First ever golf, done in 10 minutes, probably improvable..

\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG! Can you remove some of the spaces? Like a:Array<String>? \$\endgroup\$ – Rɪᴋᴇʀ Nov 11 '16 at 17:48
  • \$\begingroup\$ How'd I miss that...thanks. \$\endgroup\$ – F. George Nov 11 '16 at 17:50
  • \$\begingroup\$ @mEQ5aNLrK3lqs3kfSa5HbvsTWe0nIu What does your name mean? \$\endgroup\$ – Oliver Ni Nov 11 '16 at 18:04
  • \$\begingroup\$ I use random usernames everywhere, I don't like the possibility of somebody googling my nick and finding out everything about my online life. \$\endgroup\$ – F. George Nov 11 '16 at 18:07
1
\$\begingroup\$

Lua, 54 bytes

w=("_|__"):rep(17)print((w.."_|\n__"..w.."\n"):rep(5))

No fancy splits for Lua, but it does have an easy repeat.

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

bash 36 Byte

printf '_|__%.0s' {1..175}|fold -w70

OUtput:

_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
\$\endgroup\$
1
\$\begingroup\$

Python 2, 46 bytes

import textwrap as t;print t.fill('_|__'*175)

I was going to do an exec loop similar to @xnor's one alternate solution but he/she got to it before me. I guess I'll just have to let Python do the dirty work for me.

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

R, 62 bytes

Don't have the rep to comment, so posting as an answer: @user3297046's answer can be golfed-down to 62 bytes:

cat(gsub('(.{70})','\\1
',paste(rep('_|__',175),collapse='')))

which results in

_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
\$\endgroup\$
1
\$\begingroup\$

PHP, 56 bytes

Although I know it can be done smaller using wordwrap or string splits, I prefer more hacky solutions.

for($i=0;$i<700;$i++){echo($i%70?'':'
').'_|___'[$i%4];}
\$\endgroup\$
1
\$\begingroup\$

Symbolic Python, 69 bytes

Outputs as a list of lines.

_=-~(_==_)
__=-~_*-~_*_
_=[('_|__'*__)[:-_],('___|'*__)[:-_]]*-~(_*_)

Try it online!

Alternatively, for 16 more bytes, we can print the wall:

_=-~(_==_)
__=-~_*-~_*_
_=(('_|__'*__)[:-_]+"""
"""+('___|'*__)[:-_]+"""
""")*-~(_*_)

Try it online!

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

Tcl, 84 78 77 76 bytes

time {append a [expr [incr i]%4-2?"_":"|"];if $i%70<1 {puts $a;unset a}} 700

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Interesting trick of append and unset! \$\endgroup\$ – sergiol Nov 30 '18 at 1:46
  • \$\begingroup\$ @sergiol you sure took your time to reply :P also haven't been using tcl lately. idk if i should start using it again \$\endgroup\$ – ASCII-only Dec 5 '18 at 11:37
0
\$\begingroup\$

Perl, 37 bytes

print$_.$/x!(++$i%35)for('_|',__)x175

Ungolfed:

my $i = 0;
print($_, "\n" x !(++$i % 35)) for ('_|', '__') x 175;
\$\endgroup\$
0
\$\begingroup\$

Lithp, 72 bytes

#::((print (replace (repeat "_|__" 175) (regex "(.{70})" "g") "$1\n"))))

Sample usage:

% wall.lithp
(
    (def x #::((print (replace (repeat "_|__" 175) (regex "(.{70})" "g") "$1\n"))))
    (x)
)

Output:

$ ./run.js wall.lithp
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
\$\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.