ONLY DO WHAT ONLY YOU CAN DO

こけたら立ちなはれ 立ったら歩きなはれ

Scala で Project Euler Problem 16

scala> BigInt(2).pow(15)
res11: scala.math.BigInt = 32768

scala> BigInt(2).pow(100)
res12: scala.math.BigInt = 1267650600228229401496703205376
scala> BigInt(2).pow(100).toString.toCharArray
res14: Array[Char] = Array(1, 2, 6, 7, 6, 5, 0, 6, 0, 0, 2, 2, 8, 2, 2, 9, 4, 0, 1, 4, 9, 6, 7, 0, 3, 2, 0, 5, 3, 7, 6)
scala> BigInt(2).pow(100).toString.toCharArray.map(_.toInt)
res18: Array[Int] = Array(49, 50, 54, 55, 54, 53, 48, 54, 48, 48, 50, 50, 56, 50, 50, 57, 52, 48, 49, 52, 57, 54, 55, 48, 51, 50, 48, 53, 51, 55, 54)
scala> BigInt(2).pow(100).toString.toCharArray.map(_.toInt - 48)
res19: Array[Int] = Array(1, 2, 6, 7, 6, 5, 0, 6, 0, 0, 2, 2, 8, 2, 2, 9, 4, 0, 1, 4, 9, 6, 7, 0, 3, 2, 0, 5, 3, 7, 6)
scala> BigInt(2).pow(100).toString.toCharArray.map(_.toInt - 48).sum
res20: Int = 115
scala> BigInt(2).pow(1000).toString.toCharArray.map(_.toInt - 48).sum
res21: Int = 1366