近況

  • 年度終わり、ここ何年かやってきた仕事が終わりました。いろいろあった。勉強になりました。
  • CygwinからJavaを使う場合は、エンコーディング指定できるところは片っ端からUTF-8を指定するといい感じですかね(整理できてない)。
  • 川又永井より若いんですか。
  • コードカタのお題ですが、数を漢字に変換する(例:12345→一万二千三百四十五)ってのをやりました。Scalaのコードを載せときます。
implicit class Num2Kanji(n: Int) {
  def toKanji: String = {
    def div(n: Int, b: Int): Vector[Int] =
      if (n < b) Vector(n)
      else n % b +: div(n / b, b) 
    if (n == 0) "零"
    else div(n, 10000).map(n =>
      div(n, 10).map {
        case 0 => ""
        case 1 => "一"
        case 2 => "二"
        case 3 => "三"
        case 4 => "四"
        case 5 => "五"
        case 6 => "六"
        case 7 => "七"
        case 8 => "八"
        case 9 => "九"
      }.zipWithIndex.map {
        case ("", _) => ""
        case (c, 0) => c
        case ("一", 1) => "十"
        case (c, 1) => c + "十"
        case ("一", 2) => "百"
        case (c, 2) => c + "百"
        case ("一", 3) => "千"
        case (c, 3) => c + "千"
      }.reduce((a1, a2) => a2 + a1)
    ).zipWithIndex.map {
      case ("", _) => ""
      case (t, 0) => t
      case (t, 1) => t + "万"
      case (t, 2) => t + "億"
      case (t, 3) => t + "兆"
    }.reduce((a1, a2) => a2 + a1)
  }
}