home > Project Euler >

ForNext

Shut the fuck up and write some code

Problem 17

1から1000まですべて単語で書くのに必要な文字はいくつか?

1 から 5 までの数字を英単語で書けば one, two, three, four, five であり, 全部で の文字が使われている.

では 1 から 1000 (one thousand) までの数字をすべて英単語で書けば, 全部で何文字になるか.

注: 空白文字やハイフンを数えないこと. 例えば, 342 (three hundred and forty-two) は 23 文字, 115 (one hundred and fifteen) は 20 文字と数える. なお, "and" を使用するのは英国の慣習.

Number letter counts

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?

NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.

VBScript

JScript

Perl

PHP

Python

Ruby

PowerShell

Scala

更新日 : 2013.01.31
scala> val map = collection.mutable.Map[Int, String] ()
map: scala.collection.mutable.Map[Int,String] = Map()

scala>

scala> map += 1     -> "one"
res0: map.type = Map(1 -> one)

scala> map += 2     -> "two"
res1: map.type = Map(1 -> one, 2 -> two)

scala> map += 3     -> "three"
res2: map.type = Map(3 -> three, 1 -> one, 2 -> two)

scala> map += 4     -> "four"
res3: map.type = Map(3 -> three, 4 -> four, 1 -> one, 2 -> two)

scala> map += 5     -> "five"
res4: map.type = Map(5 -> five, 3 -> three, 4 -> four, 1 -> one, 2 -> two)

scala> map += 6     -> "six"
res5: map.type = Map(5 -> five, 3 -> three, 4 -> four, 1 -> one, 6 -> six, 2 -> two)

scala> map += 7     -> "seven"
res6: map.type = Map(5 -> five, 7 -> seven, 3 -> three, 4 -> four, 1 -> one, 6 -> six, 2 -> two)

scala> map += 8     -> "eight"
res7: map.type = Map(5 -> five, 8 -> eight, 7 -> seven, 3 -> three, 4 -> four, 1 -> one, 6 -> six, 2 -> two)

scala> map += 9     -> "nine"
res8: map.type = Map(5 -> five, 8 -> eight, 7 -> seven, 3 -> three, 4 -> four, 1 -> one, 6 -> six, 2 -> two, 9 -> nine)

scala> map += 10    -> "ten"
res9: map.type = Map(10 -> ten, 5 -> five, 8 -> eight, 7 -> seven, 3 -> three, 4 -> four, 1 -> one, 6 -> six, 2 -> two, 9 -> nine)

scala> map += 11    -> "eleven"
res10: map.type = Map(11 -> eleven, 10 -> ten, 5 -> five, 8 -> eight, 7 -> seven, 3 -> three, 4 -> four, 1 -> one, 6 -> six, 2 -> two, 9 -> nine)

scala> map += 12    -> "twelve"
res11: map.type = Map(11 -> eleven, 10 -> ten, 5 -> five, 12 -> twelve, 8 -> eight, 7 -> seven, 3 -> three, 4 -> four, 1 -> one, 6 -> six, 2 -> two, 9 -> nine)

scala> map += 13    -> "thirteen"
res12: map.type = Map(5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 2 -> two, 9 -> nine)

scala> map += 14    -> "fourteen"
res13: map.type = Map(5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 2 -> two, 14 -> fourteen, 9 -> nine)

scala> map += 15    -> "fifteen"
res14: map.type = Map(15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 2 -> two, 14 -> fourteen, 9 -> nine)

scala> map += 16    -> "sixteen"
res15: map.type = Map(16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 2 -> two, 14 -> fourteen, 9 -> nine)

scala> map += 17    -> "seventeen"
res16: map.type = Map(16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 17 -> seventeen, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 2 -> two, 14 -> fourteen, 9 -> nine)

scala> map += 18    -> "eighteen"
res17: map.type = Map(16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 17 -> seventeen, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 2 -> two, 14 -> fourteen, 18 -> eighteen, 9 -> nine)

scala> map += 19    -> "nineteen"
res18: map.type = Map(16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 17 -> seventeen, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 2 -> two, 19 -> nineteen, 14 -> fourteen, 18 -> eighteen, 9 -> nine)

scala> map += 20    -> "twenty"
res19: map.type = Map(16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 17 -> seventeen, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 20 -> twenty, 2 -> two, 19 -> nineteen, 14 -> fourteen, 18 -> eighteen, 9 -> nine)

scala> map += 30    -> "thirty"
res20: map.type = Map(16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 3 -> three, 7 -> seven, 8 -> eight, 17 -> seventeen, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 30 -> thirty, 20 -> twenty, 2 -> two, 19 -> nineteen, 14 -> fourteen, 18 -> eighteen, 9 -> nine)

scala> map += 40    -> "forty"
res21: map.type = Map(16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 40 -> forty, 3 -> three, 7 -> seven, 8 -> eight, 17 -> seventeen, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 30 -> thirty, 20 -> twenty, 2 -> two, 19 -> nineteen, 14 -> fourteen, 18 -> eighteen, 9 -> nine)

scala> map += 50    -> "fifty"
res22: map.type = Map(16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 40 -> forty, 3 -> three, 7 -> seven, 8 -> eight, 17 -> seventeen, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 30 -> thirty, 20 -> twenty, 2 -> two, 50 -> fifty, 19 -> nineteen, 14 -> fourteen, 18 -> eighteen, 9 -> nine)

scala> map += 60    -> "sixty"
res23: map.type = Map(60 -> sixty, 16 -> sixteen, 15 -> fifteen, 5 -> five, 10 -> ten, 11 -> eleven, 40 -> forty, 3 -> three, 7 -> seven, 8 -> eight, 17 -> seventeen, 12 -> twelve, 4 -> four, 1 -> one, 13 -> thirteen, 6 -> six, 30 -> thirty, 20 -> twenty, 2 -> two, 50 -> fifty, 19 -> nineteen, 14 -> fourteen, 18 -> eighteen, 9 -> nine)

scala> map += 70    -> "seventy"
res24: map.type = Map(10 -> ten, 5 -> five, 15 -> fifteen, 60 -> sixty, 11 -> eleven, 16 -> sixteen, 8 -> eight, 3 -> three, 40 -> forty, 7 -> seven, 12 -> twelve, 17 -> seventeen, 4 -> four, 13 -> thirteen, 1 -> one, 70 -> seventy, 6 -> six, 20 -> twenty, 30 -> thirty, 2 -> two, 50 -> fifty, 14 -> fourteen, 19 -> nineteen, 9 -> nine, 18 -> eighteen)

scala> map += 80    -> "eighty"
res25: map.type = Map(10 -> ten, 5 -> five, 15 -> fifteen, 60 -> sixty, 11 -> eleven, 16 -> sixteen, 8 -> eight, 3 -> three, 40 -> forty, 7 -> seven, 12 -> twelve, 17 -> seventeen, 4 -> four, 13 -> thirteen, 1 -> one, 70 -> seventy, 80 -> eighty, 6 -> six, 20 -> twenty, 30 -> thirty, 2 -> two, 50 -> fifty, 14 -> fourteen, 19 -> nineteen, 9 -> nine, 18 -> eighteen)

scala> map += 90    -> "ninety"
res26: map.type = Map(10 -> ten, 5 -> five, 15 -> fifteen, 60 -> sixty, 90 -> ninety, 11 -> eleven, 16 -> sixteen, 8 -> eight, 3 -> three, 40 -> forty, 7 -> seven, 12 -> twelve, 17 -> seventeen, 4 -> four, 13 -> thirteen, 1 -> one, 70 -> seventy, 80 -> eighty, 6 -> six, 20 -> twenty, 30 -> thirty, 2 -> two, 50 -> fifty, 14 -> fourteen, 19 -> nineteen, 9 -> nine, 18 -> eighteen)

scala> map += 1000  -> "one thousand"
res27: map.type = Map(10 -> ten, 5 -> five, 15 -> fifteen, 60 -> sixty, 90 -> ninety, 11 -> eleven, 16 -> sixteen, 8 -> eight, 3 -> three, 40 -> forty, 7 -> seven, 12 -> twelve, 17 -> seventeen, 4 -> four, 13 -> thirteen, 1 -> one, 70 -> seventy, 80 -> eighty, 6 -> six, 20 -> twenty, 30 -> thirty, 2 -> two, 50 -> fifty, 14 -> fourteen, 19 -> nineteen, 1000 -> one thousand, 9 -> nine, 18 -> eighteen)
scala> def numeral_string (n:Int):String = {
     |     if (map.contains(n)) {
     |         map(n)
     |     } else {
     |         var s = ""
     |
     |         // 100の位
     |         val n1 =  n / 100
     |         if (n1 != 0) s = map(n1) + " hundred"
     |
     |         // 10の位 + 1の位
     |         val n2 = n % 100
     |         if ((n1 != 0 ) && (n2 != 0)) s += " and "
     |
     |         if ((0 < n2) && (n2 <= 20)) {
     |             s += map(n2)
     |         } else {
     |             // 10の位
     |             val n3 = n2 / 10
     |             if (2 <= n3) s += map(n3 * 10)
     |
     |             // 1の位
     |             val n4 = (n2 % 10)
     |             if (0 < n4) s += "-" + map(n4)
     |         }
     |         s
     |     }
     | }
numeral_string: (n: Int)String
scala> (1 to 5).map(numeral_string)
res28: scala.collection.immutable.IndexedSeq[String] = Vector(one, two, three, four, five)
scala> (1 to 5).
     | map(numeral_string)
res29: scala.collection.immutable.IndexedSeq[String] = Vector(one, two, three, four, five)

scala> .map(_.replace(" ",""))
res30: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(one, two, three, four, five)

scala> .map(_.replace("-",""))
res31: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(one, two, three, four, five)
scala> (1 to 5).
     | map(numeral_string)
res32: scala.collection.immutable.IndexedSeq[String] = Vector(one, two, three, four, five)

scala> .map(_.replace(" ",""))
res33: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(one, two, three, four, five)

scala> .map(_.replace("-",""))
res34: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(one, two, three, four, five)

scala> .map(_.length)
res35: scala.collection.immutable.IndexedSeq[Int] = Vector(3, 3, 5, 4, 4)
scala> (1 to 5).
     | map(numeral_string)
res36: scala.collection.immutable.IndexedSeq[String] = Vector(one, two, three, four, five)

scala> .map(_.replace(" ",""))
res37: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(one, two, three, four, five)

scala> .map(_.replace("-",""))
res38: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(one, two, three, four, five)

scala> .map(_.length)
res39: scala.collection.immutable.IndexedSeq[Int] = Vector(3, 3, 5, 4, 4)

scala> .sum
res40: Int = 19
scala> (1 to 1000).
     | map(numeral_string)
res41: scala.collection.immutable.IndexedSeq[String] = Vector(one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, twenty-one, twenty-two, twenty-three, twenty-four, twenty-five, twenty-six, twenty-seven, twenty-eight, twenty-nine, thirty, thirty-one, thirty-two, thirty-three, thirty-four, thirty-five, thirty-six, thirty-seven, thirty-eight, thirty-nine, forty, forty-one, forty-two, forty-three, forty-four, forty-five, forty-six, forty-seven, forty-eight, forty-nine, fifty, fifty-one, fifty-two, fifty-three, fifty-four, fifty-five, fifty-six, fifty-seven, fifty-eight, fifty-nine, sixty, sixty-one, sixty-two, sixty-three, sixty-four, sixty-five, sixty-six, sixty-seven, sixty-eight, sixty-ni...
scala> .map(_.replace(" ",""))
res42: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, twenty-one, twenty-two, twenty-three, twenty-four, twenty-five, twenty-six, twenty-seven, twenty-eight, twenty-nine, thirty, thirty-one, thirty-two, thirty-three, thirty-four, thirty-five, thirty-six, thirty-seven, thirty-eight, thirty-nine, forty, forty-one, forty-two, forty-three, forty-four, forty-five, forty-six, forty-seven, forty-eight, forty-nine, fifty, fifty-one, fifty-two, fifty-three, fifty-four, fifty-five, fifty-six, fifty-seven, fifty-eight, fifty-nine, sixty, sixty-one, sixty-two, sixty-three, sixty-four, sixty-five, sixty-six, sixty-seven, sixty-eight...
scala> .map(_.replace("-",""))
res43: scala.collection.immutable.IndexedSeq[java.lang.String] = Vector(one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, twentyone, twentytwo, twentythree, twentyfour, twentyfive, twentysix, twentyseven, twentyeight, twentynine, thirty, thirtyone, thirtytwo, thirtythree, thirtyfour, thirtyfive, thirtysix, thirtyseven, thirtyeight, thirtynine, forty, fortyone, fortytwo, fortythree, fortyfour, fortyfive, fortysix, fortyseven, fortyeight, fortynine, fifty, fiftyone, fiftytwo, fiftythree, fiftyfour, fiftyfive, fiftysix, fiftyseven, fiftyeight, fiftynine, sixty, sixtyone, sixtytwo, sixtythree, sixtyfour, sixtyfive, sixtysix, sixtyseven, sixtyeight, sixtynine, seventy, seventyone, seventytwo...
scala> .map(_.length)
res44: scala.collection.immutable.IndexedSeq[Int] = Vector(3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8, 6, 9, 9, 11, 10, 10, 9, 11, 11, 10, 6, 9, 9, 11, 10, 10, 9, 11, 11, 10, 5, 8, 8, 10, 9, 9, 8, 10, 10, 9, 5, 8, 8, 10, 9, 9, 8, 10, 10, 9, 5, 8, 8, 10, 9, 9, 8, 10, 10, 9, 7, 10, 10, 12, 11, 11, 10, 12, 12, 11, 6, 9, 9, 11, 10, 10, 9, 11, 11, 10, 6, 9, 9, 11, 10, 10, 9, 11, 11, 10, 10, 16, 16, 18, 17, 17, 16, 18, 18, 17, 16, 19, 19, 21, 21, 20, 20, 22, 21, 21, 19, 22, 22, 24, 23, 23, 22, 24, 24, 23, 19, 22, 22, 24, 23, 23, 22, 24, 24, 23, 18, 21, 21, 23, 22, 22, 21, 23, 23, 22, 18, 21, 21, 23, 22, 22, 21, 23, 23, 22, 18, 21, 21, 23, 22, 22, 21, 23, 23, 22, 20, 23, 23, 25, 24, 24, 23, 25, 25, 24, 19, 22, 22, 24, 23, 23, 22, 24, 24, 23, 19, 22, 22, 24, 23, 23, 22, 24, 24, 23,...
scala> .sum
res45: Int = 21124

F#

更新日 : 2013.01.31
> let mutable map:Map<int, string> = Map.empty;;

val mutable map : Map<int,string> = map []

> map <- map |> Map.add 1     "one";;
val it : unit = ()
> map <- map |> Map.add 2     "two";;
val it : unit = ()
> map <- map |> Map.add 3     "three";;
val it : unit = ()
> map <- map |> Map.add 4     "four";;
val it : unit = ()
> map <- map |> Map.add 5     "five";;
val it : unit = ()
> map <- map |> Map.add 6     "six";;
val it : unit = ()
> map <- map |> Map.add 7     "seven";;
val it : unit = ()
> map <- map |> Map.add 8     "eight";;
val it : unit = ()
> map <- map |> Map.add 9     "nine";;
val it : unit = ()
> map <- map |> Map.add 10    "ten";;
val it : unit = ()
> map <- map |> Map.add 11    "eleven";;
val it : unit = ()
> map <- map |> Map.add 12    "twelve";;
val it : unit = ()
> map <- map |> Map.add 13    "thirteen";;
val it : unit = ()
> map <- map |> Map.add 14    "fourteen";;
val it : unit = ()
> map <- map |> Map.add 15    "fifteen";;
val it : unit = ()
> map <- map |> Map.add 16    "sixteen";;
val it : unit = ()
> map <- map |> Map.add 17    "seventeen";;
val it : unit = ()
> map <- map |> Map.add 18    "eighteen";;
val it : unit = ()
> map <- map |> Map.add 19    "nineteen";;
val it : unit = ()
> map <- map |> Map.add 20    "twenty";;
val it : unit = ()
> map <- map |> Map.add 30    "thirty";;
val it : unit = ()
> map <- map |> Map.add 40    "forty";;
val it : unit = ()
> map <- map |> Map.add 50    "fifty";;
val it : unit = ()
> map <- map |> Map.add 60    "sixty";;
val it : unit = ()
> map <- map |> Map.add 70    "seventy";;
val it : unit = ()
> map <- map |> Map.add 80    "eighty";;
val it : unit = ()
> map <- map |> Map.add 90    "ninety";;
val it : unit = ()
> map <- map |> Map.add 1000  "one thousand";;
val it : unit = ()
> let numeral_string (n:int):string =
-     if Map.containsKey n map then
-         map.[n]
-     else
-         let mutable s = ""
-
-         // 100の位
-         let n1 =  n / 100
-         if n1 <> 0 then s <- map.[n1] + " hundred"
-
-         // 10の位 + 1の位
-         let n2 = n % 100
-         if (n1 <> 0 ) && (n2 <> 0) then s <- s + " and "
-         if (0 < n2) && (n2 <= 20) then
-             s <- s + map.[n2]
-         else
-             // 10の位
-             let n3 = n2 / 10
-             if (2 <= n3) then s <- s + map.[n3 * 10]
-
-             // 1の位
-             let n4 = (n2 % 10)
-             if (0 < n4) then s <- s + "-" + map.[n4]
-
-         s
- ;;

val numeral_string : int -> string
> [1..100]
- |> List.map(numeral_string)
- ;;
val it : string list =
  ["one"; "two"; "three"; "four"; "five"; "six"; "seven"; "eight"; "nine";
   "ten"; "eleven"; "twelve"; "thirteen"; "fourteen"; "fifteen"; "sixteen";
   "seventeen"; "eighteen"; "nineteen"; "twenty"; "twenty-one"; "twenty-two";
   "twenty-three"; "twenty-four"; "twenty-five"; "twenty-six"; "twenty-seven";
   "twenty-eight"; "twenty-nine"; "thirty"; "thirty-one"; "thirty-two";
   "thirty-three"; "thirty-four"; "thirty-five"; "thirty-six"; "thirty-seven";
   "thirty-eight"; "thirty-nine"; "forty"; "forty-one"; "forty-two";
   "forty-three"; "forty-four"; "forty-five"; "forty-six"; "forty-seven";
   "forty-eight"; "forty-nine"; "fifty"; "fifty-one"; "fifty-two";
   "fifty-three"; "fifty-four"; "fifty-five"; "fifty-six"; "fifty-seven";
   "fifty-eight"; "fifty-nine"; "sixty"; "sixty-one"; "sixty-two";
   "sixty-three"; "sixty-four"; "sixty-five"; "sixty-six"; "sixty-seven";
   "sixty-eight"; "sixty-nine"; "seventy"; "seventy-one"; "seventy-two";
   "seventy-three"; "seventy-four"; "seventy-five"; "seventy-six";
   "seventy-seven"; "seventy-eight"; "seventy-nine"; "eighty"; "eighty-one";
   "eighty-two"; "eighty-three"; "eighty-four"; "eighty-five"; "eighty-six";
   "eighty-seven"; "eighty-eight"; "eighty-nine"; "ninety"; "ninety-one";
   "ninety-two"; "ninety-three"; "ninety-four"; "ninety-five"; "ninety-six";
   "ninety-seven"; "ninety-eight"; "ninety-nine"; "one hundred"]
> [100..121]
- |> List.map(numeral_string)
- ;;
val it : string list =
  ["one hundred"; "one hundred and one"; "one hundred and two";
   "one hundred and three"; "one hundred and four"; "one hundred and five";
   "one hundred and six"; "one hundred and seven"; "one hundred and eight";
   "one hundred and nine"; "one hundred and ten"; "one hundred and eleven";
   "one hundred and twelve"; "one hundred and thirteen";
   "one hundred and fourteen"; "one hundred and fifteen";
   "one hundred and sixteen"; "one hundred and seventeen";
   "one hundred and eighteen"; "one hundred and nineteen";
   "one hundred and twenty"; "one hundred and twenty-one"]
> [190..221]
- |> List.map(numeral_string)
- ;;
val it : string list =
  ["one hundred and ninety"; "one hundred and ninety-one";
   "one hundred and ninety-two"; "one hundred and ninety-three";
   "one hundred and ninety-four"; "one hundred and ninety-five";
   "one hundred and ninety-six"; "one hundred and ninety-seven";
   "one hundred and ninety-eight"; "one hundred and ninety-nine";
   "two hundred"; "two hundred and one"; "two hundred and two";
   "two hundred and three"; "two hundred and four"; "two hundred and five";
   "two hundred and six"; "two hundred and seven"; "two hundred and eight";
   "two hundred and nine"; "two hundred and ten"; "two hundred and eleven";
   "two hundred and twelve"; "two hundred and thirteen";
   "two hundred and fourteen"; "two hundred and fifteen";
   "two hundred and sixteen"; "two hundred and seventeen";
   "two hundred and eighteen"; "two hundred and nineteen";
   "two hundred and twenty"; "two hundred and twenty-one"]
> [990..1000]
- |> List.map(numeral_string)
- ;;
val it : string list =
  ["nine hundred and ninety"; "nine hundred and ninety-one";
   "nine hundred and ninety-two"; "nine hundred and ninety-three";
   "nine hundred and ninety-four"; "nine hundred and ninety-five";
   "nine hundred and ninety-six"; "nine hundred and ninety-seven";
   "nine hundred and ninety-eight"; "nine hundred and ninety-nine";
   "one thousand"]
> [100..120]
- |> List.map(numeral_string)
- |> List.map(fun s -> s.Replace(" ", ""))
- |> List.map(fun s -> s.Replace("-", ""))
- ;;
val it : string list =
  ["onehundred"; "onehundredandone"; "onehundredandtwo"; "onehundredandthree";
   "onehundredandfour"; "onehundredandfive"; "onehundredandsix";
   "onehundredandseven"; "onehundredandeight"; "onehundredandnine";
   "onehundredandten"; "onehundredandeleven"; "onehundredandtwelve";
   "onehundredandthirteen"; "onehundredandfourteen"; "onehundredandfifteen";
   "onehundredandsixteen"; "onehundredandseventeen"; "onehundredandeighteen";
   "onehundredandnineteen"; "onehundredandtwenty"]
> [1..5]
- |> List.map(numeral_string)
- |> List.map(fun s -> s.Replace(" ", ""))
- |> List.map(fun s -> s.Replace("-", ""))
- |> List.map(fun s -> s.Length)
- |> List.sum
- ;;
val it : int = 19
> [1..1000]
- |> List.map(numeral_string)
- |> List.map(fun s -> s.Replace(" ", ""))
- |> List.map(fun s -> s.Replace("-", ""))
- |> List.map(fun s -> s.Length)
- |> List.sum
- ;;
val it : int = 21124

C

C++

C++Builder

VC++

C#

Java

Objective-C

D

VB

VB.NET

Delphi

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system