All in all it's just, uh, another trick in code golf

The purpose of this challenge is to produce an ASCII version of the cover of this great album by the rock band Pink Floyd.

The brick junctions are made of characters _ and |. Bricks have width 7 and height 2 characters, excluding junctions. So the basic unit, including the junctions, is:

_________
|       |
|       |
_________


Each row of bricks is offset by half a brick width (4 chars) with respect to the previous row:

________________________________________
|       |       |       |       |
|       |       |       |       |
________________________________________
|       |       |       |       |
|       |       |       |       |
________________________________________
|       |       |       |       |
|       |       |       |       |


The wall is parameterized as follows. All parameters are measured in chars including junctions:

1. Horizontal offset of first row, F. This is the distance between the left margin and the first vertical junction of the upmost row. (Remember also the half-brick relative offset between rows). Its possible values are 0, 1, ..., 7.
2. Total width, W. This includes junctions. Its value is a positive integer.
3. Total height, H. This includes junctions. Its value is a positive integer.

The top of the wall always coincides with the top of a row. The bottom may be ragged (if the total height is not a multiple of 3). For example, here's the output for 6, 44, 11:

____________________________________________
|       |       |       |       |
|       |       |       |       |
____________________________________________
|       |       |       |       |       |
|       |       |       |       |       |
____________________________________________
|       |       |       |       |
|       |       |       |       |
____________________________________________
|       |       |       |       |       |


and a visual explanation of parameters:

          F=6
......
.   ____________________________________________
.         |       |       |       |       |
.         |       |       |       |       |
.   ____________________________________________
.     |       |       |       |       |       |
H=11 .     |       |       |       |       |       |
.   ____________________________________________
.         |       |       |       |       |
.         |       |       |       |       |
.   ____________________________________________
.     |       |       |       |       |       |

............................................
W=44


You may provide a program or a function.

Input format is flexible as usual. Output may be through STDOUT or an argument returned by a function. In this case it may be a string with newlines or an array of strings.

Trailing spaces or newlines are allowed.

Shortest code in bytes wins.

Test cases

Inputs are in the order given above, that is: horizontal offset of first row, total width, total height.

6, 44, 11:
____________________________________________
|       |       |       |       |
|       |       |       |       |
____________________________________________
|       |       |       |       |       |
|       |       |       |       |       |
____________________________________________
|       |       |       |       |
|       |       |       |       |
____________________________________________
|       |       |       |       |       |

2, 20, 10:
____________________
|       |       |
|       |       |
____________________
|       |
|       |
____________________
|       |       |
|       |       |
____________________

1, 1, 1:
_

1, 2, 3:
__
|
|

3, 80, 21:
________________________________________________________________________________
|       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
|       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
|       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
|       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
|       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
|       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
|       |       |       |       |       |       |       |       |       |
|       |       |       |       |       |       |       |       |       |

• You got me with the clickbait in the hnq – Rohan Jhunjhunwala Aug 16 '16 at 12:20
• @RohanJhunjhunwala Sounds about right – Insane Aug 16 '16 at 23:44
• Thank you for matching the number of syllables in the lyrics... you wouldn't believe how many people try to spin-off a song and get the syllabification wrong, it drives me nuts! – Chris Cirefice Aug 17 '16 at 23:41
• @ChrisCirefice Haha, thanks! The title was an important part of this challenge – Luis Mendo Aug 18 '16 at 0:54

Pyth, 43 27 bytes

I need to golf it heavily... the score is too shameful.

AQVE<*H?%N3X*8d+G*4/N3\|\_H


Input format

6,44
11


Output format

____________________________________________
|       |       |       |       |
|       |       |       |       |
____________________________________________
|       |       |       |       |       |
|       |       |       |       |       |
____________________________________________
|       |       |       |       |
|       |       |       |       |
____________________________________________
|       |       |       |       |       |


Explanation

AQVE<*H?%N3X*8d+G*4/N3\|\_H   First two inputs as list in Q,
third input as E.

AQ                            Assign G to the first item in Q
and H to the second item in Q.
VE                          For N from 0 to E-1:
/N3            N floor-div 3.
if N gives a remainder of 3 or 4 or 5
when divided by 6, this will be odd;
otherwise, this will be even.
*4               Multiply by 4.
if the above is odd, this will leave
a remainder of 4 when divided by 8;
otherwise, the remainder would be 0.
+G                 Add G (as an offset).
X*8d       \|          In the string "        " (*8d),
replace (X) the character with the
index above with "|" (modular indexing,
hence the manipulation above).
?%N3             \_        If N%3 is non-zero, use the above;
otherwise, use "_".
*H                           The above repeated H times.
<                     H       Take the first H characters of above.
Implicitly print with newline.

• looks like you win – wordsforthewise Aug 20 '16 at 7:46

C, 868583 82 bytes

3 bytes saved thanks to Lynn.
1 byte saved thanks to charlie.

i;f(o,w,h){++w;for(i=0;++i<w*h;)putchar(i%w?i/w%3?i%w+i/w/3*4+~o&7?32:124:95:10);}

• for(i=0;++i<w*h;) or if i is made local (param trick): for(;++i<w*h;) – charlie Aug 16 '16 at 13:08
• replace i; by i=1; and save one more byte in the for loop. – xryl669 Aug 16 '16 at 19:16
• for(i=1;i<w*h;++i) -> for(i=0;++i<w*h;) saves 1 – Yay295 Aug 16 '16 at 20:30
• @xryl669 That's not valid, functions must be reusable. – orlp Aug 17 '16 at 2:47
• @Yay295 I credited charlie with that, since he posted it 7 hours earlier. – orlp Aug 17 '16 at 4:59

C, 92 bytes

b(f,w,h,y,x){for(y=0;y<h;y++,puts(""))for(x=0;x<w;x++)putchar(y%3?(x+y/3*4-f)%8?32:124:95);}


Invoke as b(F, W, H).

• Only 92 bytes in C? That's incredible. – Leaky Nun Aug 16 '16 at 11:55
• 85 bytes – ceilingcat Jun 28 at 0:18

Perl, 63 bytes

#!perl -nl
$y+=print+map$y%3?$_++-$&7?$":'|':_,($y%6&4)x$&for/ \d+/..$'


Counting the shebang as 2, input is taken from stdin, whitespace separated.

Sample Usage

$echo 2 20 10 | perl bricks.pl ____________________ | | | | | | ____________________ | | | | ____________________ | | | | | | ____________________  Haskell, 83 bytes q s="_":[s,s] (f!w)h=take h$cycle$take w.drop(7-f).cycle<$>q"       |"++q"   |    "


This defines a ternary infix function ! which returns a list of strings. Usage example:

*Main> putStrLn $unlines$ (3!14) 7
______________
|       |
|       |
______________
|
|
______________


How it works:

            q"       |"++q"   |    "  -- build a list of 6 strings
--   1:     "_"
--   2:     "       |"
--   3:     "       |"
--   4:     "_"
--   5:     "   |    "
--   6:     "   |    "
<$> -- for each of the strings take w.drop(7-f).cycle -- repeat infinitely, drop the first 7-f chars -- and take the next w chars cycle -- infinitely repeat the resulting list take h -- and take the first h elements  • Answers like this make me want to learn this language. – GuitarPicker Aug 16 '16 at 18:09 • I thought of Haskell when reading the problem description. "Repeat infinitely" is a really neat feature to have. – DLosc Aug 16 '16 at 22:39 JavaScript (ES6), 96 95 bytes g= (f,w,h)=>[...Array(h)].map((_,i)=>(i%3? |:_).repeat(w+7).substr(f^7^i%6&4,w)).join  ; <div onchange=o.textContent=g(f.value,w.value,+h.value)><input id=f type=number min=0 max=7 placeholder=Offset><input id=w type=number min=0 placeholder=Width><input id=h type=number min=0 placeholder=Height></div><pre id=o> Explanation: Creates a string of either the repeating 7 spaces plus | pattern or just repeated _s, but at least long enough to be able to extract the w characters required for each row. The first three rows start at position f^7 and then the next three rows start at position f^3, so I achieve this by toggling bit 2 of f on every third row using the opposite bit 2 on the last two rows of each block of 6 for a saving of 1 byte. MATL, 4236 33 bytes :-Q'_ | |'[DClCl]Y"8et4YShwi:3$)!


Input format is: nCols, offset, nRows

Try it Online

The approach here is that we setup a "template" which we then index into by using the row indices ([1 2 ... nRows]) and column indices shifted by the first input ([1 2 ... nCols] - shift). Thanks to MATL's modular indexing, it will automatically result in a tiled output. As a side-note, to save some space, technically I work with a transposed version of the template and then just take a transpose (!) at the end.

The template is this:

________
|
|
________
|
|

• Nice use of run-length coding to generate the pattern – Luis Mendo Aug 17 '16 at 12:05

Python 2, 93 88 bytes

2nd indentation level is tab Saving some bytes thanks to Leaky Nun and some own modifications, also now correct offset:

def f(F,W,H):
for h in range(H):print["_"*W,((("|"+7*" ")*W)[8-F+h%6/3*4:])[:W]][h%3>0]


previous code:

def f(F,W,H,x="|"+7*" "):
for h in range(H):
print ["_"*W,(x[F+4*(h%6>3):]+x*W)[:W]][h%3>0]


Same length as unnamed lambda:

lambda F,W,H,x="|"+7*" ":"\n".join(["_"*W,(x[F+4*(h%6>3):]+x*W)[:W]][h%3>0]for h in range(H))

• F,W,H=input() – Leaky Nun Aug 16 '16 at 13:11
• remove the whitespace after print – Leaky Nun Aug 16 '16 at 13:11
• use h/3%2*4 or h%6/3*4 instead of 4*(h%6>3) – Leaky Nun Aug 16 '16 at 13:13
• You don't need the second indentation level. Just put the print statement at the same line as the for statement – Leaky Nun Aug 16 '16 at 13:15
• "| " is shorter than ("|"+7*" ") if I count correctly – Leaky Nun Aug 16 '16 at 13:27

QBasic, 121 109 bytes

(Tested on QB64)

Thanks to @DLosc for golfing my IF statement with a mathematical equivalent. That was worth 12 bytes.

General Method:

Loop through each cell one at a time and determine whether it should be a _, , or | depending on its location. MOD statements and boolean logic are used to determine brick boundaries and how much to stagger the bricks.

Code:

INPUT F,W,H
FOR y=0TO H-1:FOR x=0TO W-1
?CHR$((y MOD 3>0)*(((x-(y MOD 6>3)*4)MOD 8=F)*92+63)+95); NEXT:?:NEXT  Usage Note: QBasic expects input to be numbers separated by commas. • Using math instead of IF/THEN adds even more parentheses but saves 12 bytes: ?CHR$((y MOD 3>0)*(((x-(y MOD 6>3)*4)MOD 8=F)*92+63)+95); – DLosc Aug 16 '16 at 22:37
• Thanks for the comment. In the back of my head I had considered exploring math, but didn't. I did something sort of similar to this to color an image in in a recent submission, but the implementation I used didn't have a MOD operator. – GuitarPicker Aug 17 '16 at 5:30

Java, 149, 147, 146, 143 bytes

Golfed:

String f(int o,int w,int h){String s="";for(int y=0,x;y<h;++y){for(x=0;x<w;++x){s+=y%3>0?(x-o+(y-1)/3%2*4)%8==0?'|':' ':'_';}s+='\n';}return s;}


Ungolfed:

public class AllInAllItsJustUhAnotherTrickInCodeGolf {

public static void main(String[] args) {
int offset = 6;
int width = 44;
int height = 11;
System.out.println(new AllInAllItsJustUhAnotherTrickInCodeGolf()
.f(offset, width, height));
}

// Begin golf
String f(int o, int w, int h) {
String s = "";
for (int y = 0, x; y < h; ++y) {
for (x = 0; x < w; ++x) {
s += y % 3 > 0 ? (x - o + (y - 1) / 3 % 2 * 4) % 8 == 0 ? '|' : ' ' : '_';
}
s += '\n';
}
return s;
}
// End golf

}

• Maybe you could switch the order of the ternary by comparing to > 0 which could save two characters. And of course you can combine the declarations to int y=0,x. – Frozn Aug 18 '16 at 21:02
• As being said by Frozn, you can remove int  before the x and use int y=0,x in the first for-loop instead to save 2 bytes. Also, currently your can change y%3==0 to y%3<1. (This isn't possible for ...%8==0 to ...&8<1 though, since your operation could return a negative number.) – Kevin Cruijssen Aug 25 '16 at 8:26
• Done and done. You are correct, that second modulo can return negative and it did during debugging when I originally wrote this function. – user18932 Aug 25 '16 at 14:20
• Not sure how we missed this, but you can remove the spaces at your parameters for -2 bytes.. Alternatively, using int...o as parameter and changing w to o[1], h to o[2] and o to o[0] is -3 bytes instead. – Kevin Cruijssen Oct 28 '16 at 13:24

Ruby, 72 66 bytes

->f,w,h{h.times{|i|puts i%3<1??_*w:((?|+' '*7)*w)[8-f+i%6/4*4,w]}}


Thanks @Value Ink for 6 bytes!

Simple string multiplication and slicing.

Works in Ruby 2.3.0 (Ideone's version 2.1 threw syntax error).

• Use i%6/4*4 instead of (i%6>3?4:0) and use ?_ instead of '_', ?| instead of '|'. – Value Ink Aug 17 '16 at 8:09
• Thank you. I forgot about ? single char trick, and the "math" part is really impressive! – Leibrug Aug 17 '16 at 8:17
• I think ((' '*7+?|)*w)[f^7^i%6&4,w] saves you two bytes. – Neil Aug 17 '16 at 8:37
• Thank you @Neil. I'll edit the code... as soon as I understand how your suggestion works :) – Leibrug Aug 18 '16 at 5:40

Julia: 150128116108 107 bytes

# in codegolf.jl
r=repmat;b=r([' '],6,8);b[[1,4],:]='_';b[[2,3,23,24]]='|';b=r(b,h,w)[1:h,o+=1:o+w];b[:,end]=10;print(b'...)


to run with arguments: julia -e 'o=2;h=18;w=40;include("codegolf.jl")'

If you feel calling from bash is cheating and you want a function inside the interpreter, then the function version is 117 bytes :)

f(o,h,w)=(r=repmat;b=r([' '],6,8);b[[1,4],:]='_';b[[2,3,23,24]]='|';b=r(b,h,w)[1:h,o+=1:o+w];b[:,end]=10;print(b'...))


demo

(Thanks, @glen-o for the extra byte-saving tip!)

• Welcome to PPCG! Nice to see you also here! – Luis Mendo Aug 16 '16 at 17:41
• Note that inputs should be taken explicitly, i.e. you need some kind of input statement for those three variables. Or you can use a function that takes them as arguments and outputs or displays the result. When you are done, you may want to post an online demo using Try it online! – Luis Mendo Aug 16 '16 at 17:42
• – Luis Mendo Aug 16 '16 at 17:46
• ah. yes I did! :p – Tasos Papastylianou Aug 16 '16 at 18:04
• You can save a few characters by using repmat instead of ones (repmat([32],6,8)), and then renaming repmat to shave another character (g=repmat;b=g([32],6,8) and later b=g(b,h,w)[1:h,o+1:o+w+1]). Then replace reinterpret with map. By my count, you'll save 9 bytes between these changes. – Glen O Aug 17 '16 at 9:16

JavaScript, 172168165157147142 137 bytes

(O,W,H)=>{t='_'.repeat(W),x='|       '.repeat(W),f=t+
;for(i=0;++i<H;)f+=(!(i%3)?t:(i%6)>3?x.substr(O,W):x.substr(8-O,W))+
;return f}


N = (O,W,H)=>{t='_'.repeat(W),x='|       '.repeat(W),f=t+
;for(i=0;++i<H;)f+=(!(i%3)?t:(i%6)>3?x.substr(O,W):x.substr(8-O,W))+
;return f}

let test_data = [[6,44,11],
[2,20,10],
[1,1,1],
[1,2,3],
[3,80,21]];

for (test of test_data)
console.log(N(...test));

• Why not use s.repeat(w) instead of Array(w).fill(s).join? – Neil Aug 16 '16 at 20:30
• @Neil: Good idea, but I thought of something better. – Yay295 Aug 16 '16 at 20:45
• and then realized your solution is better than I thought. Thanks! – Yay295 Aug 16 '16 at 20:56

Dyalog APL, 29 bytes

↑⎕⍴⎕⍴¨a,4⌽¨a←'_',2⍴⊂⌽⎕⌽¯8↑'|'

⎕ is evaluated input; as the expression executes from right to left, it prompts for F, W, and H in that order

¯8↑'|' is ' |'

⎕⌽ is rotate, it chops F chars from the front and puts them at the end of the string

the other ⌽ means reverse

'_',2⍴⊂ creates a 3-tuple of '_' followed by two separate copies of the string so far

a,4⌽¨a← append the 4-rotation of everything so far, we end up with a 6-tuple

⎕⍴¨ reshape each element to the width

⎕⍴ reshape to the height

↑ mix vector of vectors into a matrix

Actually, 4443 40 bytes

This is an Actually port of the algorithm in Neil's JS answer. Golfing suggestions welcome. Try it online!

╗╝r⌠;6(%4&╜7^^╛'|7" "*+*t╛@H╛'_*3(%YI⌡Mi


Ungolfing:

          Takes implicit input in the order h, w, f.
╗╝        Save f to register 0. Save w to register 1.
r⌠...⌡M   Map over range [0..h-1]. Call this variable i.
;         Duplicate i
6(%       i%6...
4&        ...&4
╜7^^      ...^i^7. Call it c.
╛         Push w.
'|7" "*+  The string "       |"
*t╛@H     (("       |" * w)[c:])[:w]
╛'_*      Push "_" * w
3(%       Push 3, move duplicate i to TOS, mod.
YI        If not i%3, take "_"*w, else (("       |" * w)[c:])[:w]
Function ends here.
i         Flatten the resulting list and print the bricks implicitly.


PowerShell, 101 88 bytes

param($n,$w,$h)0..--$h|%{(('|       '*$w|% S*g(8-$n+4*($_%6-gt3))$w),('_'*$w))[!($_%3)]}


Try it online!

Octave 80 76 bytes

% in file codegolf.m
c(6,8)=0;c([1,4],:)=63;c([2,3,23,24])=92;char(repmat(c+32,h,w)(1:h,o+1:o+w))


to run from terminal: octave --eval "o=2;h=18;w=44; codegolf"

(alternatively, if you think the terminal call is cheating :p then an anonymous function implementation takes 86 bytes :)

c(6,8)=0;c([1,4],:)=63;c([2,3,23,24])=92;f=@(o,h,w)char(repmat(c+32,h,w)(1:h,o+1:o+w))


Call f(2,18,44) at the octave interpreter.

Bash + Sed, 411395381 370 bytes:

F=printf '_%.s' $(eval echo {1..$2});V="       |";(($[($2-$1)/8]>0))&&L=printf "$V%.s" $(eval echo {1..$[($2-$1)/8]})||L=;Z=printf "%$1.s|%s\n" e "$L";I=$[($2-(${#Z}-4))/8];(($I>0))&&W=printf "$V%.s"$(eval echo {1..$I})||W=;J=${Z:4}$W;for i in eval echo {1..$[$3/3+1]};{ (($[$i%2]<1))&&O+="$F\n$J\n$J\n"||O+="$F\n$Z\n$Z\n";};echo "echo -e "$O"|sed -n 1,\$3p"


Well, here is my very first answer in Bash, or any shell scripting language for that matter. This is also by far the longest answer here. Takes in a sequence of space-separated command line arguments in the format Offset Width Height. This can probably be a lot shorter than it currently is, so any tips and/or tricks for golfing this down more are appreciated.

Delphi/Object Pascal, 305, 302, 292 bytes

Full console program that reads 3 parameters.

uses SySutils,Math;var i,q,o,w,h:byte;begin o:=StrToInt(paramstr(1));w:=StrToInt(paramstr(2));h:=StrToInt(paramstr(3));for q:=0to h-1do begin for i:=1to w do if q mod 3=0then Write('_')else if IfThen(Odd(q div 3),((i+o)mod 8),((i-o)mod 8))=1then Write('|')else Write(' ');Writeln('');end end.


ungolfed

uses
SySutils,
Math;
var
i,q,o,w,h:byte;
begin
o:=StrToInt(paramstr(1));
w:=StrToInt(paramstr(2));
h:=StrToInt(paramstr(3));

for q := 0 to h-1 do
begin
for i := 1 to w do
if q mod 3 = 0  then
Write('_')
else
if IfThen(Odd(q div 3),((i+o)mod 8),((i-o)mod 8)) = 1 then
Write('|')
else Write(' ');
Writeln('');
end
end.


Sadly, Delphi does not have a ternary operator and it is quite a verbose language.

test case

D:\Test\CodeGolfWall\Win32\Debug>Project1.exe 2 20 10
____________________
|       |       |
|       |       |
____________________
|       |
|       |
____________________
|       |       |
|       |       |
____________________

D:\Test\CodeGolfWall\Win32\Debug>Project1.exe 6 44 11
____________________________________________
|       |       |       |       |
|       |       |       |       |
____________________________________________
|       |       |       |       |       |
|       |       |       |       |       |
____________________________________________
|       |       |       |       |
|       |       |       |       |
____________________________________________
|       |       |       |       |       |
`

Edit: Could shave of 3 bytes by using byte as type for all variables.

Edit 2: And console applications do not need the program declaration, -10