My Computer Programs

PRNG sequence guessing

steloflute 2015. 6. 7. 01:56

// https://www.hackerrank.com/challenges/prng-sequence-guessing
import java.util.Random;
import java.util.Scanner;

public class prng {
 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  int n = in.nextInt();
  for (int i = 0; i < n; i++) {   
   int a = in.nextInt();
   int b = in.nextInt();
   int[] prns = new int[10];
   for (int j = 0; j < 10; j++) {
    prns[j] = in.nextInt();
   }
   for (int s = a; s <= b; s++) {
    Random r = new Random();
    r.setSeed(s);
    boolean matched = true;
    for (int j = 0; j < 10; j++) {
     int c = r.nextInt(1000);     
     if (c != prns[j]) {
      matched = false;
      break;
     }
    }
    if (matched) {
     System.out.print(s);
     for (int j = 0; j < 10; j++) {
      int c = r.nextInt(1000);
      System.out.print(" " + c);
     }
     System.out.println();
     break;
    }
   }
  }
  in.close();
 }
}

'My Computer Programs' 카테고리의 다른 글

(Racket) naver-daum-top-search-scraper  (0) 2015.06.17
(Racket) naver-top-search-scraper  (0) 2015.06.17
LispScript  (0) 2015.04.30
(C#) KOSPI200 GUI Ticker  (0) 2015.03.25
(Clojure) cmdclock  (0) 2015.02.16