%%%%%%%
% signedperms.m
% Author: Lance Harden, Davidson College
% June 2006
% 
% Description: This function is equivalent to MATLAB's perms function for
% signed permutations. Its output is a matrix that displays each signed
% permutation as a row. Helpful when used in combination with the other
% pancake simulator functions.

function [A] = signedperms(k);
A = [];

temp = [ones(1,k); -ones(1,k)];
sign = unique(nchoosek(temp(:)',k),'rows');
order = perms(1:k);

for i = 1:factorial(k)
    for j = 1:(2^k)
        if i == 1
            A(j,:) = sign(j,:).*order(i,:);
        else
            A(j + ((2^k)*(i-1)),:) = sign(j,:).*order(i,:);
        end
    end
end