shaykarni

Impostor Chances

Sep 19th, 2020 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner s = new Scanner(System.in);
  7.        
  8.         System.out.print("Impostors: ");
  9.         int imp = s.nextInt();
  10.        
  11.         while (imp > 3 || imp < 1) {
  12.             System.err.println("There can only be 1, 2, or 3 impostors!");
  13.             System.out.print("Impostors: ");
  14.             imp = s.nextInt();
  15.         }
  16.        
  17.         System.out.print("Players: ");
  18.         double plrs = s.nextInt();
  19.        
  20.         if (imp == 1) {
  21.             while (plrs < 4 || plrs > 10) {
  22.                 System.err.println("Player count must be between 4 and 10!");
  23.                 System.out.print("Players: ");
  24.                 plrs = s.nextInt();
  25.             }
  26.         }
  27.         else if (imp == 2) {
  28.             while (plrs < 7 || plrs > 10) {
  29.                 System.err.println("Player count must be between 7 and 10!");
  30.                 System.out.print("Players: ");
  31.                 plrs = s.nextInt();
  32.             }
  33.         }
  34.         else {
  35.             while (plrs < 9 || plrs > 10) {
  36.                 System.err.println("Player count must be 9 or 10!");
  37.                 System.out.print("Players: ");
  38.                 plrs = s.nextInt();
  39.             }
  40.         }
  41.        
  42.         System.out.print("Party: ");
  43.         double party = s.nextInt();
  44.        
  45.         while (party > plrs || party < 1) {
  46.             System.err.println("Party has to have at least 1 member, and cannot be larger than the player count!");
  47.             System.out.print("Party: ");
  48.             party = s.nextInt();
  49.         }
  50.        
  51.         if (imp == 1) {
  52.             int simplify = simplifyFraction(party, plrs);
  53.             party /= simplify;
  54.             plrs /= simplify;
  55.            
  56.             System.out.println("Chances for 1 player: " + (party/plrs)*100 + "% (" + (int) party + "/" + (int) plrs + ")");
  57.         }  
  58.         else if (imp == 2)
  59.             twoImp(plrs, party);
  60.         else
  61.             threeImp(plrs, party);
  62.        
  63.         s.close();
  64.     }
  65.    
  66.     static void twoImp(double plrs, double party) {
  67.         double combos = 0;
  68.        
  69.         for (double i = plrs - 1; i > 0; i--) {
  70.             combos += i;
  71.         }
  72.        
  73.         double sum1 = 0;
  74.        
  75.         for (double i = plrs - 1; i >= plrs - party; i--) {
  76.             sum1 += i;
  77.         }
  78.        
  79.         int simplify = simplifyFraction(sum1, combos);
  80.         sum1 /= simplify;
  81.         double tmp = combos / simplify;
  82.        
  83.         System.out.println("Chances for 1 player: " + (sum1/tmp)*100 + "% (" + (int) sum1 + "/" + (int) tmp + ")");
  84.        
  85.         if (party >= 2) {
  86.             double sum2 = 0;
  87.            
  88.             for (double i = party - 1; i >= 1; i--) {
  89.                 sum2 += i;
  90.             }
  91.            
  92.             simplify = simplifyFraction(sum2, combos);
  93.             sum2 /= simplify;
  94.             tmp = combos / simplify;
  95.            
  96.             System.out.println("Chances for 2 players: " + (sum2/tmp)*100 + "% (" + (int) sum2 + "/" + (int) tmp + ")");
  97.         }
  98.     }
  99.    
  100.     static void threeImp(double plrs, double party) {
  101.         double combos = 0;
  102.        
  103.         for (double i = plrs - 2; i >= 1; i--) {
  104.             for (double j = i; j >= 1; j--) {
  105.                 combos += j;
  106.             }
  107.         }
  108.        
  109.         double sum1 = 0;
  110.        
  111.         for (double i = plrs - 2; i >= plrs - 2 - (party - 1); i--) {
  112.             for(double j = i; j >= 1; j--) {
  113.                 sum1 += j;
  114.             }
  115.         }
  116.        
  117.         int simplify = simplifyFraction(sum1, combos);
  118.         sum1 /= simplify;
  119.         double tmp = combos / simplify;
  120.        
  121.         System.out.println("Chances for 1 player: " + (sum1/tmp)*100 + "% (" + (int) sum1 + "/" + (int) tmp + ")");
  122.        
  123.         if (party >= 2) {
  124.             double sum2 = 0;
  125.            
  126.             for (double i = plrs - 2; i >= plrs - party; i--) {
  127.                 for (double j = i; j >= plrs - party; j--) {
  128.                     sum2 += j;
  129.                 }
  130.             }
  131.            
  132.             simplify = simplifyFraction(sum2, combos);
  133.             sum2 /= simplify;
  134.             tmp = combos / simplify;
  135.            
  136.             System.out.println("Chances for 2 players: " + (sum2/tmp)*100 + "% (" + (int) sum2 + "/" + (int) tmp + ")");
  137.         }
  138.        
  139.         if (party >= 3) {
  140.             double sum3 = 0;
  141.            
  142.             for (double i = party - 2; i >= 1; i--) {
  143.                 for (double j = i; j >= 1; j--) {
  144.                     sum3 += j;
  145.                 }
  146.             }
  147.            
  148.             simplify = simplifyFraction(sum3, combos);
  149.             sum3 /= simplify;
  150.             tmp = combos / simplify;
  151.            
  152.             System.out.println("Chances for 3 players: " + (sum3/tmp)*100 + "% (" + (int) sum3 + "/" + (int) tmp + ")");
  153.         }
  154.     }
  155.    
  156.     static int simplifyFraction(double a, double b) {
  157.         while (a != b) {
  158.             if (a > b)
  159.                 a -= b;
  160.             else
  161.                 b -= a;
  162.         }
  163.        
  164.         return (int) b;
  165.     }
  166.  
  167. }
  168.  
Add Comment
Please, Sign In to add comment