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.
20 lines
536 B
OCaml
20 lines
536 B
OCaml
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
|