Please see my own answer, I think I did it!
Hi,
An example question for a programming contest was to write a program that finds out ho
Just solved this as well in java. Since all here appear to have performance issues. I give you mine as well.
Board reprsentation:
2 arrays of integers. 1 for the rows and 1 for the columns.
column[i]=row[size-(i+1)]
, row[i] = reverse(column[i])
where reverse is the bits reversed according to the size (for size = 4 and first 2 bits are taken: rev(1100) = 0011
)row[i-1] = row[i]
, col[i]<<=1
(row[r] & (1< 0
So this makes all operations fast. Many of them would have been O(size²)
in the 2D array representation instead of now O(size)
.
Algorithm:
Performance:
N=5
, time: 3msN=10
, time: 58msN=11
, time: 166msN=12
, time: 538msN=13
, time: 2893msN=14
, time:17266msN=15
, NA (out of heapspace)Code: https://github.com/Samjayyy/logicpuzzles/tree/master/polyominos