From 16ea45b97d75e966760b719649732ba6e9b5e3a9 Mon Sep 17 00:00:00 2001 From: Matthieu Dubuget Date: Mon, 11 Nov 2019 16:39:31 +0100 Subject: [PATCH] Commit initial --- .ocamlformat | 1 + README.org | 8 ++++++++ nombres.ml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 .ocamlformat create mode 100644 README.org create mode 100644 nombres.ml diff --git a/.ocamlformat b/.ocamlformat new file mode 100644 index 0000000..5dab0e3 --- /dev/null +++ b/.ocamlformat @@ -0,0 +1 @@ +profile = conventional \ No newline at end of file diff --git a/README.org b/README.org new file mode 100644 index 0000000..c17d0ce --- /dev/null +++ b/README.org @@ -0,0 +1,8 @@ + +Tiré de : https://leconjugueur.lefigaro.fr/frlesnombres.php + + +et https://www.miakinen.net/vrac/nombres + + +https://www.dcode.fr/ecriture-nombre-lettres diff --git a/nombres.ml b/nombres.ml new file mode 100644 index 0000000..247568a --- /dev/null +++ b/nombres.ml @@ -0,0 +1,56 @@ +let rec nombre_of_int = function + | 0 -> "zéro" + | 1 -> "un" + | 2 -> "deux" + | 3 -> "trois" + | 4 -> "quatre" + | 5 -> "cinq" + | 6 -> "six" + | 7 -> "sept" + | 8 -> "huit" + | 9 -> "neuf" + | 10 -> "dix" + | 11 -> "onze" + | 12 -> "douze" + | 13 -> "treize" + | 14 -> "quatorze" + | 15 -> "quinze" + | 16 -> "seize" + | 20 -> "vingt" + | 30 -> "trente" + | 40 -> "quarante" + | 50 -> "cinquante" + | 60 -> "soixante" + | 80 -> "quatre-vingts" + | 100 -> "cent" + | 1000 -> "mille" + | n when n < 70 -> jusqua_70 n + | n when n < 80 -> jusqua_100 "soixante" n + | n when n < 100 -> jusqua_100 "quatre-vingt" n + | n when n < 1_000 -> jusqua_1000 n + | n when n < 1_000_000 -> jusqua_1000000 n + | _ -> "--------------------" + +and jusqua_70 n = + let dizaine = nombre_of_int (n / 10 * 10) in + let unite = n mod 10 in + [ dizaine; nombre_of_int unite ] + |> String.concat (if unite = 1 then " et " else "-") + +and jusqua_100 dizaine n = + let unite = n mod 10 in + [ dizaine; nombre_of_int (n mod 20) ] + |> String.concat (if unite = 1 && n < 80 then " et " else "-") + +and jusqua_1000 n = + let centaine = n / 100 and reste = n mod 100 in + let cent = if centaine > 1 && reste = 0 then "cents" else "cent" in + ( (if centaine = 1 then [ cent ] else [ nombre_of_int centaine; cent ]) + @ if reste = 0 then [] else [ nombre_of_int reste ] ) + |> String.concat " " + +and jusqua_1000000 n = + let milliers = n / 1000 and reste = n mod 1000 in + ( (if milliers = 1 then [ "mille" ] else [ nombre_of_int milliers; "mille" ]) + @ if reste = 0 then [] else [ nombre_of_int reste ] ) + |> String.concat " "