/*
contains a method for checking if two arrays of ints have exactly the same contents, but with order not important. 
It is assumed that the arrays are of the same length, and contain no duplicates
*/


public class TwoArraysEqual {

    public static void main(String []args) {
	int [] a = {1,2,3,4,5,6,7,8,9,10};
	int [] b = {10,9,8,7,6,5,4,3,2,1};
	int [] c = {1,2,3,4,5,6,7,11,9,10};
	int [] shorta = {1,2,3,4,5};
	int [] dupa = {1,2,3,4,5,5,5,5,5,5};
	

	System.out.println(twoArraysEqual(a,b));
	System.out.println(twoArraysEqual(a,c));
	
	System.out.println(twoArraysEqual(shorta, b) + " (WRONG)"); // This violates the assumption about the same length, and gives True, but incorrectly!
	System.out.println(twoArraysEqual(b, shorta)); // This way it is ok.

	System.out.println(twoArraysEqual(dupa, b) + " (WRONG)"); // This violates the assumption about duplicates, and gives True, but incorrectly!
	System.out.println(twoArraysEqual(b, dupa)); // This way it is ok.


    }


    // Note, assuming methods are equal in length, neither contains a duplicate!
    public static boolean twoArraysEqual(int[] a1, int[] a2) {
	for (int i = 0; i < a1.length; i++) { // go through each element of a1
	    boolean isInJ = false; // default condition, assume a1[i] is NOT in a2 and change it if it is. 
	    for(int j = 0; j < a2.length; j++) { // go through each element of a2
		if(a1[i]==a2[j]) { 
		    isInJ = true;
		}
	    }
	    if(!isInJ) {
		return false; 
		// there is one element in a1 that was NOT found in a2. We
		//only care about perfect matches so no need to continue; 
	    }

	}

	
	//Assuming they contain no duplicates and are of the same size, every element in a is in b and therefore every element of b is in a. 
	// How can we make this method better to handle the case that they are not the same length, and duplicates are allowed?

	//How can we change it so that only a certain percentage of ints in a1 need to be in a2, and vice versa?

	return true;

    }

}