Problem 46579. Shape Shifter - Part 1

This is based on a computer game I used to play as a kid, I can't remember what it was called but I vividly remember the mechanics.
Simplified Problem Statement:
Given a 4x3 matrix of 1's & 0's and an array of shapes (also 1's and 0's), return a list of locations where you should place the shapes (in the order they are given) so that by the end of placing all the shapes on the board, it is full of 1's. NOTE: Placing a shape swaps the values, i.e. 0 becomes 1 or vice versa, based on what the board was before. Read the in-depth rules for more clarification.
NOTE: The in-depth rules will consist of a simple version and solution to the game, actual gameplay will be harder.
Here are the in-depth rules:
1) The first input is a 4x3 board containing 1's and 0's
board = [1 1 1; ...
0 0 0; ...
0 1 1; ...
0 0 1];
Visual representation of board
2) The second input is an array containing a number of 'shapes' consisting of 1's and 0's
shapes = [{[1 1 1]}, ... % shape 1
{[1 0; 1 1]}]; % shape 2
Visual representation of shape 1 (left) & shape 2 (right)
3) Your goal is to return a list of the proper placement of the shapes so as to convert the board entirely to 1's. NOTE: This is a linear index, not row & column, and it's with respect to the upper left hand corner of the shape.
So, let's place the first shape on row 2, col 1 ...
shapeLocs = 4;
First shift, visually
Now let's place the second shape at row 3, col 1 (linearlly 7) to turn the entire board into 1's
shapeLocs = [shapeLocs, 7];
Second shift, visually
This will have satisfied the constraints and solved the puzzle.
Your output should be,
shapeLocs = [4 7];
If, however, you put it at 8 rather than 7... (just so you fully understand the shifting mechanic)
What it would look like (after shift) if you place shape at 8 rather than 7...
It'll obviously get more complicated, but don't be scared shiftless; Go forth and conquer.

Solution Stats

28.57% Correct | 71.43% Incorrect
Last Solution submitted on Jun 01, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers6

Suggested Problems

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!