long randomNumber; 
void setup() {
  Serial.begin(9600); 
  int a[] = {10,11,12,13,14,15,16,17,18};
  for(int i = 0; i<9; i++) {
    pinMode(a[i], INPUT);
  }

  int b[] = {0,1,2,3,4,5,6,7,8,9,19};
  for(int i = 0; i<8; i++) {
    pinMode(b[i], OUTPUT);
  pinMode(A6, OUTPUT); 
  pinMode(A3, INPUT); 
  }
}

void loop() {
    int myInts[0];
    int myInts2[0]; 
    
    if (digitalRead(10) == HIGH) {// 1st Digit Read
       myInts[0] = 1;
    } else {
       myInts[0] = 0;
    }
    
    if (digitalRead(11) == HIGH) {
       myInts[1] = 2;
    } else {
       myInts[1] = 0;
    }
    
    if (digitalRead(12) == HIGH) {
       myInts[2] = 4;
    } else { 
       myInts[2] = 0;
    }
    
    if (digitalRead(13) == HIGH) {
        myInts[3] = 8;
    } else {
       myInts[3] = 0;
    }

   if (digitalRead(14) == HIGH) {//2nd Digital Read
       myInts2[0] = 1;
    } else {
       myInts2[0] = 0;
    }
    
    if (digitalRead(15) == HIGH) {
       myInts2[1] = 2;
    } else {
       myInts2[1] = 0;
    }
    
    if (digitalRead(16) == HIGH) {
       myInts2[2] = 4;
    } else { 
       myInts2[2] = 0;
    }
    
    if (digitalRead(17) == HIGH) {
        myInts2[3] = 8;
    } else {
       myInts2[3] = 0;
    }
     
     int y = myInts[0] + myInts[1] + myInts[2] + myInts[3];
     int z = myInts2[0] + myInts2[1] + myInts2[2] + myInts2[3]; 
     int t = 10*y + z;
     int x;
     
    if (t == 0) {
      digitalWrite(0, HIGH); 
      x = 100;
    } else {
      digitalWrite(0, LOW);
      x = t;
    }
 
  while (digitalRead(18) == HIGH) {
    digitalWrite(1, LOW); 
    leds1(LOW, LOW, LOW, LOW);
    leds1(HIGH, LOW, LOW, LOW);
    leds1(LOW, HIGH, LOW, LOW);
    leds1(HIGH, HIGH, LOW, LOW); 
    leds1(LOW, LOW, HIGH, LOW); 
    leds1(HIGH, LOW, HIGH, LOW);
    leds1(LOW, HIGH, HIGH, LOW); 
    leds1(HIGH, HIGH, HIGH, LOW);
    leds1(LOW, LOW, LOW, HIGH); 
    leds1(HIGH, LOW, LOW, HIGH);
    leds2(LOW, LOW, LOW, LOW);
    leds2(HIGH, LOW, LOW, LOW);
    leds2(LOW, HIGH, LOW, LOW);
    leds2(HIGH, HIGH, LOW, LOW); 
    leds2(LOW, LOW, HIGH, LOW); 
    leds2(HIGH, LOW, HIGH, LOW);
    leds2(LOW, HIGH, HIGH, LOW); 
    leds2(HIGH, HIGH, HIGH, LOW);
    leds2(LOW, LOW, LOW, HIGH); 
    leds2(HIGH, LOW, LOW, HIGH);

     randomSeed(analogRead(6) + analogRead(7)); 
     int randomNumber2;
     int v;
     int output;
     int w = random(1,x+1); 
     
    if (w == 100) {
    digitalWrite(1, HIGH); 
  
    delay(5);
    } else {
     randomNumber = w%10;
     v = w - randomNumber;
     randomNumber2 = v/10; 
     output = randomNumber2*10 + randomNumber; 
     Serial.print(w);
    
     int c;
     int d;
     int e;
     int f;
     int g;
     int h;
     int i; 
     int j; 

    if (randomNumber > 7) {// 1st Digit Write
      f = HIGH;
      randomNumber = randomNumber % 8;
    } else {
      f = LOW;
    }
    
    if (randomNumber > 3) {
      e = HIGH;
      randomNumber = randomNumber % 4;
    } else {
      e = LOW;
    }
    
    if (randomNumber > 1) {
      d = HIGH;
      randomNumber = randomNumber % 2;
    } else {
      d = LOW;
    }

    if (randomNumber > 0) {
      c = HIGH;
      randomNumber = randomNumber % 1;
    } else {
      c = LOW;
    }

     if (randomNumber2 > 7) {// 2nd Digit Write
      j = HIGH;
      randomNumber2 = randomNumber2 % 8;
    } else {
      j = LOW;
    }
    
    if (randomNumber2 > 3) {
      i = HIGH;
      randomNumber2 = randomNumber2 % 4;
    } else {
      i = LOW;
    }
    
    if (randomNumber2 > 1) {
      h = HIGH;
      randomNumber2 = randomNumber2 % 2;
    } else {
      h = LOW;
    }

    if (randomNumber2 > 0) {
      g = HIGH;
      randomNumber2 = randomNumber2 % 1;
    } else {
      g = LOW;
    }
      
    digitalWrite(5, c);
    digitalWrite(4, d);
    digitalWrite(3, e);
    digitalWrite(2, f);
    delay(5);
    digitalWrite(9, g); 
    digitalWrite(8, h);
    digitalWrite(7, i);
    digitalWrite(6, j);
    delay(5);
    }
  }
}

void leds1(int a, int b, int c, int d) {
  digitalWrite(5, a);
  digitalWrite(4, b);
  digitalWrite(3, c);
  digitalWrite(2, d);
  delay(5);
}
void leds2(int a, int b, int c, int d) {
  digitalWrite(9, a);
  digitalWrite(8, b);
  digitalWrite(7, c);
  digitalWrite(6, d);
  delay(5);
}