import java.util.*;
import java.io.*;

public class Util
{
    public static final String YOUR_TICKET = "your ticket:";
    public static final String NEARBY_TICKETS = "nearby tickets:";

    public static final String OR = "or";

    public static final boolean checkAlCategories (Vector<Category> cats, Ticket t)
    {
        boolean[] valid = new boolean[cats.size()];

        for (int i = 0; i < cats.size(); i++)
        {
            valid[i] = false;

            if (cats.elementAt(i).valid(t))
                valid[i] = true;
        }

        boolean ultimateValidity = true;

        for (int j = 0; j < valid.length; j++)
        {
            if (!valid[j])
                ultimateValidity = false;
        }

        System.out.println("Checked all categories and "+t+" validity is "+ultimateValidity);

        return ultimateValidity;
    }

    // read the category data and ignore ticket information.

    public static final Vector<Category> loadCategories (String inputFile, boolean debug)
    {
        /*
         * Open the data file and read it in.
         */

        BufferedReader reader = null;
        Vector<Category> values = new Vector<Category>();

        try
        {
            reader = new BufferedReader(new FileReader(inputFile));

            String line = null;
            boolean finished = false;

            while (((line = reader.readLine()) != null) && !finished)
            {
                if (YOUR_TICKET.equals(line) || (NEARBY_TICKETS.equals(line))) // end
                    finished = true;
                else
                {
                    int colonIndex = line.indexOf(":");

                    if (colonIndex != -1)
                    {
                        String type = line.substring(0, colonIndex);

                        int orIndex = line.indexOf(OR);
                        String firstRange = line.substring(colonIndex +1, orIndex).trim();
                        String secondRange = line.substring(orIndex + OR.length()).trim();
                        int r1 = Integer.parseInt(firstRange.substring(0, firstRange.indexOf("-")));
                        int r2 = Integer.parseInt(firstRange.substring(firstRange.indexOf("-") +1));
                        int r3 = Integer.parseInt(secondRange.substring(0, secondRange.indexOf("-")));
                        int r4 = Integer.parseInt(secondRange.substring(secondRange.indexOf("-") +1));

                        Category cat = new Category(type, r1, r2, r3, r4, debug);

                        if (debug)
                            System.out.println("Loaded "+cat);

                        values.add(cat);
                    }
                }
            }
        }
        catch (Throwable ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            try
            {
                reader.close();
            }
            catch (Throwable ex)
            {
            }
        }

        return values;
    }

    // read the ticket data and ignore categories.

    public static final Vector<Ticket> loadTickets (String inputFile, boolean debug)
    {
        /*
         * Open the data file and read it in.
         */

        BufferedReader reader = null;
        Vector<Ticket> values = new Vector<Ticket>();

        try
        {
            reader = new BufferedReader(new FileReader(inputFile));

            String line = null;
            boolean ticketData = false;

            while ((line = reader.readLine()) != null)
            {
                if (YOUR_TICKET.equals(line) || NEARBY_TICKETS.equals(line))
                {
                    ticketData = true;
                }
                else
                {
                    if (ticketData && (line.indexOf(",") != -1))
                    {
                        String[] range = line.split(",");
                        Ticket t = new Ticket(range);

                        values.add(t);
                    }
                }
            }
        }
        catch (Throwable ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            try
            {
                reader.close();
            }
            catch (Throwable ex)
            {
            }
        }

        return values;
    }

    private Util ()
    {
    }
}
@@ -220,24 +220,74 @@
 OR = %22or%22;%0A%0A
+    public static final int CHECKED_NUMBER = -1;%0A%0A
     public s
@@ -376,140 +376,480 @@
     
-boolean
+int
 %5B%5D val
-id
+ues
  = new 
-boolean%5Bcats.size()%5D;%0A%0A        for (int i = 0; i %3C cats.size(); i++)%0A        %7B%0A            valid%5Bi
+int%5Bt.values().length%5D;%0A%0A        for (int k = 0; k %3C values.length; k++)%0A            values%5Bk%5D = t.values()%5Bk%5D;%0A%0A        System.out.println(%22%5CnSTART CHECK %22+t);%0A%0A        for (int i = 0; i %3C cats.size(); i++)%0A        %7B%0A            for (int j = 0; j %3C values.length; j++)%0A            %7B%0A                if (values%5Bj
 %5D 
+!
 = 
-false;%0A%0A
+CHECKED_NUMBER)%0A                %7B%0A                    System.out.println(%22Checking %22+values%5Bj%5D+%22 against %22+cats.elementAt(i));%0A%0A        
     
@@ -884,17 +884,25 @@
 ).valid(
-t
+values%5Bj%5D
 ))%0A     
@@ -916,76 +916,263 @@
     
-valid%5Bi%5D = true;%0A        %7D%0A%0A        boolean ultimateValidity = true;
+    %7B%0A                        System.out.println(%22VALID%22);%0A%0A                        values%5Bj%5D = CHECKED_NUMBER;%0A                    %7D%0A                    else%0A                        System.out.println(%22INVALID%22);%0A                %7D%0A            %7D%0A        %7D
 %0A%0A  
@@ -1200,18 +1200,19 @@
  j %3C val
-id
+ues
 .length;
@@ -1247,60 +1247,50 @@
 if (
-!
 val
-id%5Bj%5D)%0A                ultimateValidity = false;
+ues%5Bj%5D != CHECKED_NUMBER)%0A            %7B
 %0A   
@@ -1286,35 +1286,32 @@
       %7B%0A        
-%7D%0A%0A
         System.o
@@ -1326,71 +1326,40 @@
 ln(%22
-Checked all categories and %22+t+%22 validity is %22+ultimateV
+Number %22+values%5Bj%5D+%22 is inv
 alid
-ity
+%22
 );%0A%0A
@@ -1370,31 +1370,74 @@
     
-return ultimateValidity
+        return false;%0A            %7D%0A        %7D%0A%0A        return true
 ;%0A  

Update Util.java