Fuck fizzbuzz, this is axeswordbuzz

Fuck fizzbuzz, this is axeswordbuzz

If you can't solve this with a ~20loc program you should consider philosophy or flipping burgers

Attached: axe+vs+sword.png (480x480, 48K)

Other urls found in this thread:

youtube.com/watch?v=afqhBODc_8U
twitter.com/SFWRedditVideos

axe because swords are for pussies

What's there to solve?

Axes and swords BTFO:
youtube.com/watch?v=afqhBODc_8U

>enemy with 50 hp
>sword takes 1 swing to kill
>axe takes 50 swings to kill
nice weapon there axecucks

>yellow socks comes in with a rondel dagger
>he forms a plan ... and he's dead
Why is this so funny

The axe is better, right?
>Both have average regular dmg of 60
>Axe: (60 * 0.85) + ((60 * 2) * 0.15)) = 69
>Sword: (60 * 0.8) + ((60 * 1.5) * 0.2) = 66

Attached: 37272495.jpg (602x960, 85K)

what is the attack speed? I presume axe is slower. So soword is better.
Even if same attack speed then soword is still better because it is less rng.

They both have attack speed of 1 since it's unspecified.

>less rng is somehow better dps
Ok

less rng works better with low hp enemies, as stated. Better to have one swing consistently dealing around 60 dmg, than dealing 20 damage with first hit and then 120 with the second, which will be overkill for a 50hp enemy.

import random

def axe():
dmg = random.randint(1,121)
if(random.random() < 0.16):
dmg = dmg*2
return dmg


def sword():
dmg = random.randint(50,70)
if(random.random() < 0.20):
dmg = dmg*1.5
return dmg


sworddmgtotal = 0
axedmgtotal = 0
for i in range(1000):
swdmg = sword()
sworddmgtotal += swdmg
print("sword " + str(swdmg))
axdmg = axe()
axedmgtotal += axdmg
print("axe" + str(axdmg))

print("avg dmg sword " + str(sworddmgtotal/1000))
print("avg dmg axe " + str(axedmgtotal/1000))

avg dmg sword 66.002
avg dmg axe 71

Axe wins!
/thread

why didn't spear-autist do it if he's so good?

> needing to write a program for a question you can solve in your head
How are you so bad at this?

Why are brainlets even needing to use random or even code?
int axe_avg_dmg = (1+120)/2;
int sword_avg_dmg = (50+70)/2;
int axe_ammortized_dmg = axe_avg_dmg + sword_avg_dmg * 2 * 0.15;
int sword_ammortized_dmg = sword_avg_dmg + sword_avg_dmg * 1.5 * 0.2;

wrote in code, but this is just math.

>sword_ammortized_dmg
>ammortized_dmg
>ammortized
Wat1

Wat2: amortized value != fucking avg dmg with critical hits

it is... read on what it means

Even if it is, your math is wrong

what the fuck are you smoking mate?

Depends on your enemies. If they have 50 hp, the sword will kill one with every hit while the axe often won't. If monster groups are being led by a 200 hp champion, the axe can potentially one-shot a champion on a crit with a high damage roll while the sword can't.

Low hp enemies wasn't part of the question

randint(a,b) produces integer from a to b including a and b so it should be randint(1,120)
why random() < 0.16? its 15% chance

also results can be obtained with two lines of math as wrote, no programming necessary.

also made an error, avg damage of the axe is 60.5 not 60
the formula is:
((csc*(csdm - 1) + 1)*(dl+du)/2
where dl and du are damage lower and damage upper
csc is critical strike chance from 0 to 1
csdm is critical strike damage multiplier

probably typo

where?
i dont smoke

>where?
How about the part where you say
axe_ammortized_dmg = axe_avg_dmg + sword_avg_dmg * x
sword_ammortized_dmg = sword_avg_dmg + sword_avg_dmg * y


Axe depends on sword avg?

????

Your assumptions are wrong, brainlet.

its clearly a typo...
prove it.

I can't. We cool rite? :^D
But that's no type tho

Array(10000).fill(0).map(() => Math.floor(Math.random() * 120)).map(x => Math.random() > 0.15 ? x*2 : x).reduce((p, c) => p+c, 0)/10000

Axe of Lunacy: 109

Array(10000).fill(0).map(() => 50+Math.floor(Math.random() * 20)).map(x => Math.random() > 0.2 ? x*1.5 : x).reduce((p, c) => p+c, 0)/10000

Sword of Megapower: 83

Your code is bad and you should feel bad

's all about breakpoints. Might wanna account for damage granularity too. Additionally you wanna be running a bloodlust frenzerker, which grants an additional 250% damage as well as up to a 16x damage multiplier.

I fucked up
critchances should obviously be flipped

Axe of Lunacy: 68
Sword of Megapower: 65

what a mess of a code jesus christ this is what FP brainlets think is good.

This guy raids

you may not like it, but that's what peak performance looks like. it's also very readable since you onle have to understand it one dot at a time.

let me demonstrate:

Array(10000).
//creates an array of length 10000

fill(0).
//actually not needed, but JS doesn't allow to map over an unfilled array

map(() => 50+Math.floor(Math.random() * 20)).
//fill the array with 50 + random * 20
//must be map instead of fill, since it should be different for each entry

map(x => Math.random() < 0.2 ? x*1.5 : x).
//check if it's a crit (random < 0.2) and return x*1.5 or only x otherwise

reduce((p, c) => p+c, 0)
//compute the sum

/10000
//devide by array length

I would take procedural
over functional meme
anytime.

Average damage by the Axe of Lunacy: 69.575
Average damage by the Sword of Megapower: 66

>Defining two identical functions

This code gave me cancer.

20+ lines for such shit

Get the Haskellfags in here.

what is their weapon speed? do they both hit the same amount of times per minute?

it's JS, but the Haskell approach would be very similiar to

It's 1

JavaScript is nothing like Haskell so fuck off.

Why do functionalfags hate newlines?

What'll be the win rate depending on your enemy's HP?

It lets them think that this 10 million hidden operations code is just one line and therefore very efficient.

it's not about efficiency
it's about cleanliness and proper abstraction

the compiler should make properly abstracted code very efficient anyway.

Right, it’s actually good

>fizz
>shit
op confirmed assmad zed main
Fizz is perfect fishfrog and absolute sex~

Attached: sarcastic_fizz.png (832x796, 315K)

>Single line of convoluted code
>cleanliness and proper abstraction

Attached: 5d815a1288f1da5404dbe34347e9cf83.png (420x420, 301K)

so do you multiply the non-crit damage with the probability of not critting or not?

critical damage is not added to the default damage right so you have to weight down the default?
#this looks weird as you add the crit to a 15% of the time:
0.85*a + 0.15*(a + a*2.0)
0.85*a + 0.15*a + 0.15*a*2.0
a(0.85 + 0.15 + 0.15*2.0)
a(1.0 + 0.15*2.0)
a + a*2.0*0.15
#and by having done that you end up with second anons expression

Attached: 1539540438363.png (407x402, 87K)

Friendly reminder that abstraction reduces performance, not improves.

Also
>using Monte Carlo method for non stochastic system instead of simple arithmetics
Pajeet / 10.

>~20loc
Unless it's python or something, can't you just put it all on one line?

>clearly missed the meaning of ~

dude probably did it while u were taking a dump. then he fucked off to have a drink with his buddies
meanwhile you're spending hours to come up with the perfect solution for an exercise posted on Jow Forums by a pajeet. even HE probably forgot about this post by now

Nothing was part of question actually. This is some pleb proving that Jow Forums will argue about anything.

And rng is bad.

>you need to spend hours for this
Lmfao

Enemy with 250HP one kill with Axe, no with sword. Swords are not good designed to cut wood with, and sometimes you need to cut some wood, I'll stay with axe.

Also I gratulate all people who're so enslaved by the computers they need to write stuff to explicitly count something an avarage person should know to count in the head. Sad fact is that it's you who get processed faster.

1000 samples, having fixed sample size...

Can't you just make it statistically without bruteforcing probability? You need like 1000000 tries to bruteforce probability.

sword
everyone who has played a game knows stable damage is superior because you'll always get that 1 damage when you need to 120
crit rate is always more valuable than crit damage anyway as damage will diminish

When you need Youtube views, that cutted video of you killing oponents one hit is more suitable. People crave deviation.

There's some inconsistency with your if statement for the critical damage. Why didn't you create objects for this? That way you wouldn't have such errors.

>1000000
nah

Firstly there is no question asked, secondly, if you need ANY computer to program to solve for the average damage you are retarded and a code monkey at best.

Thirdly there is no distribution named for the damage values or what values the damage can take, just integers?

Swordlets completely and utterly BTFO

function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function weapon(minDmg, maxDmg, critChance, critDmg) {
this.minDmg = minDmg;
this.maxDmg = maxDmg;
this.critChance = critChance;
this.critDmg = critDmg;
}

function player(weapon) {
this.hp = 10000;
this.attack = function(otherPlayer) {
var dmgDealt = randomInt(weapon.minDmg, weapon.maxDmg);
if (Math.random() < weapon.critChance) {
dmgDealt *= weapon.critDmg;
}

otherPlayer.hp -= dmgDealt;
};
}

var axe = new weapon(1, 120, 0.15, 2);
var sword = new weapon(50, 70, 0.2, 1.5);

var playerWithAxe = new player(axe);
var playerWithSword = new player(sword);

var currentPlayer;

var axeWon = 0;
var swordWon = 0;

var N_tries = 1000000;

for (var tries = 0; tries < N_tries; tries++) {
// flip a coin to determine who goes first
currentPlayer = randomInt(0, 1);
// give players 10,000 health each
playerWithAxe.hp = playerWithSword.hp = 10000;
// simulate a battle
while (playerWithAxe.hp > 0 && playerWithSword.hp > 0) {
// attack
if (currentPlayer == 0)
playerWithAxe.attack(playerWithSword);
else
playerWithSword.attack(playerWithAxe);
// switch player for next turn
currentPlayer = currentPlayer == 1 ? 0 : 1;
}
// tally score
if (playerWithAxe.hp < 0 && playerWithSword.hp < 0) {
// tie
}
else if (playerWithAxe.hp < 0) {
swordWon++;
}
else if (playerWithSword.hp < 0) {
axeWon++;
}
}

console.log('Number of battle simulations ran: ' + N_tries);
console.log('Axe won: ' + axeWon);
console.log('Sword won: ' + swordWon);

Attached: axe_wins.png (969x990, 105K)

Hmm, what if the HP is equal to say 50 or 121. Interesting questions.

Sword wins like 90% of the time if you set 50-80 dmg

> \v\

So in the long term/bosses you want the axe since it has higher average DMG but for small amounts of HP you want the sword since it has a guaranteed kill.

Figuring out how you could combine sword and axe to get more optimal kill would also be interesting. Perhaps in the last hits you switch to sword to guarantee the kill?

And if so, at which point should you switch from the axe to the sword. I'd say that's a nice question. There should be some 50% win rate equilibrium where you need to switch under to sword and above to axe.

fix ur're shite code

Attached: unknown.png (628x938, 48K)

>using bitmask for a simple decision

Just dual wield, lmao.

I tried writing a small function in JavaScript to calculate the average value each weapon would have depending on the defense of an enemy.
The problem is that the average value I get varies every time I execute the function even if I don't change the enemy's defense.
I don't know what the hell I'm doing wrong.

"use strict";
function foo(enemy_def=20)
{
// let enemy_def = 0;
let damage_avg_axe = 0, damage_avg_sword = 0, crit = 0, newdmg = 0;
let axe =
{
dmg_min: 1,
dmg_max: 120,
dmg: function(){return rand(this.dmg_min,this.dmg_max);},
crit_chance: 15,
crit_mult: 2,
};
let sword =
{
dmg_min: 50,
dmg_max: 70,
dmg: function(){return rand(this.dmg_min,this.dmg_max);},
crit_chance: 20,
crit_mult: 1.5,
};
crit = rand(0,100);
damage_avg_axe = (crit

Attached: file.png (414x864, 23K)

Kek

/* I win. */
int main(){
return 0;
}

Why do you hate the spacebar, your code looks borderline undreadable

What? Where should I add more spaces?

How about almost everywhere

// wrong
for (let i=0;i

I'm a fucking brainlet, but why does if(Math.random() < crit_chance)
Give the proper crit chance?
Doesn't random numbers give whole numbers from any range of 0-n?
Having it compared to .16 would only trigger on 0? If you get 1,2,3 or any other number it would return false.
Please help me understand.

Math.random gives you a number between 0 and 0.99999999999

So (Math.random() < 0.5) gives you roughly 50%, you can see that right?

(Math.random() < 0.3) would give you 30%. Why? Because Math.random has a uniform distribution which means that all numbers are equally likely. So if they're all equally likely, the chance that it will be < 0.3 is more or less exactly 30% (I mean there's better methods, but this does pretty well in most cases).

In JS you can simply run Math.random() on your browser's console and see the result for yourself.

axe average: 69,575
sword average: 66

why even bother wasting CPU time on something that can be solved using your calculator.

Ok that makes sense. I don't use JavaScript so wasn't sure how their random numbers work.
What about with other languages to implement this? It seems like JavaScript gives the ez mode solution to this.

It's the same in all other langs

Because it's fun to code and it takes like 5-10 minutes

This way of doing it is literally the use-case for a class

plus your summation loop can be compressed into one sum() with a list comprehension


import random

class Weapon:
def __init__(self, dmg_range, critical_chance, critical_multiplier):
self.dmg_range = dmg_range
self.critical_chance = critical_chance
self.critical_multiplier = critical_multiplier

def swing(self):
multiplier = (self.critical_multiplier / 100) \
if (random.random() * 100)

meant for

How is damage determined? Is it truly random or am I likely to put out to the higher end or lower end?

#include
unsigned int rand(int & s, unsigned int l, unsigned int h) {
s = (unsigned short)((unsigned short)(s * 12829U) + 47989U);
unsigned short r = ((s >> ((s >> 13u) + 3u)) ^ s) * 62169u;
return l + (unsigned int)((((unsigned int)(((r >> 11u) ^ r))) * ((unsigned int)(1 + h - l))) >> 16);
}
int main(int argc, char *argv[]) {
for (int i = 0; i < 100000; ++i) printf("%s: %u %s: %u\n",
"sword", (rand(argc, 50, 70) * 3) / (2 + ((int)(rand(argc, 1, 100)

philosophy student here, axe wins
wrote my shitty script in php :^) because the best language is the one that happens to be installed

Attached: axesword.png (423x293, 23K)

Keep variance low if the average values are the same for better reliability, take the sword

Greater predictability = more reliability so the sword wins.

Terrible

I like this question because it favors virginless neckbeards who play wow

cringe

Sweet lord

just gonna post my begginers answer, open to suggestions

function calcDmg(dmgmin, dmgmax, chance, critical) {
var dmg = Math.random() * (dmgmax - dmgmin) + dmgmin;
if (Math.random() < chance) return dmg * critical;
return dmg;
}

function fight() {
var axehp = 1000;
var swordhp = 1000;
var turn = Math.random() < 0.5 ? 1 : -1;
while (axehp > 0 && swordhp > 0) {
if (turn < 0) swordhp -= calcDmg(1, 120, 0.15, 2);
else axehp -= calcDmg(50, 70, 0.2, 1.5);
turn *= -1;
}
return axehp > 0 ? "axe" : "sword";
}

console.log("WINRAR: " + fight() + "!");

sword wins only in case of bad rolls
how could this be math?

Solve what? What's the question?