There is no need to test all cases. The ideal case is a swiss cheese in which no guest share a wall. Just start filling rooms from there if needed (the only problems is that room filling must follow an order, which makes the code quite large (but repetitive and boring), and there are two base cases for the swiss cheese structure). Maybe it's possible to create a function and decrease code size, but unless you see it at the moment that you are coding it, it would mean loosing too much time during competition when a Ctrl+C, Ctrl+V would be faster (and better than testing all cases).
Currently, my solutions and this one are the only that don't use brute force, but this one is the smallest. Congrats. :) (I was able to create a smaller solution after looking at your code.)
Select every other element of a vector
Create a cell array out of a struct
Rotate a Matrix by 90 degrees
Determine if input is a perfect number
Generate a vector like 1,2,2,3,3,3,4,4,4,4
Kaggle: Planetoid Game of Life - Total Score 0.10
GJam 2013 Veterans: Ocean View (Small)
Kaggle: Planetoid Game of Life - Variable Iterations for a wrapping array
PACMAT 06 - Optimized Ghosts, Equal Speed, Inf Lives; Interactive Download
GJam March 2016 IOW: Polynesiaglot Medium
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office