\begin{figure}
\begin{alltt}
function Training(data, K)
  Rules = BuildRules(data)
  for(k = 0; k < K; k++)
    Rules = Optimize(Rules, data)
  return Rules

function Optimize(Rules, data)
  for each rule in Rules
    Rules.remove(rule)
    UPos = instances in data.defective reported as nonDefective according to Rules
    UNeg = instances in data.nonDefective reported as defective according to Rules
    split(UPos, UNeg) into (GrowPos, GrowNeg) and (PrunePos, PruneNeg)
    RepRule = GrowRule(GrowPos, GrowNeg)
    RevRule = GrowRule(GrowPos, GrowNeg, rule)
    RepRule = PruneRule(RepRule, PrunePos, PruneNeg)
    RevRule = PruneRule(RevRule, PrunePos, PruneNeg)
        if(RevRule better than RepRule)
      Rules.add(RevRule)
    else
      Rules.add(RepRule)
      
function BuildRules(data)
  P = data.defective
  N = data.nonDefective
  Rules = \{\}
  DL = DescriptiveLength(Rules, P, N)
  while P \(\neq\) \{\}
    split (P, N) into (GrowPos, GrowNeg) and (PrunePos, PruneNeg)
    Rule = GrowRule(GrowPos, GrowNeg)
    Rule = PruneRule(Rule, PrunePos, PruneNeg)
    Rules.add(Rule)
    if(DescriptionLength(Rules, P, N) > DL + 64)
      for each rule in reverseOrder(Rules)
        if(DescriptionLength(Rules - {rule}, P, N) < DL then
          Rules.remove(rule)
          DL = DescriptionLength(Rules, P, N)
      return Rules
    DL = DescriptionLength(Rules, P, N)
    P.remove(instances in P reported as defective according to Rules)
    N.remove(instances in N reported as nonDefective according to Rules)
\end{alltt}
\caption{Pseudo code of RIPPER\cite{menziesExampleOfRipper}}\label{fig:pseudoCode-ripper}
\end{figure}
