6
\$\begingroup\$

I have recently thought of a wonderful relatively old mobile game, called Tower Bloxx. Alhough I'm not really old myself, but it reminded me of childhood and school :)

So this my challenge is a kind of a reference to that good game!

I have (hopefully) looked into any tower question on PPCG and this won't be a dupe.


Definition

Given N - number of blocks, build a tower of N blocks with the following pattern. The horizontal coordinate is changed with every block.

In order to avoid misinterpretations, here's the "table" of correlations between the n-th block and its horizontal coordinate.

There're no random things there, the coordinate for each block is strictly defined.

These horizontal coordinates are all listed relative to the first block and they are in fact just for readability of the following test cases.

N    X (coord)
------
1    0
2    2
3   -2
4    0
5   -2
6    2
7    goto N=1

On top of the last block, you must smash a roof.


Input

Positive integer (N).

Output:

N blocks stacked on top of each other and the roof. Each block is horizontally moved compared to the first block (to either -2, 0, or 2 points), as described in the table.

The block structure:

  *********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  *********

Once they are stacked together, the top of the lower block intersects with the bottom of the higher block:

    *********
    * ----- *
    * |   | *
    * |   | *
    * ----- *
  ***********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  *********

The roof that should be stacked on top of the last, n-th block is:

      *
     ***
    ** **
   **   **

The block with the roof atop looks like this:

      *
     ***
    ** **
   **   **
  *********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  *********

Test cases below.

Input: 1. Output:

      *
     ***
    ** **
   **   **
  *********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  *********

Input: 2. Output:

        *
       ***
      ** **
     **   **
    *********
    * ----- *
    * |   | *
    * |   | *
    * ----- *
  ***********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  *********

Input: 3. Output:

    *
   ***
  ** **
 **   **
*********
* ----- *
* |   | *
* |   | *
* ----- *
*************
    * ----- *
    * |   | *
    * |   | *
    * ----- *
  ***********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  *********

Input: 4. Output:

      *
     ***
    ** **
   **   **
  *********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
***********
* ----- *
* |   | *
* |   | *
* ----- *
*************
    * ----- *
    * |   | *
    * |   | *
    * ----- *
  ***********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  *********

Input: 10. Output:

      *
     ***
    ** **
   **   **
  *********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
***********
* ----- *
* |   | *
* |   | *
* ----- *
*************
    * ----- *
    * |   | *
    * |   | *
    * ----- *
  ***********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  ***********
    * ----- *
    * |   | *
    * |   | *
    * ----- *
*************
* ----- *
* |   | *
* |   | *
* ----- *
***********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
***********
* ----- *
* |   | *
* |   | *
* ----- *
*************
    * ----- *
    * |   | *
    * |   | *
    * ----- *
  ***********
  * ----- *
  * |   | *
  * |   | *
  * ----- *
  *********

Scoring

Code golf, shortest wins!


Trailing invisible stuff is allowed.

\$\endgroup\$
  • \$\begingroup\$ Are the coordinates relative to the first block or the previous block? Because first you said „first“ and then „previous“. \$\endgroup\$ – O.O.Balance Apr 3 '18 at 20:05
  • \$\begingroup\$ @O.O.B The coordinates stated in tables are just for readability, and they are relative to the first block. Each next block is moved relative to the previous block. I see no conflict in wording. \$\endgroup\$ – nicael Apr 3 '18 at 20:08
  • \$\begingroup\$ In fact, I believe anyone can see the pattern by looking just in the test cases without seeing the table and anything else. \$\endgroup\$ – nicael Apr 3 '18 at 20:08
  • \$\begingroup\$ While the test cases are unambiguous, the wording „Each block is horizontally moved compared to the previous block, as described in the table.“ is misleading imo. \$\endgroup\$ – O.O.Balance Apr 3 '18 at 20:14
  • \$\begingroup\$ @o.O edited. 😏 \$\endgroup\$ – nicael Apr 3 '18 at 20:18
2
\$\begingroup\$

Charcoal, 48 bytes

FN«M×X±¹ιI§224ι←B⁹±⁶*↗↗↑↓²→⁵↖↑²←⁵↖»GH<⁵*M⁷←GH<⁴*

Try it online! Link is to verbose version of code. Explanation:

FN«

Draw N Blox.

M×X±¹ιI§224ι←

Adjust the horizontal position before drawing each Blox.

B⁹±⁶*

Draw the outer wall of the Blox.

↗↗↑↓²→⁵↖↑²←⁵↖»

Draw the inner wall of the Blox.

GH<⁵*M⁷←GH<⁴*

Raise the roof.

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

JavaScript (ES6), 206 bytes

Saved 2 bytes thanks to @kamoroso94

f=(n,k=0)=>n--?f(n,k+1)+`${n?`
`:23456}0110`.replace(/./g,c=>' '.repeat('240204'[k%6])+'* ----- ,* |   | ,    ,   **,  ** *, **   *,********'.split`,`[c]+`*
`)+(k%6<2?'  ':'')+'*'.repeat(k?k%3<2?11:13:9):''

Try it online!

\$\endgroup\$
  • \$\begingroup\$ ` 23456 ` doesn't need to have backticks around it, save two bytes. \$\endgroup\$ – kamoroso94 Apr 3 '18 at 21:59
  • \$\begingroup\$ @kamoroso94 Thanks, nice catch! \$\endgroup\$ – Arnauld Apr 3 '18 at 22:01
  • \$\begingroup\$ @kamoroso94 Also, use `\`23456\`` to have backticks in code: `23456`. \$\endgroup\$ – user202729 Apr 4 '18 at 4:47
0
\$\begingroup\$

SOGL V0.12, 53 bytes

ø.∫"│“3─wι«@*ο"²¹EiΕbK⁷‘╬$.F=?"¦○⌠Q°‘5nΓ;+}┼JGKh╬8;++

Try it Here!

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

Python 2, 258 bytes

n=input()
l=[[4,2,4,0,2,0][(n-i)%6]for i in[0]+range(n)+[n-1]]
for i,v in enumerate(l[:-1]):s=v*' ';a,b=s+'* ----- *',s+'* |   | *';x,y=sorted([l[i+1],v]);print'\n'.join(([a,b,b,a]if i else[s+'    *',s+'   ***',s+'  ** **',s+' **   **'])+[' '*x+'*'*(9+y-x)])

Try it online!

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

JavaScript (Node.js), 238 bytes

n=>{for(l=n>2&&2,s=i="";i<n;l=A)
s=(y=(p=" "[r="repeat"](A="240204"[i++%6]-(n<3)*2))+`* ----- *
`)+(x=p+`* |   | *
`)+x+y+" "[r](l>A?A:l)+"*"[r](9+Math.abs(A-l))+`
`+s
return p+`    *
${p}   ***
${p}  ** **
${p} **   **
${p}*********
`+s}

Try it online!

\$\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.