ocaml: phase 5.1 number_words.ml baseline (letter count of 1..19 spelled out = 106)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
19-arm match returning the English word for each number 1..19, then
sum String.length:
let number_to_words n =
match n with
| 1 -> 'one' | 2 -> 'two' | ... | 19 -> 'nineteen'
| _ -> ''
total_letters 19 = 36 + 70 = 106
(1-9) (10-19)
Real PE17 covers 1..1000 (answer 21124) but needs more elaborate
number-to-words logic (compounds, 'and', 'thousand'). 1..19 keeps
the program small while exercising literal-pattern match dispatch
on many arms.
128 baseline programs total.
This commit is contained in:
@@ -86,6 +86,7 @@
|
||||
"module_use.ml": 3,
|
||||
"monotonic.ml": 4,
|
||||
"newton_sqrt.ml": 1414,
|
||||
"number_words.ml": 106,
|
||||
"mutable_record.ml": 10,
|
||||
"option_match.ml": 5,
|
||||
"palindrome.ml": 4,
|
||||
|
||||
19
lib/ocaml/baseline/number_words.ml
Normal file
19
lib/ocaml/baseline/number_words.ml
Normal file
@@ -0,0 +1,19 @@
|
||||
let number_to_words n =
|
||||
match n with
|
||||
| 1 -> "one" | 2 -> "two" | 3 -> "three" | 4 -> "four" | 5 -> "five"
|
||||
| 6 -> "six" | 7 -> "seven" | 8 -> "eight" | 9 -> "nine"
|
||||
| 10 -> "ten" | 11 -> "eleven" | 12 -> "twelve"
|
||||
| 13 -> "thirteen" | 14 -> "fourteen" | 15 -> "fifteen"
|
||||
| 16 -> "sixteen" | 17 -> "seventeen" | 18 -> "eighteen" | 19 -> "nineteen"
|
||||
| _ -> ""
|
||||
|
||||
let total_letters limit =
|
||||
let total = ref 0 in
|
||||
for i = 1 to limit do
|
||||
total := !total + String.length (number_to_words i)
|
||||
done;
|
||||
!total
|
||||
|
||||
;;
|
||||
|
||||
total_letters 19
|
||||
Reference in New Issue
Block a user