Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.HashMap;
- public class mathwork {
- public static void main(String... args){
- double[][] input = new double[][] {
- new double[] {0.1, 4},
- new double[] {0.2, 3},
- new double[] {0.3, 2},
- new double[] {0.4, 1},
- };
- double Cost = 2.25;
- int NUMBER_OF_GAMES = 2;
- for(int NumberOfGames = NUMBER_OF_GAMES; NumberOfGames < NUMBER_OF_GAMES+1; NumberOfGames++){
- HashMap<Integer, Double> Initialmap = new HashMap<>();
- HashMap<Integer, Double> Dummymap = new HashMap<>();
- HashMap<Integer, Double> FinalMap = new HashMap<>();
- for(int i = 0; i < input.length; i++){
- Initialmap.put((int) Math.round(input[i][1]), input[i][0]);
- Dummymap.put((int) Math.round(input[i][1]), input[i][0]);
- }
- for(int i = 1; i < NumberOfGames; i++){
- for(int InitialKey : Initialmap.keySet()){
- for(int DummyKey : Dummymap.keySet()){
- int WinningValue = (int) Math.round(InitialKey + DummyKey);
- double WinningChance = Initialmap.get(InitialKey) * Dummymap.get(DummyKey);
- if(!FinalMap.containsKey(WinningValue)){
- FinalMap.put(WinningValue, WinningChance);
- }else{
- FinalMap.put(WinningValue, FinalMap.get(WinningValue) + WinningChance);
- }
- }
- }
- double InputCost = (i+1) * Cost;
- double WinningChance = 0;
- double LosingChance = 0;
- double EqualChance = 0;
- double ExpectedValue = 0;
- for(int FinalKey : FinalMap.keySet()){
- ExpectedValue += FinalMap.get(FinalKey) * FinalKey;
- if(FinalKey < InputCost){
- LosingChance += FinalMap.get(FinalKey);
- }else if(FinalKey == InputCost){
- EqualChance += FinalMap.get(FinalKey);
- }else{
- WinningChance += FinalMap.get(FinalKey);
- }
- }
- System.out.println("For " + (i+1) + " games: " + LosingChance + " chance to lose, " + EqualChance + " chance to equal, " + WinningChance + " chance to win. expected Value: " + ExpectedValue);
- Dummymap = new HashMap<>();
- for(int FinalKey : FinalMap.keySet()){
- Dummymap.put(FinalKey, FinalMap.get(FinalKey));
- }
- FinalMap = new HashMap<>();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment