function N = HadSolveFlops(n)
% n is a power of 2.
% N is the number of flops required to solve an order-n Hadamard system.

if n==1
% Nothing to do since H1*x = x
N = 0;
else
m = n/2;
% There are two recursive calls, a pair of length-m vector adds,
% and a pair of length-m vector scales so
N = 2*HadSolveFlops(n/2)+2*m+2*m;
end

% Grading (2 points):
% 1 point for a base case (n=1) that is 0 or 1
% 1 point for a recursive case that correctly counts the 2 recursive
% calls and the 2n work done by each call.
%
% A few solutions managed to do it in 1.5n, and one had a solution that
% did it in 1n. Some added 1 for computing n/2.

% Common issues:
% -Failure to work for n=1 (usually when using 2 as the base case) (-1)
% -Calls HadSolveFlops(m) twice instead of multiplying one call by 2 (-0)
% -Miscount the 2n flops per recursive call (-1)
% -Count only flops for only 1 recursive call (-1)