Skip to content

Instantly share code, notes, and snippets.

@fu5ha
Last active June 16, 2017 18:52
Show Gist options
  • Save fu5ha/418be10c8830c375c762c48107901d49 to your computer and use it in GitHub Desktop.
Save fu5ha/418be10c8830c375c762c48107901d49 to your computer and use it in GitHub Desktop.
PUBG Crate Analysis
const fs = require("fs");
const inputData = JSON.parse(fs.readFileSync('data.json', 'utf-8'));
function round(value, decimals) {
return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
}
const level3Types = [
"Level 3 Military Vest",
"Level 3 Helmet",
"Level 3 Backpack"
];
const sniperTypes = [
"SKS",
"M24",
"AWM",
"Kar98",
"VSS"
];
function crateHasAnyOfTypes(crate, types) {
return types.reduce((hasItem, item) => hasItem || item in crate, false);
}
function numberOfTypesInCrate(crate, types) {
return types.reduce((numberOfItems, item) => numberOfItems + (item in crate ? crate[item] : 0), 0);
}
function numberOfCratesWithTypes(data, types) {
return data.filter((crate) => crateHasAnyOfTypes(crate, types)).length;
}
function totalNumberOfTypes(data, types) {
return data.reduce((totalItems, crate) => totalItems + numberOfTypesInCrate(crate, types), 0);
}
function chanceOfCrateWithTypes(data, types) {
return numberOfCratesWithTypes(data, types) / data.length;
}
function numberOfCratesWithTwoSameTypes(data, types) {
return data.filter((crate) => numberOfTypesInCrate(crate, types) >= 2).length;
}
function numberOfCratesWithTwoDifferentTypes(data, types1, types2) {
return data.filter(crate => crateHasAnyOfTypes(crate, types1) && crateHasAnyOfTypes(crate, types2)).length;
}
function numberOfCratesWithTypes1NotTypes2(data, types1, types2) {
return data.filter(crate => crateHasAnyOfTypes(crate, types1) && !(crateHasAnyOfTypes(crate, types2))).length;
}
function numberOfCratesWithoutTypes(data, types) {
return data.filter(crate => !(crateHasAnyOfTypes(crate, types))).length;
}
function chanceOfCrateWithTypes1GivenTypes2(data, types1, types2) {
return numberOfCratesWithTwoDifferentTypes(data,types1,types2) / numberOfCratesWithTypes(data,types2);
}
function chanceOfCrateWithTypes1NotTypes2(data, types1, types2) {
return numberOfCratesWithTypes1NotTypes2(data,types1,types2) / numberOfCratesWithoutTypes(data,types2);
}
console.log("Number of crates with one or more level 3 gear pieces: " + round(numberOfCratesWithTypes(inputData, level3Types),2));
console.log("Number of crates with two or more level 3 gear pieces: " + round(numberOfCratesWithTwoSameTypes(inputData, level3Types),2));
console.log("");
console.log("Number of crates with snipers: " + round(numberOfCratesWithTypes(inputData, sniperTypes),2));
console.log("Total number of snipers: " + round(totalNumberOfTypes(inputData, sniperTypes),2));
console.log("Chance to find crate with sniper weapon: " + round(chanceOfCrateWithTypes(inputData, sniperTypes),2));
console.log("");
console.log("Number of crates with one or more 8x scopes: " + round(numberOfCratesWithTypes(inputData, ["8X Scope"]),2));
console.log("Number of crates with two or more 8x scopes: " + round(numberOfCratesWithTwoSameTypes(inputData, ["8X Scope"]),2));
console.log("");
console.log("Number of crates with 15x scopes: " + round(numberOfCratesWithTypes(inputData, ["15X Scope"]),2));
console.log("Total number of 15x scopes: " + round(totalNumberOfTypes(inputData, ["15X Scope"]),2));
console.log("Chance to find crate with 15x scope: " + round(chanceOfCrateWithTypes(inputData, ["15X Scope"]),2));
console.log("Chance to find 15x scope when there is a sniper in the crate: " + round(chanceOfCrateWithTypes1GivenTypes2(inputData, ["15X Scope"], sniperTypes),2));
console.log("Chance to find 15x scope when there is no sniper in the crate: " + round(chanceOfCrateWithTypes1NotTypes2(inputData, ["15X Scope"], sniperTypes),2));
console.log("");
console.log("Number of crates with ghillie suits: " + round(numberOfCratesWithTypes(inputData, ["Ghillie Suit"]),2));
console.log("Total number of ghillie suits: " + round(totalNumberOfTypes(inputData, ["Ghillie Suit"]),2));
console.log("Chance to find crate with ghillie suit: " + round(chanceOfCrateWithTypes(inputData, ["Ghillie Suit"]),2));
console.log("Chance to find ghillie suit when there is a sniper in the crate: " + round(chanceOfCrateWithTypes1GivenTypes2(inputData, ["Ghillie Suit"], sniperTypes),2));
console.log("Chance to find ghillie suit when there is no sniper in the crate: " + round(chanceOfCrateWithTypes1NotTypes2(inputData, ["Ghillie Suit"], sniperTypes),2));
/* ================ OUTPUTS =================
Number of crates with one or more level 3 gear pieces: 56
Number of crates with two or more level 3 gear pieces: 0
Number of crates with snipers: 62
Total number of snipers: 62
Chance to find crate with sniper weapon: 0.61
Number of crates with one or more 8x scopes: 42
Number of crates with two or more 8x scopes: 1
Number of crates with 15x scopes: 6
Total number of 15x scopes: 6
Chance to find crate with 15x scope: 0.06
Chance to find 15x scope when there is a sniper in the crate: 0.06
Chance to find 15x scope when there is no sniper in the crate: 0.05
Number of crates with ghillie suits: 17
Total number of ghillie suits: 17
Chance to find crate with ghillie suit: 0.17
Chance to find ghillie suit when there is a sniper in the crate: 0.16
Chance to find ghillie suit when there is no sniper in the crate: 0.18
================ OUTPUTS ================== */
[
{
"Ghillie Suit": 1,
"M249": 1,
"8X Scope": 2,
"5.56": 200
},
{
"Ghillie Suit": 1,
"Tommy Gun": 1,
"ACP": 100,
"Level 3 Backpack": 1
},
{
"SKS": 1,
"7.62": 30,
"8X Scope": 1,
"Level 3 Military Vest": 1,
"Adrenaline Syringe": 1
},
{
"Ghillie Suit": 1,
"Kar98": 1,
"7.62": 40,
"Level 3 Military Vest": 1,
"Adrenaline Syringe": 1,
"Ext. Quickdraw Mag (AR)": 1
},
{
"M249": 1,
"5.56": 200,
"Level 3 Military Vest": 1,
"Medkit": 1,
"Ext. Quickdraw Mag (Sniper)": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1
},
{
"M24": 1,
"7.62": 15,
"15X Scope": 1,
"Adrenaline Syringe": 1
},
{
"Kar98": 1,
"7.62": 20,
"Level 3 Backpack": 1,
"First Aid Kit": 1
},
{
"M24": 1,
"7.62": 15,
"Level 3 Backpack": 1,
"Adrenaline Syringe": 1
},
{
"AWM": 1,
".300": 20,
"8X Scope": 1,
"Vertical Grip": 1
},
{
"M24": 1,
"7.62": 15,
"Ghillie Suit": 1
},
{
"VSS": 1,
"9mm": 90,
"Medkit": 1,
"Level 3 Military Vest": 1
},
{
"M249": 1,
"5.56": 100,
"15X Scope": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1,
"Tactical Stock": 1,
"Level 3 Backpack": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1,
"Adrenaline Syringe": 1,
"Level 3 Backpack": 1
},
{
"VSS": 1,
"9mm": 60,
"Adrenaline Syringe": 1,
"Tactical Stock": 1,
"Level 3 Backpack": 1
},
{
"AWM": 1,
".300": 20,
"Vertical Grip": 1
},
{
"VSS": 1,
"9mm": 90,
"Cheekpad": 1,
"Level 3 Backpack": 1
},
{
"M249": 1,
"5.56": 100,
"8X Scope": 1,
"Medkit": 1,
"Tactical Stock": 1
},
{
"M24": 1,
"7.62": 15,
"Level 3 Military Vest": 1
},
{
"M249": 1,
"5.56": 100,
"Adrenaline Syringe": 1,
"Medkit": 1
},
{
"Tommy Gun": 1,
"ACP": 200
},
{
"Tommy Gun": 1,
"ACP": 200,
"Vertical Grip": 1
},
{
"Kar98": 1,
"7.62": 15,
"Tactical Stock": 1,
"Medkit": 1
},
{
"AWM": 1,
".300": 20,
"First Aid Kit": 1,
"Tactical Stock": 1,
"Level 3 Military Vest": 1,
"8X Scope": 1
},
{
"Kar98": 1,
"7.62": 15,
"Ghillie Suit": 1,
"Level 3 Backpack": 1
},
{
"VSS": 1,
"Compensator (Sniper)": 1,
"First Aid Kit": 1
},
{
"Tommy Gun": 1,
"ACP": 100,
"8X Scope": 1,
"Level 3 Helmet": 1
},
{
"M249": 1,
"5.56": 100,
"Level 3 Military Vest": 1,
"Ext. Quickdraw Mag (AR)": 1
},
{
"Ghillie Suit": 1,
"VSS": 1,
"9mm": 90
},
{
"M249": 1,
"5.56": 100,
"8X Scope": 1,
"Level 3 Backpack": 1,
"Cheekpad": 1
},
{
"Tommy Gun": 1,
"ACP": 100,
"8X Scope": 1,
"Level 3 Backpack": 1
},
{
"Kar98": 1,
"Medkit": 1,
"Vertical Grip": 1,
"Level 3 Backpack": 1
},
{
"VSS": 1,
"9mm": 90,
"Medkit": 1,
"Ext. Quickdraw Mag (AR)": 1
},
{
"AWM": 1,
".300": 20,
"Adrenaline Syringe": 1,
"Vertical Grip": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1,
"Level 3 Military Vest": 1,
"Painkiller": 1
},
{
"VSS": 1,
"9mm": 90,
"Level 3 Military Vest": 1,
"Vertical Grip": 1
},
{
"M249": 1,
"5.56": 100,
"8X Scope": 1,
"Level 3 Helmet": 1
},
{
"VSS": 1,
"9mm": 90,
"Level 3 Helmet": 1,
"8X Scope": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1,
"Level 3 Backpack": 1,
"Compensator (AR)": 1
},
{
"M249": 1,
"5.56": 100,
"Adrenaline Syringe": 1
},
{
"M249": 1,
"5.56": 100,
"8X Scope": 1,
"Compensator (AR)": 1
},
{
"VSS": 1,
"9mm": 90,
"8X Scope": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1,
"Ghillie Suit": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1
},
{
"M249": 1,
"5.56": 100,
"Ext. Quickdraw Mag (Sniper)": 1
},
{
"M249": 1,
"5.56": 100,
"Ghillie Suit": 1,
"Level 3 Helmet": 1
},
{
"M249": 1,
"5.56": 100,
"8X Scope": 1
},
{
"Tommy Gun": 1,
"ACP": 100,
"Ghillie Suit": 1,
"Medkit": 1
},
{
"Kar98": 1,
"7.62": 15,
"Ghillie Suit": 1
},
{
"Kar98": 1,
"7.62": 15,
"Level 3 Helmet": 1
},
{
"AWM": 1,
".300": 20,
"8X Scope": 1,
"Level 3 Military Vest": 1
},
{
"M249": 1,
"5.56": 100,
"Level 3 Backpack": 1
},
{
"Tommy Gun": 1,
"ACP": 200,
"15X Scope": 1
},
{
"Tommy Gun": 1,
"ACP": 100,
"Level 3 Military Vest": 1,
"Adrenaline Syringe": 1,
"Medkit": 1
},
{
"VSS": 1,
"9mm": 90,
"Level 3 Backpack": 1,
"Tactical Stock": 1,
"Adrenaline Syringe": 1
},
{
"Tommy Gun": 1,
"ACP": 100,
"8X Scope": 1,
"Vertical Grip": 1,
"Level 3 Backpack": 1,
"Medkit": 1
},
{
"M24": 1,
"7.62": 30,
"8X Scope": 1,
"Medkit": 1,
"Ext. Quickdraw Mag (Sniper)": 1
},
{
"AWM": 1,
".300": 20,
"Level 3 Backpack": 1
},
{
"M24": 1,
"7.62": 30,
"8X Scope": 1,
"Level 3 Helmet": 1
},
{
"Kar98": 1,
"7.62": 15,
"Level 3 Military Vest": 1,
"Painkiller": 1,
"Tactical Stock": 1
},
{
"Tommy Gun": 1,
"ACP": 200,
"Level 3 Helmet": 1,
"Ghillie Suit": 1,
"Tactical Stock": 1
},
{
"Tommy Gun": 1,
"ACP": 200,
"Level 3 Military Vest": 1,
"Medkit": 1
},
{
"AWM": 1,
".300": 20,
"Adrenaline Syringe": 1,
"Ext. Quickdraw Mag (Sniper)": 1,
"Level 3 Backpack": 1
},
{
"Tommy Gun": 1,
"ACP": 200,
"Level 3 Military Vest": 1,
"8X Scope": 1
},
{
"M249": 1,
"5.56": 100,
"Ghillie Suit": 1,
"Adrenaline Syringe": 1,
"Compensator (Sniper)": 1,
"8X Scope": 1,
"Level 3 Helmet": 1
},
{
"M249": 1,
"5.56": 100,
"Ext. Quickdraw Mag (Sniper)": 1,
"Level 3 Backpack": 1
},
{
"M249": 1,
"5.56": 200,
"Vertical Grip": 1,
"Compensator (AR)": 1,
"Medkit": 1
},
{
"Kar98": 1,
"7.62": 15,
"15X Scope": 1,
"Adrenaline Syringe": 1,
"Level 3 Helmet": 1
},
{
"VSS": 1,
"9mm": 90,
"Tactical Stock": 1,
"Level 3 Military Vest": 1
},
{
"AWM": 1,
".300": 20,
"Ghillie Suit": 1,
"8X Scope": 1,
"Tactical Stock": 1,
"Level 3 Helmet": 1
},
{
"AWM": 1,
".300": 20,
"8X Scope": 1
},
{
"Kar98": 1,
"7.62": 15,
"Ghillie Suit": 1,
"Compensator (AR)": 1
},
{
"AWM": 1,
".300": 20,
"8X Scope": 1,
"Medkit": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1,
"Adrenaline Syringe": 1,
"Ghillie Suit": 1,
"Compensator (AR)": 1
},
{
"M249": 1,
"5.56": 200,
"8X Scope": 1,
"Medkit": 1,
"Compensator (AR)": 1
},
{
"M24": 1,
"7.62": 15,
"Level 3 Military Vest": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1,
"Level 3 Military Vest": 1,
"Adrenaline Syringe": 1
},
{
"M249": 1,
"5.56": 100,
"8X Scope": 1,
"Level 3 Military Vest": 1
},
{
"VSS": 1,
"9mm": 90,
"8X Scope": 1
},
{
"Tommy Gun": 1,
"ACP": 100,
"Level 3 Helmet": 1,
"Adrenaline Syringe": 1
},
{
"AWM": 1,
".300": 20,
"8X Scope": 1,
"First Aid Kit": 1
},
{
"AWM": 1,
".300": 20,
"Level 3 Military Vest": 1
},
{
"VSS": 1,
"9mm": 90,
"15X Scope": 1
},
{
"Tommy Gun": 1,
"ACP": 100,
"Level 3 Military Vest": 1,
"Ext. Quickdraw Mag (AR)": 1
},
{
"AWM": 1,
".300": 20,
"8X Scope": 1,
"First Aid Kit": 1,
"Ext. Quickdraw Mag (AR)": 1
},
{
"AWM": 1,
".300": 20,
"Level 3 Military Vest": 1,
"8X Scope": 1
},
{
"Kar98": 1,
"7.62": 15,
"Vertical Grip": 1,
"Medkit": 1
},
{
"M24": 1,
"7.62": 15,
"Level 3 Helmet": 1,
"Compensator (Sniper)": 1
},
{
"M249": 1,
"5.56": 200,
"Adrenaline Syringe": 1,
"Level 3 Backpack": 1,
"Quickdraw Mag (Sniper)": 1
},
{
"VSS": 1,
"9mm": 90,
"Level 3 Helmet": 1
},
{
"M24": 1,
"7.62": 15,
"8X Scope": 1,
"Ghillie Suit": 1,
"Medkit": 1
},
{
"M249": 1,
"5.56": 100,
"8X Scope": 1,
"Ext. Quickdraw Mag (AR)": 1
},
{
"Kar98": 1,
"7.62": 15,
"15X Scope": 1
},
{
"M249": 1,
"5.56": 200,
"8X Scope": 1
},
{
"Tommy Gun": 1,
"ACP": 100,
"Tactical Stock": 1
},
{
"Kar98": 1,
"7.62": 15,
"Level 3 Helmet": 1
},
{
"M249": 1,
"5.56": 100,
"8X Scope": 1,
"Painkiller": 1,
"Compensator (AR)": 1
},
{
"Kar98": 1,
"7.62": 15,
"Adrenaline Syringe": 1,
"Level 3 Helmet": 1
},
{
"M249": 1,
"5.56": 100,
"Adrenaline Syringe": 1,
"Ghillie Suit": 1,
"8X Scope": 1
},
{
"VSS": 1,
"9mm": 90,
"Level 3 Backpack": 1
}
]
Number of crates with one or more level 3 gear pieces: 56
Number of crates with two or more level 3 gear pieces: 0
Number of crates with snipers: 62
Total number of snipers: 62
Chance to find crate with sniper weapon: 0.61
Number of crates with one or more 8x scopes: 42
Number of crates with two or more 8x scopes: 1
Number of crates with 15x scopes: 6
Total number of 15x scopes: 6
Chance to find crate with 15x scope: 0.06
Chance to find 15x scope when there is a sniper in the crate: 0.06
Chance to find 15x scope when there is no sniper in the crate: 0.05
Number of crates with ghillie suits: 17
Total number of ghillie suits: 17
Chance to find crate with ghillie suit: 0.17
Chance to find ghillie suit when there is a sniper in the crate: 0.16
Chance to find ghillie suit when there is no sniper in the crate: 0.18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment