No unique solution. For me it is the last solution of the permutation matrix.
For which test statement is there not a unique solution? We need to fix the test suite if there are two answers of same score.
Sorry, it was a mistake.
The statement of the problem is incorrect: "the sum of the absolute values of the differences is zero." You want the smallest sum, but it isn't necessarily zero.
Is there any size constraint on this problem ? My solution is not getting accepted ...
Best solution without lookup table
Never thought for-loop can be used for a matrix.
Aww.. ran out of memory.
%the part of the code i cut out, should work in theory ..
fliplist = fliplr(list);
idx = triu(ones(length(list)),0);
for j = 1:length(idx)
idx2 = unique(perms(idx(j,:)),'rows');
[a b] = size(idx2);
for i = 1 : a
idxi = boolean(idx2(i,:)');
list2 = list;
list2(idxi,:) = fliplist(idxi,:);
list2 = list2';
list2 = list2(:);
dlist = abs(diff(list2));
val2 = sum(dlist(2:2:end));
if val2 < val
val = val2;
orientation = idxi';
if val == 0
First N Perfect Squares
Who knows the last digit of pi?
Sum of first n terms of a harmonic progression
Remove from a 2-D matrix all the rows that contain at least one element less than or equal to 4
02 - Vector Variables 1
How many trades represent all the profit?
Getting the indices from a vector
Make a random, non-repeating vector.
Flag largest magnitude swings as they occur
Project Euler: Problem 1, Multiples of 3 and 5
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