Unique and Mindblowing - an AI Coding Attempt

Unique and Mindblowing - an AI Coding Attempt

sorgill9N2FU
Explorer Explorer
405 Views
2 Replies
Message 1 of 3

Unique and Mindblowing - an AI Coding Attempt

sorgill9N2FU
Explorer
Explorer

Thought I'd share this screencap of some code created by OpenAI's davinci model - got a good chuckle out of me.

 

In all seriousness, I've been goofing around with this a bit today, and I've been actually impressed multiple times by some of the results. Most results don't actually do anything useful, but they get very close to being pretty legit solutions to the prompts provided (most of the time just editing a few lines of code to make it work, and most often caused by the AI using functions that exist within LISP but not within AutoLISP).

 

UaMB.JPG

0 Likes
Accepted solutions (1)
406 Views
2 Replies
Replies (2)
Message 2 of 3

pbejse
Mentor
Mentor

@sorgill9N2FU wrote:

Thought I'd share this screencap of some code created by OpenAI's davinci model - got a good chuckle out of me.

 


It looks interesting enough to me that I immediately sign-up to play in the playground 🙂

 

Message 3 of 3

sorgill9N2FU
Explorer
Explorer
Accepted solution

It is interesting for sure. Here is another example that has a little bit more 'substance'.

 

First thing to note, this code does not work, so don't bother trying it.

 

AI.JPG

 

I took the code and simply formatted it, and this is what it looks like.

 

;============================================================================
; string-split.lsp
;============================================================================
;
; This program provides a function, `string-split`, for splitting a string
; into a list of substrings at arbitrary delimiters.
;
; The `string-split` function accepts two arguments:
;
; * A string to split into substrings.
; * A delimiter that indicates where the split should occur.
;
; The return value is a list of strings.
;
; Example:
;
; (string-split "abc|def|ghi" "|")
; => ("abc" "def" "ghi")
;
; (string-split "a/bc/def" "/")
; => ("a" "bc" "def")
;
(defun string-split (str delimiter)
	(cond
		((member delimiter str)
			(cons
				(substr str 1 (vl-position delimiter str))
				(string-split (substr str (+ (vl-position delimiter str) 1)) delimiter)
			)
		)
		(t str)
	)
)

 

A few things key take-aways I noticed:

 

  1. First, I specified not to use the 'let' function because this AI is regularly recognizing and using (let) from general LISP, but autoLISP does not recognize the let function.
  2. Clearly, the AI understood what I was asking it to do. Somehow, it even decided to comment about what the program should do, and how to use it, which was fascinating to me. This is a machine..
  3. The AI falsely uses the member function as a way to determine whether or not the delimiter is found within the string, as member expects a list not a string as input. It makes the same mistake with 'vl-position' which also expects a list. Despite these mistakes, it clearly knows what it is trying to do.
  4. The AI uses recursion here, something I really never would have even cared to think about doing.

A few modifications to this code like making the 'member' and 'vl-position' function to work as the AI thought they should, this code would likely execute properly. Crazy.

 

EDIT:

 

I modified the code slightly, to use WCMATCH and VL-STRING-SEARCH instead, and then a little bit of list manipulation correction, and it does indeed work. Not necessarily the best way to do the task, that title probably goes to Lee Mac's recursive version, but still impressive considering the fundamental solution was automatically generated from a text prompt in plain English.

 

(defun string-split (str delimiter)
	(cond
		((wcmatch str (strcat "*" delimiter "*"))
			(append
				(list (substr str 1 (vl-string-search delimiter str)))
				(string-split (substr str (+ (vl-string-search delimiter str) (+ (strlen delimiter) 1))) delimiter)
			)
		)
		(t (list str))
	)
)

 

 

Cheers!