<commit_before><commit_msg>Add solution to problem 55. BigInt rules the world.<commit_after>object Solution {
  import scala.collection.mutable
  
  def genConvergeNums(n: Int): Array[BigInt] = {
    val cache = mutable.Map.empty[BigInt, BigInt]
    
    def recursiveCalculateConverge(x: BigInt, c: Int): BigInt = {
      if (cache.contains(x)) cache(x)
      else {
        if (c >= 60) {
          cache(x) = BigInt(-1)
          cache(x)
        }
        else {
          val xs = x.toString
          val rxs = xs.reverse
          if (xs == rxs) {
            cache(x) = x
            x
          }
          else {
            val rx = BigInt(rxs)
            val convergeNum = recursiveCalculateConverge(x + rx, c + 1)
            cache(x) = convergeNum
            if (xs.size == rxs.size) cache(rx) = convergeNum
            convergeNum
          }
        }
      }
    }

    (0 to n).toArray.map(recursiveCalculateConverge(_, 0))
  }

  def main(args: Array[String]) {
    val n = readLine.toInt
    val converges = genConvergeNums(n)
    val occ = new mutable.HashMap[BigInt, Int] { override def default(k: BigInt) = 0 }
    for (x <- converges if x != -1) occ(x) += 1
    val (k, c)= occ.maxBy(_._2)
    println(k + " " + c)
  }
}

{'fraction_non_alphanumeric': 0.12349639133921411, 'fraction_numerical': 0.009623095429029671, 'mean_word_length': 1.798206278026906, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '925026', 'n_tokens_mistral': 444, 'n_tokens_neox': 421, 'n_words': 104}