I'm not sure I understand the assignment correctly. The damage I give to the monster is always 1, right? So if the monster's health is 3, it gets killed before it can attack back. It needs at least 4 hit points to be able to bite.
#!/usr/bin/perl use warnings; use strict; use Function::Parameters; fun kill_monsters($h, $m, $dm) { my $hits = int(($m - 1) / 3); my $damage = $dm * $hits; $h -= $damage; return $h > 0 ? "hits: $hits, damage: $damage, health: $h" : 'hero died' } use Test::More tests => 3; is kill_monsters(100, 3, 33), 'hits: 0, damage: 0, health: 100'; is kill_monsters( 50, 7, 10), 'hits: 2, damage: 20, health: 30'; is kill_monsters( 2, 7, 1), 'hero died';
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm not sure I understand the assignment correctly. The damage I give to the monster is always 1, right? So if the monster's health is 3, it gets killed before it can attack back. It needs at least 4 hit points to be able to bite.