Home > Beyond, codefights, Programación > CodeFights MZbot AllianceVsMonster – Ruby

CodeFights MZbot AllianceVsMonster – Ruby

def allianceVersusMonster hp, ad
    mHp = hp[0]
    mAd = ad[0]
    turns = []
    size = hp.size - 1
    (1...ad.size).each do |x|
        turns <= mAd && cHp >= mHp
        timesToDie = ( mHp / cAd.to_f).ceil
        timesIDie = ( cHp / mAd.to_f).ceil
        return size if timesIDie >= timesToDie
        mHp -= (timesIDie - 1) * cAd 
        w[1] = cHp % mAd + 1
    end
    
    #fight until dead
    turns.each do |w|
        cAd, cHp = w
        return size if cAd >= mAd && cHp >= mHp       
        while cHp > 0 && mHp > 0
            mHp -= cAd
            return size if mHp <= 0
            cHp -= mAd
        end
        size -= 1
    end
    0
end
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: