public static void main(String[] args) throws IOException {

		/*boolx[] kmap = { boolx.F,boolx.F,boolx.T,boolx.F
			           , boolx.T,boolx.T,boolx.T,boolx.F
			           , boolx.F,boolx.T,boolx.T,boolx.T
			           , boolx.F,boolx.T,boolx.F,boolx.F
				       };

		Utility.rep4varKmap(kmap);
		System.out.println(KarnaughMapGrader.grade(4, kmap, true));
		
		if(true)
			return;*/
		
		BufferedReader br = new BufferedReader (
								new InputStreamReader(System.in));
		System.out.print("Type your id number                                         : ");
		int idNum = Integer.parseInt(br.readLine())%30+1;
		System.out.print("How many kmap do you want to see (-1 for just the best(s) ) : ");
		int numShowedState = Integer.parseInt(br.readLine());
		
		Permutation perm = new Permutation(8,7);
		assert perm.total >= numShowedState
				: "numShowedState exceed perm.total";
		// hareware coursework II ideal state diagram no. 25
		int[][] hwcw2isd = new int[8][2];
		
		for(int i=4;i>=0;i--) {
			if(idNum%2 == 1) {
				hwcw2isd[i][0] = 7;
				hwcw2isd[i][1] = (i==4) ? 6 : i+1;
			} else {
				hwcw2isd[i][0] = (i==4) ? 6 : i+1;
				hwcw2isd[i][1] = 7;
			}
			idNum >>= 1;
		}
		
		/*hwcw2isd25[0][0] = 7; hwcw2isd25[0][1] = 1; // reset
		hwcw2isd25[1][0] = 7; hwcw2isd25[1][1] = 2; // s1
		hwcw2isd25[2][0] = 3; hwcw2isd25[2][1] = 7; // s2 
		hwcw2isd25[3][0] = 4; hwcw2isd25[3][1] = 7; // s3
		hwcw2isd25[4][0] = 7; hwcw2isd25[4][1] = 6; // s4*/
		hwcw2isd[5] = null;                       // unused state
		hwcw2isd[6][0] = 0; hwcw2isd[6][1] = 6; // open
		hwcw2isd[7][0] = 7; hwcw2isd[7][1] = 7; // alarm
		
		int[] assignment = new int[8];
		
		StateToKarnaughMap[] states = new StateToKarnaughMap[perm.total];
		
		for(int i=0;i<states.length;i++) {
			hwcw2UpdateAssignment(assignment,perm);
			states[i] = new StateToKarnaughMap(hwcw2isd,2,3,assignment);
			perm.next();
		}
		
		Arrays.sort(states);
		
		if(numShowedState >= 0) {
			for(int i=0;i<numShowedState;i++)
				hwcw2PrintState(states[i]);
		} else {
			for(int i=0;i<states.length;i++)
				if(states[i].score == states[0].score)
					hwcw2PrintState(states[i]);
		}
	}