From af891417360436d822f61a8c96a9c130203733ce Mon Sep 17 00:00:00 2001 From: Ken Kahn Date: Mon, 27 May 2024 07:55:14 +0200 Subject: [PATCH] Unsuccessful experiment with Phi 3 3B --- apps/number to English by Phi 3 3B/index.html | 35 ++++++++++++++ .../numberToEnglish.js | 46 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 apps/number to English by Phi 3 3B/index.html create mode 100644 apps/number to English by Phi 3 3B/numberToEnglish.js diff --git a/apps/number to English by Phi 3 3B/index.html b/apps/number to English by Phi 3 3B/index.html new file mode 100644 index 0000000..b01ba4d --- /dev/null +++ b/apps/number to English by Phi 3 3B/index.html @@ -0,0 +1,35 @@ + + + + + Number to English Converter + + + +

Number to English Word Conversion Test

+ +
+

+ Written by AI Assistant +
+ +
+ + + +
+ + + + \ No newline at end of file diff --git a/apps/number to English by Phi 3 3B/numberToEnglish.js b/apps/number to English by Phi 3 3B/numberToEnglish.js new file mode 100644 index 0000000..12ea615 --- /dev/null +++ b/apps/number to English by Phi 3 3B/numberToEnglish.js @@ -0,0 +1,46 @@ +function convertToEnglish(number) { + const ones = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; + const tens = [ + '', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety' + ]; + + if (number === 0) return ones[0]; + + let result; + + // Handle numbers up to one hundred. + if (number < 10) { + return ones[number]; + } else if (number < 20) { + return `${ones[number]}teen`; + } else { + // Split the number into hundreds, tens and ones places. + const hundredsPlace = Math.floor(number / 100); + const remainder = number % 100; + let word = ''; + + if (hundredsPlace > 0) { + word += `${ones[hundredsPlace]} hundred `; + } + + // Handle tens. + if (remainder > 0) { + const tenValue = Math.floor(remainder / 10); + const onesValue = remainder % 10; + + if (tenValue > 0) { + word += `${tens[tenValue]} `; } + + // Handle the single digit case. + if (onesValue > 0 || tenValue === 0) { + word += ones[onesValue]; + } + } + + return word.trim(); + } +} + +// Example usage: +console.log(convertToEnglish(123)); // Outputs: one hundred twenty three +console.log(convertToEnglish(456789)); // Outputs: four hundred fifty six thousand seven hundred eighty nine