Cubes

This challenge was inspired by the 3% television series.

You are given a set of 3-dimensional blocks with different shapes. You must find the correct orientation and position for each block so that they form an 8x8x8 cube. Blocks cannot overlap with other blocks, and there must be no empty cells in the 8x8x8 grid.

The first block in the array has the correct orientation, and must be placed at 0, 0, 0. The rest of the blocks have been shuffled and randomly rotated around the X, Y, and Z axis. Rotations are a multiple of 90 degrees. Any empty space around the blocks has been trimmed.

Here’s how the blocks are encoded:

  • The outermost array contains the list of blocks.
  • Each block is a nested array with 3 levels:
    • The first level is an array of “planes” along the Z axis (depth).
    • The second level is an array of “rows” along the Y axis (height).
    • The third level is an array of “cells” along the X axis (width).

Example:

// Get the second block
const block = blocks[1]

// Get the value at {x: 2, y: 3, z: 4}
const value = block[4][3][2]

Each “cell” contains one of three values:

  • -1: This is an empty cell.
  • 0: This cell encodes a single bit with a value of 0.
  • 1: This cell encodes a single bit with a value of 1.

Empty cells (-1) can overlap with the empty cells of other blocks. 0 and 1 values must never overlap with other blocks.


Here’s a 2x1x1 block (width: 2, height: 1, depth: 1):

[[[1, 0]]]

2x1x1 Block

In these visualizations, the lighter color represents a 1 bit, and the darker color represents a 0 bit.

Here’s a 1x2x2 block (width: 1, height: 2, depth: 2):

[[[0], [0]], [[-1], [0]]]

1x2x2 Block

Blocks can be rotated , 90°, 180°, or 270° around the X, Y and Z axes:

Here’s a 4x7x8 block that has been rotated:

Rotated block

This is the block’s original orientation and position:

Block with correct orientation

Here’s all of the other blocks that form this 8x8x8 cube:


Once you’ve solved the cube, concatenate all the bits from 0, 0, 0 to 7, 7, 7 in this order: x, y, z

x: 0, y: 0, z: 0
x: 1, y: 0, z: 0
x: 2, y: 0, z: 0
...
x: 6, y: 0, z: 0
x: 7, y: 0, z: 0
x: 0, y: 1, z: 0
x: 1, y: 1, z: 0
...
x: 6, y: 7, z: 0
x: 7, y: 7, z: 0
x: 0, y: 0, z: 1
x: 1, y: 0, z: 1
...
x: 5, y: 7, z: 7
x: 6, y: 7, z: 7
x: 7, y: 7, z: 7

The result will be 512 bits. Split this into two 256-bit values (the first 256 bits, and the last 256 bits). XOR these 256-bit values together to produce a single 256-bit value. This is the private key for a Bitcoin address that contains 0.005 BTC.

First, encode the 256-bit value as a 64-character hex string. Then you will need to convert this hex string to the wallet import format (WIF). This allows you to import the private key into a Bitcoin wallet.

You can use the bitcoin-explorer command-line tool:

$ echo <hex-encoded-private-key> | bx base58check-encode -v 128

Or you can use this Ruby script:

$ private_key_to_wif.rb <hex-encoded-private-key>

Now you can import the private key and transfer the 0.005 BTC to your own address.



Stage 3

Now that you’ve solved the cube, you can proceed to the third stage by visiting this URL:

https://btc2018.formapi.io/<hex-encoded-private-key>

(Replace <hex-encoded-private-key> with the 256-bit hex-encoded string.)