<commit_before>package ark

case class Combo(private val _hits: List[Hit] = Nil) {

  /**
   * Current total ark
   */
  def ark: Int = {
    def ark(hits: List[Hit]): BigDecimal = {
      if (hits.isEmpty) {
        0
      } else {
        val prev = hits.take(hits.size - 1)
        val last = hits.last
        def sum(hits: List[Hit]) = hits.map(_.damage).sum * hits.map(_.multiplier).sum
        if (prev.contains(last)) 2 * ark(prev) else ark(prev) + sum(hits)
      }
    }
    ark(hits).toInt;
  }

  /**
   * Combo ark if the hit were added.
   */
  def ark(candidate: Hit): Int = throw new UnsupportedOperationException("Implement me!");

  def hits: List[Hit] = _hits;

  /**
   * Appends the hit at the end of the Combo.
   *
   * @return a new Combo instance
   */
  def append(hit: Hit): Combo = copy(_hits :+ hit)
}

case class Hit(val trap: Trap, val bonusMultiplier: BigDecimal = 0.0) {
  def damage = trap.damage
  def baseMultiplier = trap.multiplier
  def multiplier = baseMultiplier + bonusMultiplier
}<commit_msg>Refact<commit_after>package ark

import scala.annotation.tailrec

case class Combo(val hits: List[Hit] = Nil) {

  /**
   * Current total ark
   */
  def ark: Int = Combo.ark(hits).toInt

  /**
   * Combo ark if the hit were added.
   */
  def ark(candidate: Hit): Int = Combo.ark(hits :+ candidate).toInt;

  /**
   * Appends the hit at the end of the Combo.
   *
   * @return a new Combo instance
   */
  def append(hit: Hit): Combo = copy(hits :+ hit)
}
case object Combo {
  def sum(hits: List[Hit]) = hits.map(_.damage).sum * hits.map(_.multiplier).sum

  def ark(hits: List[Hit]): BigDecimal = {
    if (hits.isEmpty) {
      0
    } else {      
      val prev = hits.take(hits.size - 1)
      val last = hits.last
      if (!prev.contains(last)) ark(prev) + sum(hits) else 2 * ark(prev)
    }
  }
}

case class Hit(val trap: Trap, val bonusMultiplier: BigDecimal = 0.0) {
  def damage = trap.damage
  def baseMultiplier = trap.multiplier
  def multiplier = baseMultiplier + bonusMultiplier
}
{'fraction_non_alphanumeric': 0.13316953316953317, 'fraction_numerical': 0.004914004914004914, 'mean_word_length': 2.6684684684684683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1531338', 'n_tokens_mistral': 753, 'n_tokens_neox': 743, 'n_words': 200}