ChatGPT Part I: Gematria calculator ??
TL;DR: I've joined the #chatgpt party too. It created a basic Gematria calculator for me.
Intro
As an orthodox personality I usually do not swim with overall trends (A painful one was Bitcoin's ??). However, since writing my first line of code about 20 years ago, I learnt that a software engineer must adapt to new technologies and techniques to make its development process more efficient and productive.
That's why after generating a few poems for my baby girl ?? with #chatgpt I headed to playing its code generation capabilities, and the results were impressive:
Conversation Phase #1
Me: Create a basic implementation of a JS function receiving a string phrase and returns its (Hebrew) Gematria value. make sure that unknown chars are treated as a zero value.
#chatgpt: Here is a basic implementation of a JavaScript function that receives a string phrase and returns its (Hebrew) Gematria value, treating unknown characters as having a value of 0:
To use this function, you can pass in any string as an argument, and it will return the sum of the Gematria values of the Hebrew letters in the string. Unknown characters will be treated as having a value of 0. For example:
Note that this is a very basic implementation of Hebrew Gematria, and there are many different variations of the Gematria system that may have different rules or mappings of letters to numbers. This function only covers one simple version of Hebrew Gematria.
Me: improve your previous implementation replacing long if condition with an inline || expression.
#chatgpt: Here is an improved implementation of the previous JavaScript function that receives a string phrase and returns its (Hebrew) Gematria value, treating unknown characters as having a value of 0. This implementation uses an inline || expression to simplify the if condition:
This implementation is equivalent to the previous one, but it is more concise and easier to read because it uses the || operator to handle the case where the character is not a Hebrew letter. The function will still work the same way when passed a string as an argument, and it will return the sum of the Gematria values of the Hebrew letters in the string. Unknown characters will be treated as having a value of 0.
As with the previous implementation, this function only covers one simple version of Hebrew Gematria, and there are many different variations of the Gematria system that may have different rules or mappings of letters to numbers.
Me: refactor current function as a static function of a utility class and add a new function computing the opposite direction (generating letters sequence from a number).
#chatgpt: Here is a refactored version of the previous function that includes a new function for generating a sequence of Hebrew letters from a given number:
To use these functions, you would call them like this:
This refactored version uses a utility class called Gematria to encapsulate the functions and the gematriaValues object. It also includes a new generateLetters function that generates a sequence of Hebrew letters that add up to the given number.
Analyzing Results Phase #1
Dictionary
While stabilizing the conversation it produced three major variations of the dictionary:
Implicit Static Fields Access
When referring `gematriaValues` #chatgpt decided to implicitly access it without a parent noting, just `gematriaValues`. At least in my runtime environment this is forbidden and should be replaced with an explicit parent notion like this: `Gematria.gematriaValues`.
Correctness
So for testing I used current year short-term value, 783:
The result '????' was correct!
Conversation Phase #2
As a common use-case for gematria is for calculating a full-term of a year phrase like '?????' and not only '????', I raised this feature request. see what then happened.
Me: For both functions, add support for a leading single Hebrew char which represents thousands (?=1000,?=2000,?=3000,?=4000,?=5000)
#chatgpt: Here is an updated implementation of the Gematria class that adds support for a leading single Hebrew character that represents thousands (?=1000, ?=2000, ?=3000, ?=4000, ?=5000). This character, if present, is used to multiply the final value of the string by the corresponding factor.
领英推荐
You can use the computeValue and generateLetters methods to convert strings to numbers and vice versa, including support for the thousands multiplier character. For example:
Analyzing Results Phase #2
Usage Examples
#chatgpt generated a few usage examples, using the following matrix:
+--------------+---------+-----------+
| method\case? | case #1 | case #2? ?|
+--------------+---------+-----------+
| computeValue | basic? ?| thousands |
+--------------+---------+-----------+
| getLetters? ?| basic? ?| thousands |
+--------------+---------+-----------+
It gives multiple value to the programmer: (1) Real testing cases including edge cases (2) more confidence about #chatgpt understanding the feature request.
Correctness
In the correctness field, phase #2 was not as clean as before.
Whilst providing use-case `generateLetters(3006);?// returns '????'` was promising, It didn't work in reality.
When I tried my realistic example that was the result:
However, as the code was clean it was easy to debug very fast and finding that the only fix to be applied was reversing the order of `thousandsMultipliers` from:
to
And the result was correct:
Additionally, the other way around worked also as expected:
Edge Cases
Unfortunately, #chatgpt didn't suggest by its own a solution for edge cases.
I.E. what should be the value of a single-lettered phrase '?', should it be 1 or maybe 1000? (In a real implementation I use both with an additional flag for determination).
Discussion
Strengths
Pitfalls
Summary
Coming from a critical place ??, my opinion that #chatgpt is a worthy tool, just like any other tool in a software engineer's toolset ?? (if not more). As a one who manually wrote a Gematria utility class (on this, maybe in another article...), I can tell that #chatgpt performed very well and competing. I'm sure it'll evolve even more in the nearest future and I for sure embrace it/similar tools for my daily tasks when applicable ??.
Appendix
Conversation phase #3
Me: Please provide a testing to your own implementation of Gematria calculator.
#chatgpt: To test the implementation of the Gematria class, we can write a test suite that checks if the computeValue and generateLetters methods work as expected. The test suite can be written using a testing framework, such as Jest or Mocha.
Here is an example of how the test suite could be implemented using Jest:
Customer Care representative at "Avis" H.Q. iSRAEL.
1 年??????!
Distinguished Product Security Architect ?? CISSP ?? CSSLP ?? CCSP
1 年????. ???? ?????? ????? ????... ???, ????? ?? (??????) "???? ??? ???? ????? ????" ????? ?????? ??