Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- System.out.print("Impostors: ");
- int imp = s.nextInt();
- while (imp > 3 || imp < 1) {
- System.err.println("There can only be 1, 2, or 3 impostors!");
- System.out.print("Impostors: ");
- imp = s.nextInt();
- }
- System.out.print("Players: ");
- double plrs = s.nextInt();
- if (imp == 1) {
- while (plrs < 4 || plrs > 10) {
- System.err.println("Player count must be between 4 and 10!");
- System.out.print("Players: ");
- plrs = s.nextInt();
- }
- }
- else if (imp == 2) {
- while (plrs < 7 || plrs > 10) {
- System.err.println("Player count must be between 7 and 10!");
- System.out.print("Players: ");
- plrs = s.nextInt();
- }
- }
- else {
- while (plrs < 9 || plrs > 10) {
- System.err.println("Player count must be 9 or 10!");
- System.out.print("Players: ");
- plrs = s.nextInt();
- }
- }
- System.out.print("Party: ");
- double party = s.nextInt();
- while (party > plrs || party < 1) {
- System.err.println("Party has to have at least 1 member, and cannot be larger than the player count!");
- System.out.print("Party: ");
- party = s.nextInt();
- }
- if (imp == 1) {
- int simplify = simplifyFraction(party, plrs);
- party /= simplify;
- plrs /= simplify;
- System.out.println("Chances for 1 player: " + (party/plrs)*100 + "% (" + (int) party + "/" + (int) plrs + ")");
- }
- else if (imp == 2)
- twoImp(plrs, party);
- else
- threeImp(plrs, party);
- s.close();
- }
- static void twoImp(double plrs, double party) {
- double combos = 0;
- for (double i = plrs - 1; i > 0; i--) {
- combos += i;
- }
- double sum1 = 0;
- for (double i = plrs - 1; i >= plrs - party; i--) {
- sum1 += i;
- }
- int simplify = simplifyFraction(sum1, combos);
- sum1 /= simplify;
- double tmp = combos / simplify;
- System.out.println("Chances for 1 player: " + (sum1/tmp)*100 + "% (" + (int) sum1 + "/" + (int) tmp + ")");
- if (party >= 2) {
- double sum2 = 0;
- for (double i = party - 1; i >= 1; i--) {
- sum2 += i;
- }
- simplify = simplifyFraction(sum2, combos);
- sum2 /= simplify;
- tmp = combos / simplify;
- System.out.println("Chances for 2 players: " + (sum2/tmp)*100 + "% (" + (int) sum2 + "/" + (int) tmp + ")");
- }
- }
- static void threeImp(double plrs, double party) {
- double combos = 0;
- for (double i = plrs - 2; i >= 1; i--) {
- for (double j = i; j >= 1; j--) {
- combos += j;
- }
- }
- double sum1 = 0;
- for (double i = plrs - 2; i >= plrs - 2 - (party - 1); i--) {
- for(double j = i; j >= 1; j--) {
- sum1 += j;
- }
- }
- int simplify = simplifyFraction(sum1, combos);
- sum1 /= simplify;
- double tmp = combos / simplify;
- System.out.println("Chances for 1 player: " + (sum1/tmp)*100 + "% (" + (int) sum1 + "/" + (int) tmp + ")");
- if (party >= 2) {
- double sum2 = 0;
- for (double i = plrs - 2; i >= plrs - party; i--) {
- for (double j = i; j >= plrs - party; j--) {
- sum2 += j;
- }
- }
- simplify = simplifyFraction(sum2, combos);
- sum2 /= simplify;
- tmp = combos / simplify;
- System.out.println("Chances for 2 players: " + (sum2/tmp)*100 + "% (" + (int) sum2 + "/" + (int) tmp + ")");
- }
- if (party >= 3) {
- double sum3 = 0;
- for (double i = party - 2; i >= 1; i--) {
- for (double j = i; j >= 1; j--) {
- sum3 += j;
- }
- }
- simplify = simplifyFraction(sum3, combos);
- sum3 /= simplify;
- tmp = combos / simplify;
- System.out.println("Chances for 3 players: " + (sum3/tmp)*100 + "% (" + (int) sum3 + "/" + (int) tmp + ")");
- }
- }
- static int simplifyFraction(double a, double b) {
- while (a != b) {
- if (a > b)
- a -= b;
- else
- b -= a;
- }
- return (int) b;
- }
- }
Add Comment
Please, Sign In to add comment