\documentstyle{report}

\pagestyle{myheadings}
\def\headlineaux{\sc Math 220/317: Programming II/Data Structures
\hrulefill
}
\markboth{\headlineaux}{\headlineaux}

\setlength{\textwidth}{6.25in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}



\newcommand{\assignmentNumber}{5}
\newcommand{\outdate}{October, not distrib., 1994}

\begin{document}
\begin{titlepage}\begin{centerline}{\Huge \framebox{Burt Rosenberg}}
\end{centerline}\end{titlepage}
                              
\section*{Answer Set \assignmentNumber \hfill{\parbox{3in}
    {\small\sc\begin{flushright} Out: \outdate\end{flushright}}}}
    

\begin{verbatim}
program partitions(input,output) ;

(* Partition program, solution to HW5 EC.
   Burt Rosenberg (c) 1994
   Univ. of Miami.
*)

const NPARTS = 50 ;
var
     parts : array[0..NPARTS] of integer ;

procedure partition( n : integer ; k : integer ) ;
(* list all partitions on n w/ largest element k or smaller.
   Recursion equation:
      either partition has a part size k or not.
      In the first case, place a k in next avail. parts cell and
      recurse on n-k. Note that k<=n in this case.
      In the second case, recurse on P(n,k-1)
   Terminal conditions:
      n=0: print out partition,
      k=1: do not recurse on P(n,0).
*)                                  

var
   i : integer ;
begin
   (* ASSERT parts[0] is the number of occupied cells in parts *)
   if (n=0) then begin
      for i:=1 to (parts[0]-1) do write(parts[i]:0,' + ') ;
      writeln( parts[parts[0]]:0)
   end else begin
      if (k<=n) then begin
         parts[0] := parts[0] + 1 ;
         parts[parts[0]] := k ;
         partition( n-k, k ) ;
         parts[0] := parts[0] - 1
      end ;
      if (k>1) then partition( n, k-1 ) ;
   end ;
end ;

var i : integer ;

begin
   parts[0] := 0 ;
   write('?> ') ;
   readln( i ) ;
   partition(i,i) ;

end .
\end{verbatim}

\end{document}

