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
|
||||
@@ -407,6 +407,12 @@ _Newest first._
|
||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||
recursive match, List.append, List.fold_left.
|
||||
- 2026-05-10 Phase 5.1 — number_words.ml baseline (letter count of
|
||||
numbers 1-19 spelled out = 106). 19-arm match dispatch returning
|
||||
the English word for each number. Sums lengths over 1..19. Real
|
||||
PE17 covers 1..1000 (answer 21124) but requires more elaborate
|
||||
number-to-words logic. Tests literal-pattern match with many arms.
|
||||
128 baseline programs total.
|
||||
- 2026-05-10 Phase 5.1 — palindrome_sum.ml baseline (sum of 3-digit
|
||||
palindromes = 49500). 90 palindromes between 100 and 999 (form
|
||||
aba; 9 choices for a, 10 for b). Sum = 49500 = 90 * 550 (mean
|
||||
|
||||
Reference in New Issue
Block a user