Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SolutionA {
- public static void main(String[] args) {
- char[] letters = {'A','B','C','D','E','F','G','H','I'};
- char[] password = new char[4];
- int[] pos = new int[4];
- for(int i = 0; i<4;i++){
- pos[i] = 0;
- }
- boolean running = true;
- while(running){
- //i < n
- for(int i= 0; i < 4; i++){
- //i == n-1
- if(i == 3) {
- password[i] = letters[pos[i]++];
- if(pos[i] == letters.length) {
- for(int j = 3; j>=0; j--) {
- if((j !=3 && pos[j] != letters.length-1) || (j == 3 && pos[j] != letters.length)) {
- pos[j]++;
- break;
- }
- else if(j == 0 && pos[j] == letters.length-1) {
- running = false;
- }
- else {
- pos[j] = 0;
- }
- }
- }
- }
- else {
- password[i] = letters[pos[i]];
- }
- }
- boolean correct = true;
- if(password[0] != 'D' && password[0] != 'H' ) {
- correct = false;
- }
- for(int i = 0; i<4;i++){
- if(i <3){
- if(password[i] == 'G' && password[i+1] == 'A'){
- correct =false;
- }
- else if(password[i] == 'A' && password[i+1] == 'G'){
- correct = false;
- }
- }
- }
- for(int i = 0; i<4;i++){
- if(i <3){
- if(password[i] == 'B' && (password[i+1] != 'B' && password[i+1] != 'C')){
- correct =false;
- }
- }
- }
- if(correct) {
- System.out.println(password);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment