1 dimensional jigsaw

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
12
down vote

favorite
2












Can you piece these jigsaw pieces back together again?




X...X......X....X..X
X.X.....X.....X....X
XX.X...X...X
X.....X.X...X.....X
X.X.X.X..X..


The solution consists of 25 X's in a row. Where two pieces overlap, X's replace the .'s.










share|improve this question























  • Nice puzzle. How did you set about looking for a set of pieces which would make a non-trivial puzzle?
    – Rosie F
    Aug 31 at 10:28






  • 1




    my current ad hoc solution is based around another of my puzzles - Keys. Scrambling this proved very difficult, and I resorted to generating a random puzzle and obscuring the answer by trial and error, all using computers. This has left me with a healthy sense of how to make a solution unique, but as I said, is by no means guaranteed to work. You just reject the rejects I guess.
    – JonMark Perry
    Aug 31 at 10:38










  • If I may, would you mind replacing the O by ., it would make reading easier.
    – Matthieu M.
    Aug 31 at 11:30














up vote
12
down vote

favorite
2












Can you piece these jigsaw pieces back together again?




X...X......X....X..X
X.X.....X.....X....X
XX.X...X...X
X.....X.X...X.....X
X.X.X.X..X..


The solution consists of 25 X's in a row. Where two pieces overlap, X's replace the .'s.










share|improve this question























  • Nice puzzle. How did you set about looking for a set of pieces which would make a non-trivial puzzle?
    – Rosie F
    Aug 31 at 10:28






  • 1




    my current ad hoc solution is based around another of my puzzles - Keys. Scrambling this proved very difficult, and I resorted to generating a random puzzle and obscuring the answer by trial and error, all using computers. This has left me with a healthy sense of how to make a solution unique, but as I said, is by no means guaranteed to work. You just reject the rejects I guess.
    – JonMark Perry
    Aug 31 at 10:38










  • If I may, would you mind replacing the O by ., it would make reading easier.
    – Matthieu M.
    Aug 31 at 11:30












up vote
12
down vote

favorite
2









up vote
12
down vote

favorite
2






2





Can you piece these jigsaw pieces back together again?




X...X......X....X..X
X.X.....X.....X....X
XX.X...X...X
X.....X.X...X.....X
X.X.X.X..X..


The solution consists of 25 X's in a row. Where two pieces overlap, X's replace the .'s.










share|improve this question















Can you piece these jigsaw pieces back together again?




X...X......X....X..X
X.X.....X.....X....X
XX.X...X...X
X.....X.X...X.....X
X.X.X.X..X..


The solution consists of 25 X's in a row. Where two pieces overlap, X's replace the .'s.







jigsaw-puzzle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 31 at 11:38

























asked Aug 31 at 7:28









JonMark Perry

14.7k52972




14.7k52972











  • Nice puzzle. How did you set about looking for a set of pieces which would make a non-trivial puzzle?
    – Rosie F
    Aug 31 at 10:28






  • 1




    my current ad hoc solution is based around another of my puzzles - Keys. Scrambling this proved very difficult, and I resorted to generating a random puzzle and obscuring the answer by trial and error, all using computers. This has left me with a healthy sense of how to make a solution unique, but as I said, is by no means guaranteed to work. You just reject the rejects I guess.
    – JonMark Perry
    Aug 31 at 10:38










  • If I may, would you mind replacing the O by ., it would make reading easier.
    – Matthieu M.
    Aug 31 at 11:30
















  • Nice puzzle. How did you set about looking for a set of pieces which would make a non-trivial puzzle?
    – Rosie F
    Aug 31 at 10:28






  • 1




    my current ad hoc solution is based around another of my puzzles - Keys. Scrambling this proved very difficult, and I resorted to generating a random puzzle and obscuring the answer by trial and error, all using computers. This has left me with a healthy sense of how to make a solution unique, but as I said, is by no means guaranteed to work. You just reject the rejects I guess.
    – JonMark Perry
    Aug 31 at 10:38










  • If I may, would you mind replacing the O by ., it would make reading easier.
    – Matthieu M.
    Aug 31 at 11:30















Nice puzzle. How did you set about looking for a set of pieces which would make a non-trivial puzzle?
– Rosie F
Aug 31 at 10:28




Nice puzzle. How did you set about looking for a set of pieces which would make a non-trivial puzzle?
– Rosie F
Aug 31 at 10:28




1




1




my current ad hoc solution is based around another of my puzzles - Keys. Scrambling this proved very difficult, and I resorted to generating a random puzzle and obscuring the answer by trial and error, all using computers. This has left me with a healthy sense of how to make a solution unique, but as I said, is by no means guaranteed to work. You just reject the rejects I guess.
– JonMark Perry
Aug 31 at 10:38




my current ad hoc solution is based around another of my puzzles - Keys. Scrambling this proved very difficult, and I resorted to generating a random puzzle and obscuring the answer by trial and error, all using computers. This has left me with a healthy sense of how to make a solution unique, but as I said, is by no means guaranteed to work. You just reject the rejects I guess.
– JonMark Perry
Aug 31 at 10:38












If I may, would you mind replacing the O by ., it would make reading easier.
– Matthieu M.
Aug 31 at 11:30




If I may, would you mind replacing the O by ., it would make reading easier.
– Matthieu M.
Aug 31 at 11:30










3 Answers
3






active

oldest

votes

















up vote
11
down vote



accepted










The solution is:






X . . . X . . . . . . X . . . . X . . X 1
X . X . . . . . X . . . . . X . . . . X 2
X X . X . . . X . . . X 3
X . . . . . X . X . . . X . . . . . X 4
X . X . X . X . . X . . 5

3 3 4 3 2 1 2 3 4 1 4 3 2 5 4 5 1 5 2 5 4 1 5 2 1






share|improve this answer
















  • 1




    There isn't that much to explain, really: I just pushed the pieces around in a fixed-width text editor until they aligned.
    – M Oehm
    Aug 31 at 8:20






  • 1




    (I liked the puzzle and I also like the idea of text editors as low-key front end.)
    – M Oehm
    Aug 31 at 8:24

















up vote
1
down vote













Here is a Python script which bruteforces the solution. To summarize, it assumes one of the pieces is the right-most, then shifts each remaining piece to the left and checks if it solves the puzzle.



The check is done by treating the strings as binary numbers, performing bit shifts (i.e. multiplying by powers of 2), then check if their sum is equal to $2^25 - 1$ i.e. the 25-bit number with all 1s.



Note that in the case where the solution consists of multiple pieces aligned at the right-most, the script will think there are multiple solutions, but these can be easily screened out manually.



On my computer this runs for ~0.5s. I imagine this can be optimized if necessary for larger inputs.



def f(x):
return int(x.replace('X', '1').replace('.', '0'), base=2)

def finv(x):
return "0:b".format(x).replace('1', 'X').replace('0', '.')

pieces = [
f('X...X......X....X..X'),
f('X.X.....X.....X....X'),
f('XX.X...X...X'),
f('X.....X.X...X.....X'),
f('X.X.X.X..X..')
]

finallen = 25

def piece_len(piece):
from math import log2, ceil
return ceil(log2(piece))
# Alternatively, return len(finv(piece))

for piece in pieces:
remainingpieces = pieces[:]
remainingpieces.remove(piece)

# Assume the current piece is the right-most.
# The position of each remaining piece is then at most
# (25 - length of piece) to the left.

positionstoshift = [0] * len(remainingpieces)
stoploop = False
while not stoploop:
shiftedremainingpieces =

for i in range(len(remainingpieces)):
shiftedremainingpieces.append(
remainingpieces[i] << positionstoshift[i]
)

arithsum = sum(shiftedremainingpieces) + piece

if arithsum == 2 ** finallen - 1:
print("Solution found:")
# Print all pieces with appropriate space padding
print(" " * (finallen - piece_len(piece)) + finv(piece))
for i in range(len(remainingpieces)):
print(" " * (
finallen -
piece_len(remainingpieces[i]) -
positionstoshift[i]
) + finv(remainingpieces[i]))
print("")
# Terminate the program here if only one solution is needed

# Increment positionstoshift
positionstoshift[-1] += 1
# Loop from the right, carry over as necessary
for i in range(-1, -len(positionstoshift) - 1, -1):
if positionstoshift[i] > finallen - piece_len(remainingpieces[i]):
positionstoshift[i] = 0
try:
positionstoshift[i - 1] += 1
except IndexError:
# Can't carry over, hence reached the end
stoploop = True
break


Output:





Solution found:
X...X......X....X..X
X.X.....X.....X....X
XX.X...X...X
X.....X.X...X.....X
X.X.X.X..X..

Solution found:
X.X.X.X..X..
X...X......X....X..X
X.X.....X.....X....X
XX.X...X...X
X.....X.X...X.....X






share|improve this answer






















  • your first 'solution' isn't
    – JonMark Perry
    Aug 31 at 16:23










  • @JonMarkPerry Sorry that was just me messing up the formatting on stackexchange
    – ace
    Aug 31 at 16:25










  • okay, but you should have found 120 solutions like this
    – JonMark Perry
    Aug 31 at 16:32










  • @JonMarkPerry How did you arrive at the number 120? I'm struggling to see how my algorithm skipped 118 cases.
    – ace
    Aug 31 at 16:38










  • your 2 solutions are permutations of each other by row, and there are 5!=5.4.3.2.1=120 of these.
    – JonMark Perry
    Aug 31 at 16:59

















up vote
0
down vote













A start:



Number the 25 positions $1dots 25$.



I note that your 2nd piece occupies 4 positions of one parity and 1 of the other. So do your 3rd and 5th pieces. And your 4th occupies 5 positions all of the same parity.






share|improve this answer




















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "559"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f71112%2f1-dimensional-jigsaw%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    11
    down vote



    accepted










    The solution is:






    X . . . X . . . . . . X . . . . X . . X 1
    X . X . . . . . X . . . . . X . . . . X 2
    X X . X . . . X . . . X 3
    X . . . . . X . X . . . X . . . . . X 4
    X . X . X . X . . X . . 5

    3 3 4 3 2 1 2 3 4 1 4 3 2 5 4 5 1 5 2 5 4 1 5 2 1






    share|improve this answer
















    • 1




      There isn't that much to explain, really: I just pushed the pieces around in a fixed-width text editor until they aligned.
      – M Oehm
      Aug 31 at 8:20






    • 1




      (I liked the puzzle and I also like the idea of text editors as low-key front end.)
      – M Oehm
      Aug 31 at 8:24














    up vote
    11
    down vote



    accepted










    The solution is:






    X . . . X . . . . . . X . . . . X . . X 1
    X . X . . . . . X . . . . . X . . . . X 2
    X X . X . . . X . . . X 3
    X . . . . . X . X . . . X . . . . . X 4
    X . X . X . X . . X . . 5

    3 3 4 3 2 1 2 3 4 1 4 3 2 5 4 5 1 5 2 5 4 1 5 2 1






    share|improve this answer
















    • 1




      There isn't that much to explain, really: I just pushed the pieces around in a fixed-width text editor until they aligned.
      – M Oehm
      Aug 31 at 8:20






    • 1




      (I liked the puzzle and I also like the idea of text editors as low-key front end.)
      – M Oehm
      Aug 31 at 8:24












    up vote
    11
    down vote



    accepted







    up vote
    11
    down vote



    accepted






    The solution is:






    X . . . X . . . . . . X . . . . X . . X 1
    X . X . . . . . X . . . . . X . . . . X 2
    X X . X . . . X . . . X 3
    X . . . . . X . X . . . X . . . . . X 4
    X . X . X . X . . X . . 5

    3 3 4 3 2 1 2 3 4 1 4 3 2 5 4 5 1 5 2 5 4 1 5 2 1






    share|improve this answer












    The solution is:






    X . . . X . . . . . . X . . . . X . . X 1
    X . X . . . . . X . . . . . X . . . . X 2
    X X . X . . . X . . . X 3
    X . . . . . X . X . . . X . . . . . X 4
    X . X . X . X . . X . . 5

    3 3 4 3 2 1 2 3 4 1 4 3 2 5 4 5 1 5 2 5 4 1 5 2 1







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 31 at 8:01









    M Oehm

    33.2k1104153




    33.2k1104153







    • 1




      There isn't that much to explain, really: I just pushed the pieces around in a fixed-width text editor until they aligned.
      – M Oehm
      Aug 31 at 8:20






    • 1




      (I liked the puzzle and I also like the idea of text editors as low-key front end.)
      – M Oehm
      Aug 31 at 8:24












    • 1




      There isn't that much to explain, really: I just pushed the pieces around in a fixed-width text editor until they aligned.
      – M Oehm
      Aug 31 at 8:20






    • 1




      (I liked the puzzle and I also like the idea of text editors as low-key front end.)
      – M Oehm
      Aug 31 at 8:24







    1




    1




    There isn't that much to explain, really: I just pushed the pieces around in a fixed-width text editor until they aligned.
    – M Oehm
    Aug 31 at 8:20




    There isn't that much to explain, really: I just pushed the pieces around in a fixed-width text editor until they aligned.
    – M Oehm
    Aug 31 at 8:20




    1




    1




    (I liked the puzzle and I also like the idea of text editors as low-key front end.)
    – M Oehm
    Aug 31 at 8:24




    (I liked the puzzle and I also like the idea of text editors as low-key front end.)
    – M Oehm
    Aug 31 at 8:24










    up vote
    1
    down vote













    Here is a Python script which bruteforces the solution. To summarize, it assumes one of the pieces is the right-most, then shifts each remaining piece to the left and checks if it solves the puzzle.



    The check is done by treating the strings as binary numbers, performing bit shifts (i.e. multiplying by powers of 2), then check if their sum is equal to $2^25 - 1$ i.e. the 25-bit number with all 1s.



    Note that in the case where the solution consists of multiple pieces aligned at the right-most, the script will think there are multiple solutions, but these can be easily screened out manually.



    On my computer this runs for ~0.5s. I imagine this can be optimized if necessary for larger inputs.



    def f(x):
    return int(x.replace('X', '1').replace('.', '0'), base=2)

    def finv(x):
    return "0:b".format(x).replace('1', 'X').replace('0', '.')

    pieces = [
    f('X...X......X....X..X'),
    f('X.X.....X.....X....X'),
    f('XX.X...X...X'),
    f('X.....X.X...X.....X'),
    f('X.X.X.X..X..')
    ]

    finallen = 25

    def piece_len(piece):
    from math import log2, ceil
    return ceil(log2(piece))
    # Alternatively, return len(finv(piece))

    for piece in pieces:
    remainingpieces = pieces[:]
    remainingpieces.remove(piece)

    # Assume the current piece is the right-most.
    # The position of each remaining piece is then at most
    # (25 - length of piece) to the left.

    positionstoshift = [0] * len(remainingpieces)
    stoploop = False
    while not stoploop:
    shiftedremainingpieces =

    for i in range(len(remainingpieces)):
    shiftedremainingpieces.append(
    remainingpieces[i] << positionstoshift[i]
    )

    arithsum = sum(shiftedremainingpieces) + piece

    if arithsum == 2 ** finallen - 1:
    print("Solution found:")
    # Print all pieces with appropriate space padding
    print(" " * (finallen - piece_len(piece)) + finv(piece))
    for i in range(len(remainingpieces)):
    print(" " * (
    finallen -
    piece_len(remainingpieces[i]) -
    positionstoshift[i]
    ) + finv(remainingpieces[i]))
    print("")
    # Terminate the program here if only one solution is needed

    # Increment positionstoshift
    positionstoshift[-1] += 1
    # Loop from the right, carry over as necessary
    for i in range(-1, -len(positionstoshift) - 1, -1):
    if positionstoshift[i] > finallen - piece_len(remainingpieces[i]):
    positionstoshift[i] = 0
    try:
    positionstoshift[i - 1] += 1
    except IndexError:
    # Can't carry over, hence reached the end
    stoploop = True
    break


    Output:





    Solution found:
    X...X......X....X..X
    X.X.....X.....X....X
    XX.X...X...X
    X.....X.X...X.....X
    X.X.X.X..X..

    Solution found:
    X.X.X.X..X..
    X...X......X....X..X
    X.X.....X.....X....X
    XX.X...X...X
    X.....X.X...X.....X






    share|improve this answer






















    • your first 'solution' isn't
      – JonMark Perry
      Aug 31 at 16:23










    • @JonMarkPerry Sorry that was just me messing up the formatting on stackexchange
      – ace
      Aug 31 at 16:25










    • okay, but you should have found 120 solutions like this
      – JonMark Perry
      Aug 31 at 16:32










    • @JonMarkPerry How did you arrive at the number 120? I'm struggling to see how my algorithm skipped 118 cases.
      – ace
      Aug 31 at 16:38










    • your 2 solutions are permutations of each other by row, and there are 5!=5.4.3.2.1=120 of these.
      – JonMark Perry
      Aug 31 at 16:59














    up vote
    1
    down vote













    Here is a Python script which bruteforces the solution. To summarize, it assumes one of the pieces is the right-most, then shifts each remaining piece to the left and checks if it solves the puzzle.



    The check is done by treating the strings as binary numbers, performing bit shifts (i.e. multiplying by powers of 2), then check if their sum is equal to $2^25 - 1$ i.e. the 25-bit number with all 1s.



    Note that in the case where the solution consists of multiple pieces aligned at the right-most, the script will think there are multiple solutions, but these can be easily screened out manually.



    On my computer this runs for ~0.5s. I imagine this can be optimized if necessary for larger inputs.



    def f(x):
    return int(x.replace('X', '1').replace('.', '0'), base=2)

    def finv(x):
    return "0:b".format(x).replace('1', 'X').replace('0', '.')

    pieces = [
    f('X...X......X....X..X'),
    f('X.X.....X.....X....X'),
    f('XX.X...X...X'),
    f('X.....X.X...X.....X'),
    f('X.X.X.X..X..')
    ]

    finallen = 25

    def piece_len(piece):
    from math import log2, ceil
    return ceil(log2(piece))
    # Alternatively, return len(finv(piece))

    for piece in pieces:
    remainingpieces = pieces[:]
    remainingpieces.remove(piece)

    # Assume the current piece is the right-most.
    # The position of each remaining piece is then at most
    # (25 - length of piece) to the left.

    positionstoshift = [0] * len(remainingpieces)
    stoploop = False
    while not stoploop:
    shiftedremainingpieces =

    for i in range(len(remainingpieces)):
    shiftedremainingpieces.append(
    remainingpieces[i] << positionstoshift[i]
    )

    arithsum = sum(shiftedremainingpieces) + piece

    if arithsum == 2 ** finallen - 1:
    print("Solution found:")
    # Print all pieces with appropriate space padding
    print(" " * (finallen - piece_len(piece)) + finv(piece))
    for i in range(len(remainingpieces)):
    print(" " * (
    finallen -
    piece_len(remainingpieces[i]) -
    positionstoshift[i]
    ) + finv(remainingpieces[i]))
    print("")
    # Terminate the program here if only one solution is needed

    # Increment positionstoshift
    positionstoshift[-1] += 1
    # Loop from the right, carry over as necessary
    for i in range(-1, -len(positionstoshift) - 1, -1):
    if positionstoshift[i] > finallen - piece_len(remainingpieces[i]):
    positionstoshift[i] = 0
    try:
    positionstoshift[i - 1] += 1
    except IndexError:
    # Can't carry over, hence reached the end
    stoploop = True
    break


    Output:





    Solution found:
    X...X......X....X..X
    X.X.....X.....X....X
    XX.X...X...X
    X.....X.X...X.....X
    X.X.X.X..X..

    Solution found:
    X.X.X.X..X..
    X...X......X....X..X
    X.X.....X.....X....X
    XX.X...X...X
    X.....X.X...X.....X






    share|improve this answer






















    • your first 'solution' isn't
      – JonMark Perry
      Aug 31 at 16:23










    • @JonMarkPerry Sorry that was just me messing up the formatting on stackexchange
      – ace
      Aug 31 at 16:25










    • okay, but you should have found 120 solutions like this
      – JonMark Perry
      Aug 31 at 16:32










    • @JonMarkPerry How did you arrive at the number 120? I'm struggling to see how my algorithm skipped 118 cases.
      – ace
      Aug 31 at 16:38










    • your 2 solutions are permutations of each other by row, and there are 5!=5.4.3.2.1=120 of these.
      – JonMark Perry
      Aug 31 at 16:59












    up vote
    1
    down vote










    up vote
    1
    down vote









    Here is a Python script which bruteforces the solution. To summarize, it assumes one of the pieces is the right-most, then shifts each remaining piece to the left and checks if it solves the puzzle.



    The check is done by treating the strings as binary numbers, performing bit shifts (i.e. multiplying by powers of 2), then check if their sum is equal to $2^25 - 1$ i.e. the 25-bit number with all 1s.



    Note that in the case where the solution consists of multiple pieces aligned at the right-most, the script will think there are multiple solutions, but these can be easily screened out manually.



    On my computer this runs for ~0.5s. I imagine this can be optimized if necessary for larger inputs.



    def f(x):
    return int(x.replace('X', '1').replace('.', '0'), base=2)

    def finv(x):
    return "0:b".format(x).replace('1', 'X').replace('0', '.')

    pieces = [
    f('X...X......X....X..X'),
    f('X.X.....X.....X....X'),
    f('XX.X...X...X'),
    f('X.....X.X...X.....X'),
    f('X.X.X.X..X..')
    ]

    finallen = 25

    def piece_len(piece):
    from math import log2, ceil
    return ceil(log2(piece))
    # Alternatively, return len(finv(piece))

    for piece in pieces:
    remainingpieces = pieces[:]
    remainingpieces.remove(piece)

    # Assume the current piece is the right-most.
    # The position of each remaining piece is then at most
    # (25 - length of piece) to the left.

    positionstoshift = [0] * len(remainingpieces)
    stoploop = False
    while not stoploop:
    shiftedremainingpieces =

    for i in range(len(remainingpieces)):
    shiftedremainingpieces.append(
    remainingpieces[i] << positionstoshift[i]
    )

    arithsum = sum(shiftedremainingpieces) + piece

    if arithsum == 2 ** finallen - 1:
    print("Solution found:")
    # Print all pieces with appropriate space padding
    print(" " * (finallen - piece_len(piece)) + finv(piece))
    for i in range(len(remainingpieces)):
    print(" " * (
    finallen -
    piece_len(remainingpieces[i]) -
    positionstoshift[i]
    ) + finv(remainingpieces[i]))
    print("")
    # Terminate the program here if only one solution is needed

    # Increment positionstoshift
    positionstoshift[-1] += 1
    # Loop from the right, carry over as necessary
    for i in range(-1, -len(positionstoshift) - 1, -1):
    if positionstoshift[i] > finallen - piece_len(remainingpieces[i]):
    positionstoshift[i] = 0
    try:
    positionstoshift[i - 1] += 1
    except IndexError:
    # Can't carry over, hence reached the end
    stoploop = True
    break


    Output:





    Solution found:
    X...X......X....X..X
    X.X.....X.....X....X
    XX.X...X...X
    X.....X.X...X.....X
    X.X.X.X..X..

    Solution found:
    X.X.X.X..X..
    X...X......X....X..X
    X.X.....X.....X....X
    XX.X...X...X
    X.....X.X...X.....X






    share|improve this answer














    Here is a Python script which bruteforces the solution. To summarize, it assumes one of the pieces is the right-most, then shifts each remaining piece to the left and checks if it solves the puzzle.



    The check is done by treating the strings as binary numbers, performing bit shifts (i.e. multiplying by powers of 2), then check if their sum is equal to $2^25 - 1$ i.e. the 25-bit number with all 1s.



    Note that in the case where the solution consists of multiple pieces aligned at the right-most, the script will think there are multiple solutions, but these can be easily screened out manually.



    On my computer this runs for ~0.5s. I imagine this can be optimized if necessary for larger inputs.



    def f(x):
    return int(x.replace('X', '1').replace('.', '0'), base=2)

    def finv(x):
    return "0:b".format(x).replace('1', 'X').replace('0', '.')

    pieces = [
    f('X...X......X....X..X'),
    f('X.X.....X.....X....X'),
    f('XX.X...X...X'),
    f('X.....X.X...X.....X'),
    f('X.X.X.X..X..')
    ]

    finallen = 25

    def piece_len(piece):
    from math import log2, ceil
    return ceil(log2(piece))
    # Alternatively, return len(finv(piece))

    for piece in pieces:
    remainingpieces = pieces[:]
    remainingpieces.remove(piece)

    # Assume the current piece is the right-most.
    # The position of each remaining piece is then at most
    # (25 - length of piece) to the left.

    positionstoshift = [0] * len(remainingpieces)
    stoploop = False
    while not stoploop:
    shiftedremainingpieces =

    for i in range(len(remainingpieces)):
    shiftedremainingpieces.append(
    remainingpieces[i] << positionstoshift[i]
    )

    arithsum = sum(shiftedremainingpieces) + piece

    if arithsum == 2 ** finallen - 1:
    print("Solution found:")
    # Print all pieces with appropriate space padding
    print(" " * (finallen - piece_len(piece)) + finv(piece))
    for i in range(len(remainingpieces)):
    print(" " * (
    finallen -
    piece_len(remainingpieces[i]) -
    positionstoshift[i]
    ) + finv(remainingpieces[i]))
    print("")
    # Terminate the program here if only one solution is needed

    # Increment positionstoshift
    positionstoshift[-1] += 1
    # Loop from the right, carry over as necessary
    for i in range(-1, -len(positionstoshift) - 1, -1):
    if positionstoshift[i] > finallen - piece_len(remainingpieces[i]):
    positionstoshift[i] = 0
    try:
    positionstoshift[i - 1] += 1
    except IndexError:
    # Can't carry over, hence reached the end
    stoploop = True
    break


    Output:





    Solution found:
    X...X......X....X..X
    X.X.....X.....X....X
    XX.X...X...X
    X.....X.X...X.....X
    X.X.X.X..X..

    Solution found:
    X.X.X.X..X..
    X...X......X....X..X
    X.X.....X.....X....X
    XX.X...X...X
    X.....X.X...X.....X







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Aug 31 at 16:25

























    answered Aug 31 at 16:20









    ace

    44429




    44429











    • your first 'solution' isn't
      – JonMark Perry
      Aug 31 at 16:23










    • @JonMarkPerry Sorry that was just me messing up the formatting on stackexchange
      – ace
      Aug 31 at 16:25










    • okay, but you should have found 120 solutions like this
      – JonMark Perry
      Aug 31 at 16:32










    • @JonMarkPerry How did you arrive at the number 120? I'm struggling to see how my algorithm skipped 118 cases.
      – ace
      Aug 31 at 16:38










    • your 2 solutions are permutations of each other by row, and there are 5!=5.4.3.2.1=120 of these.
      – JonMark Perry
      Aug 31 at 16:59
















    • your first 'solution' isn't
      – JonMark Perry
      Aug 31 at 16:23










    • @JonMarkPerry Sorry that was just me messing up the formatting on stackexchange
      – ace
      Aug 31 at 16:25










    • okay, but you should have found 120 solutions like this
      – JonMark Perry
      Aug 31 at 16:32










    • @JonMarkPerry How did you arrive at the number 120? I'm struggling to see how my algorithm skipped 118 cases.
      – ace
      Aug 31 at 16:38










    • your 2 solutions are permutations of each other by row, and there are 5!=5.4.3.2.1=120 of these.
      – JonMark Perry
      Aug 31 at 16:59















    your first 'solution' isn't
    – JonMark Perry
    Aug 31 at 16:23




    your first 'solution' isn't
    – JonMark Perry
    Aug 31 at 16:23












    @JonMarkPerry Sorry that was just me messing up the formatting on stackexchange
    – ace
    Aug 31 at 16:25




    @JonMarkPerry Sorry that was just me messing up the formatting on stackexchange
    – ace
    Aug 31 at 16:25












    okay, but you should have found 120 solutions like this
    – JonMark Perry
    Aug 31 at 16:32




    okay, but you should have found 120 solutions like this
    – JonMark Perry
    Aug 31 at 16:32












    @JonMarkPerry How did you arrive at the number 120? I'm struggling to see how my algorithm skipped 118 cases.
    – ace
    Aug 31 at 16:38




    @JonMarkPerry How did you arrive at the number 120? I'm struggling to see how my algorithm skipped 118 cases.
    – ace
    Aug 31 at 16:38












    your 2 solutions are permutations of each other by row, and there are 5!=5.4.3.2.1=120 of these.
    – JonMark Perry
    Aug 31 at 16:59




    your 2 solutions are permutations of each other by row, and there are 5!=5.4.3.2.1=120 of these.
    – JonMark Perry
    Aug 31 at 16:59










    up vote
    0
    down vote













    A start:



    Number the 25 positions $1dots 25$.



    I note that your 2nd piece occupies 4 positions of one parity and 1 of the other. So do your 3rd and 5th pieces. And your 4th occupies 5 positions all of the same parity.






    share|improve this answer
























      up vote
      0
      down vote













      A start:



      Number the 25 positions $1dots 25$.



      I note that your 2nd piece occupies 4 positions of one parity and 1 of the other. So do your 3rd and 5th pieces. And your 4th occupies 5 positions all of the same parity.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        A start:



        Number the 25 positions $1dots 25$.



        I note that your 2nd piece occupies 4 positions of one parity and 1 of the other. So do your 3rd and 5th pieces. And your 4th occupies 5 positions all of the same parity.






        share|improve this answer












        A start:



        Number the 25 positions $1dots 25$.



        I note that your 2nd piece occupies 4 positions of one parity and 1 of the other. So do your 3rd and 5th pieces. And your 4th occupies 5 positions all of the same parity.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 31 at 7:40









        Rosie F

        5,4732941




        5,4732941



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f71112%2f1-dimensional-jigsaw%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay