14
There are two pieces of wood. Both consist of a straight body and some extra blocks below the body. An example piece with extra blocks at (0-indexed) positions 0,4,7,9,10:
XXXXXXXXXXX
X X X XX
The piece can be represented as a 01
binary sequence with the i
th character showing if there is a block at the i
th position. The upper example can be represented as 10001001011
.
We can put together two pieces by vertically flipping the second one (and maybe flipping it horizontally too). After the flip(s) we can find an alignment where the two pieces can be put together to have a height of 3.
Two example pieces:
XXXXXXXXXXX XXXXXXXX
X X X XX XXX
Second piece flipped vertically and horizontally:
XXXXXXXXXXX
X X X XX
XXX
XXXXXXXX
Pieces put together:
XXXXXXXXXXX
XXXXX X XX
XXXXXXXX
The example resulted in a total width of 12 blocks.
You should write a program or function which receives two string as input representing the two pieces and outputs an integer the minimal achievable width with a height of 3.
Input
- Two strings consisting of the characters
0
and1
. - Both strings contain at least one character.
- You may choose to receive the two strings as one joined by a single space.
Output
- A single positive integer, the minimal total width achievable.
Examples
0 0 => 1
1 0 => 1
1 1 => 2
11 111 => 5
010 0110 => 5
0010 111 => 5
00010 11011 => 6
01010 10101 => 5
1001 100001 => 6
1110001100001 1100100101 => 14
001101010000101 100010110000 => 16
0010110111100 001011010101001000000 => 21
0010110111100 001011010101001001100 => 28
100010100100111101 11100101100010100100000001 => 27
0010 10111 => 5
0100 10111 => 5
0010 11101 => 5
0100 11101 => 5
10111 0010 => 5
10111 0100 => 5
11101 0010 => 5
11101 0100 => 5
This is code golf so the shortest entry wins.
Is the piece in the first example supposed to be piece 1 in the second part of the example? If so, then one of them is wrong. – mdc32 – 2015-05-26T23:50:54.453
@mdc32 They weren't the same pieces but changed the first one to avoid confusion. – randomra – 2015-05-26T23:56:15.417