Untitled
raw download clone
TEXT
views 10
,
size 1658 b
package com.kuba;
import java.util.ArrayList;
import java.util.Random;

public class Lotto {

    public static void main(String[] args) {

        long start=System.currentTimeMillis();
        ArrayList<Integer> guesses = new ArrayList<Integer>();
        for (int i = 0; i < args.length; i++) {
            guesses.add(Integer.parseInt(args[i]));
        }
        System.out.println(guesses);

        ArrayList<Integer> num_random = new ArrayList<Integer>();
        Random random = new Random();

        for (int i = 0; i <= 5; i++) {

            int x;
            do {
                x = random.nextInt(1, 49);
            } while (num_random.contains(x));

            num_random.add(x);
        }
        System.out.println(num_random);

        int match_counter = 0;
        boolean is_six = false;
        int tries_counter = 0;


        while(!is_six) {
            for (int i = 0; i < args.length; i++) {
                if (num_random.contains(guesses.get(i))) {
                    match_counter++;
                }
            }

            tries_counter ++;

            if (match_counter == 6) {
                is_six = true;
            }
            match_counter = 0;


            for (int i = 0; i <= 5; i++) {

                int x;
                do {
                    x = random.nextInt(1, 49);
                } while (num_random.contains(x));

                num_random.set(i, x);
            }


        }
         System.out.println(tries_counter);
        long stop = System.currentTimeMillis();
        System.out.println(stop - start);
    }

}
close fullscreen
Login or Register to edit or fork this paste. It's free.