ChatGPT Part I: Gematria calculator ??
Carol Yepes / Getty Images

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:

No alt text provided for this image

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:

No alt text provided for this image

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:

No alt text provided for this image

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:

No alt text provided for this image

To use these functions, you would call them like this:

No alt text provided for this image

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:

  1. Only partial set of letters (?,?,?,?) was generated with a TODO add more key-value pairs notation.
  2. All but final letters (?,?,?,?,?) were generated
  3. All letters including final ones were generated (assuming them having the same values as their simple equivalents).

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:

No alt text provided for this image

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.

No alt text provided for this image

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:

No alt text provided for this image

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:

No alt text provided for this image

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:

No alt text provided for this image

to

No alt text provided for this image

And the result was correct:

No alt text provided for this image

Additionally, the other way around worked also as expected:

No alt text provided for this image

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

  • Stateful: #chatgpt's stateful behavior is a big plus. It remembers previous solution state and react very good to feature requests.
  • Complete requirement processing: #chatgpt's Ability to process a complicated requirement really helped me after multiple crashes (discussed below) to continue from the point I stopped. I just literally concatenated my previous requests into a single and complicated one and it came over all single requests to generate a complete product.
  • Creativity: due to many crashes I had to request the same thing multiple times. I was surprised to see that from time to time it provide different answer with certain components which are implemented in a whole different direction.

Pitfalls

  • Crashes: #chatgpt was crashed a lot while I used it.
  • Correctness + bugs: as covered, #chatgpt does have some bugs and wrong local implementations.
  • Edge cases: #chatgpt do not think of (many) edge cases and leaves that to the programmer.

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:

No alt text provided for this image
Eliyahu Lowenstein

Customer Care representative at "Avis" H.Q. iSRAEL.

1 年

??????!

回复
Jacob Barkai

Distinguished Product Security Architect ?? CISSP ?? CSSLP ?? CCSP

1 年

????. ???? ?????? ????? ????... ???, ????? ?? (??????) "???? ??? ???? ????? ????" ????? ?????? ??

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了