Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculatePings(pings, targets) {
- var success = 0;
- var failure = 0;
- next: for (var i = 0; i < 70000000; ++i) {
- var a = targets.map(function (x, i) {
- return {
- health: x.health,
- index: i
- };
- });
- for (var j = 0; j < pings; ++j) {
- var index = Math.floor(Math.random() * (a.length + 1));
- var card = a[index];
- if (index !== a.length) {
- --card.health;
- if (card.health === 0) {
- a.splice(index, 1);
- }
- }
- }
- for (var j = 0; j < a.length; ++j) {
- var card = a[j];
- if (card.health > targets[card.index].max) {
- ++failure;
- continue next;
- }
- }
- ++success;
- }
- return (success / (success + failure)) * 100;
- }
- console.log(calculatePings(4, [{ max: 8, health: 10 }]));
Advertisement
Add Comment
Please, Sign In to add comment