@glennyisbae/

Bulgarian Solitaire

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
class Main {
  public static void main(String[] args) {
    Scanner evan=new Scanner(System.in);
	System.out.print("What would you like your triangular number to be? ");
	int bill= evan.nextInt();
	int jill=0;
	for (int i=bill; i>0; i--){
		jill+=i;
	}
	ArrayList<Integer> will= new ArrayList<Integer>();
	int kill= (int)(Math.random()*(bill-1))+1;
	for (int i=0; i<kill; i++){
		will.add(0);
	}
	for (int i =0; i<kill-1; i++){
		will.set(i, (int)(Math.random()*jill));
		jill-=will.get(i);
	}
	will.set(kill-1, jill);
	will.removeIf(e-> e==0);
	System.out.print("Original:");
	display(will);
	int till=0;
	boolean basic=false;
	while (basic==false){
		will.replaceAll(n->n-1);
		will.add(will.size());
		will.removeIf(e-> e==0);
		display(will);
		till++;
		basic=true;
		for (int i=1; i<=bill; i++){
			if (will.contains(i)==false)
			basic=false;
		}	
	}
	System.out.println("It finished in "+till+ " turns");
  }
  public static void display(ArrayList<Integer> will){
  System.out.print("[");
	for (int i=0; i<will.size();i++){
		System.out.print(will.get(i));
		if (i!=will.size()-1)
		System.out.print(", ");
	}
	System.out.print("]");
	System.out.println();
  }
}