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

65

10

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

Additional rules

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:
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |    
   |       |       |       |       |       |       |       |       |       |    
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |    
   |       |       |       |       |       |       |       |       |       |    
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |    
   |       |       |       |       |       |       |       |       |       |    
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |    
   |       |       |       |       |       |       |       |       |       |    

Luis Mendo

Posted 2016-08-16T11:10:50.970

Reputation: 87 464

34You got me with the clickbait in the hnq – Rohan Jhunjhunwala – 2016-08-16T12:20:34.027

2@RohanJhunjhunwala Sounds about right – Insane – 2016-08-16T23:44:47.800

4Thank 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 – 2016-08-17T23:41:24.623

1@ChrisCirefice Haha, thanks! The title was an important part of this challenge – Luis Mendo – 2016-08-18T00:54:45.787

Answers

17

Pyth, 43 27 bytes

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

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

Try it online already.

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.

Leaky Nun

Posted 2016-08-16T11:10:50.970

Reputation: 45 011

looks like you win – wordsforthewise – 2016-08-20T07:46:49.783

30

C, 86 85 83 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);}

orlp

Posted 2016-08-16T11:10:50.970

Reputation: 37 067

1for(i=0;++i<w*h;) or if i is made local (param trick): for(;++i<w*h;) – charlie – 2016-08-16T13:08:14.117

replace i; by i=1; and save one more byte in the for loop. – xryl669 – 2016-08-16T19:16:04.107

for(i=1;i<w*h;++i) -> for(i=0;++i<w*h;) saves 1 – Yay295 – 2016-08-16T20:30:25.487

@xryl669 That's not valid, functions must be reusable. – orlp – 2016-08-17T02:47:38.623

@Yay295 I credited charlie with that, since he posted it 7 hours earlier. – orlp – 2016-08-17T04:59:52.430

Suggest for(i=!++w instead of ++w;for(i=0 – ceilingcat – 2019-06-27T18:30:11.803

26

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

Lynn

Posted 2016-08-16T11:10:50.970

Reputation: 55 648

3Only 92 bytes in C? That's incredible. – Leaky Nun – 2016-08-16T11:55:11.120

85 bytes – ceilingcat – 2019-06-28T00:18:40.350

13

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
____________________
  |       |       |
  |       |       |
____________________
      |       |
      |       |
____________________
  |       |       |
  |       |       |
____________________

primo

Posted 2016-08-16T11:10:50.970

Reputation: 30 891

11

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

nimi

Posted 2016-08-16T11:10:50.970

Reputation: 34 639

1Answers like this make me want to learn this language. – GuitarPicker – 2016-08-16T18:09:26.313

3I thought of Haskell when reading the problem description. "Repeat infinitely" is a really neat feature to have. – DLosc – 2016-08-16T22:39:48.180

10

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.

Neil

Posted 2016-08-16T11:10:50.970

Reputation: 95 035

7

MATL, 42 36 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:

________
       |
       |
________
  |     
  |     

Suever

Posted 2016-08-16T11:10:50.970

Reputation: 10 257

1Nice use of run-length coding to generate the pattern – Luis Mendo – 2016-08-17T12:05:18.140

6

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

Karl Napf

Posted 2016-08-16T11:10:50.970

Reputation: 4 131

F,W,H=input() – Leaky Nun – 2016-08-16T13:11:14.767

remove the whitespace after print – Leaky Nun – 2016-08-16T13:11:37.567

use h/3%2*4 or h%6/3*4 instead of 4*(h%6>3) – Leaky Nun – 2016-08-16T13:13:13.237

You don't need the second indentation level. Just put the print statement at the same line as the for statement – Leaky Nun – 2016-08-16T13:15:02.393

"| " is shorter than ("|"+7*" ") if I count correctly – Leaky Nun – 2016-08-16T13:27:05.533

I insist that it is shorter to use F,W,H=input() – Leaky Nun – 2016-08-16T13:28:36.880

I used variations of the same formulas in my QBasic answer (before peeking, of course). The rest of the logic is pretty different, though. Maybe some of the suggestions to optimize this answer will translate to mine. – GuitarPicker – 2016-08-16T18:14:40.293

((7*" "+"|")*W)[F^7^h%6&4:] saves you 2 bytes. – Neil – 2016-08-17T08:41:57.187

6

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.

GuitarPicker

Posted 2016-08-16T11:10:50.970

Reputation: 1 101

1Using 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 – 2016-08-16T22:37:10.447

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 – 2016-08-17T05:30:45.763

5

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

}

user18932

Posted 2016-08-16T11:10:50.970

Reputation:

1Maybe 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 – 2016-08-18T21:02:24.427

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 – 2016-08-25T08:26:26.410

Done and done. You are correct, that second modulo can return negative and it did during debugging when I originally wrote this function. – None – 2016-08-25T14:20:27.570

1Not 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 – 2016-10-28T13:24:01.670

4

Julia: 150 128 116 108 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!)

Tasos Papastylianou

Posted 2016-08-16T11:10:50.970

Reputation: 233

Welcome to PPCG! Nice to see you also here! – Luis Mendo – 2016-08-16T17:41:41.263

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 – 2016-08-16T17:42:47.563

Also, it appears you have interpreted h and w in bricks, not in chars

– Luis Mendo – 2016-08-16T17:46:53.240

ah. yes I did! :p – Tasos Papastylianou – 2016-08-16T18:04:10.477

that actually makes it slightly easier! :D – Tasos Papastylianou – 2016-08-16T18:28:04.577

1You 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 – 2016-08-17T09:16:02.943

Actually it saves a lot more, since the Int32 requirement also disappears with map, and this also allows me to use repmat twice (it throws an error with Int32)! I can't believe I didn't map from the beginning (I guess I was stuck thinking of Char as a Type rather than also as a 'constructor'). Thanks, nice catch! :D – Tasos Papastylianou – 2016-08-17T16:20:01.790

... or ... you could just print a character array directly ... d'oh! – Tasos Papastylianou – 2016-08-17T17:07:11.633

4

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

Leibrug

Posted 2016-08-16T11:10:50.970

Reputation: 121

2Use i%6/4*4 instead of (i%6>3?4:0) and use ?_ instead of '_', ?| instead of '|'. – Value Ink – 2016-08-17T08:09:28.870

Thank you. I forgot about ? single char trick, and the "math" part is really impressive! – Leibrug – 2016-08-17T08:17:09.627

1I think ((' '*7+?|)*w)[f^7^i%6&4,w] saves you two bytes. – Neil – 2016-08-17T08:37:15.147

Thank you @Neil. I'll edit the code... as soon as I understand how your suggestion works :) – Leibrug – 2016-08-18T05:40:31.780

3

JavaScript, 172 168 165 157 147 142 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));

Yay295

Posted 2016-08-16T11:10:50.970

Reputation: 650

Why not use s.repeat(w) instead of Array(w).fill(s).join\``? – Neil – 2016-08-16T20:30:41.613

@Neil: Good idea, but I thought of something better. – Yay295 – 2016-08-16T20:45:24.533

and then realized your solution is better than I thought. Thanks! – Yay295 – 2016-08-16T20:56:52.067

3

Dyalog APL, 29 bytes

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

tests: 6 44 11, 2 20 10, 1 1 1, 1 2 3, 3 80 21

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

ngn

Posted 2016-08-16T11:10:50.970

Reputation: 11 449

2

PowerShell, 101 88 bytes

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

Try it online!

Veskah

Posted 2016-08-16T11:10:50.970

Reputation: 3 580

2

Actually, 44 43 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.

Sherlock9

Posted 2016-08-16T11:10:50.970

Reputation: 11 664

1

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.

Tasos Papastylianou

Posted 2016-08-16T11:10:50.970

Reputation: 233

1

Bash + Sed, 411 395 381 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.

R. Kap

Posted 2016-08-16T11:10:50.970

Reputation: 4 730

1

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

R-D

Posted 2016-08-16T11:10:50.970

Reputation: 231