Programming Challenge

Programming Challenge

john.uhden
Mentor Mentor
8,286 Views
91 Replies
Message 1 of 92

Programming Challenge

john.uhden
Mentor
Mentor

It is claimed that the sentence "The quick brown fox jumped over the lazy dog." contains at least one of all the letters in the English alphabet.  Case doesn't matter.

Your challenge is to post a function that proves or disproves that claim.  It should take the sentence as a string and return T or nil, e.g.

(defun true? (str)

  (and

    (= (type str) 'STR)

    (vl-yes-they-are-all-there str)

  )

)

Have fun, OR ELSE!

John F. Uhden

Replies (91)
Message 41 of 92

john.uhden
Mentor
Mentor

YESSS!!

Morgan Freeman is one of my favorite actors...

(The Shawshank Redemption, Bruce Almighty, The Bucket List)

John F. Uhden

Message 42 of 92

hak_vz
Advisor
Advisor

@john.uhden Actually your reply was a good proposal for Saturday night movie, so I watched The Bucked List.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 43 of 92

Bruno-VDH
Participant
Participant
Accepted solution

Hello,

 

I wanted to share a thought:
For functions working with an alphabetical list, it is possible to integrate the frequency of the letters into the code.

https://en.wikipedia.org/wiki/Letter_frequency

 

(defun mytest (str / l)
  (setq	l '(90 81 88 74 75 86 66 80 89 71 70 87 77 85 67 76 68 82 72 83 78 73 79 65 84 69)
	str (strcase str)
  )
  (while (and (vl-string-position (car l) str) (setq l (cdr l))))
  (not l)
)

 

Message 44 of 92

john.uhden
Mentor
Mentor
@Bruno-VDH
Welcome to this forum!
@Anonymous told us of your prowess, and it's obvious.

That's a good one that will be considered keenly.
Please spend as much time with us as you can.

John F. Uhden

0 Likes
Message 45 of 92

braudpat
Mentor
Mentor

Hello @Bruno-VDH 

 

BRAVO Bruno, you are with US !!

 

The Health, Bye, Patrice

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 46 of 92

Bruno-VDH
Participant
Participant

Thank you for this warm welcome😊

0 Likes
Message 47 of 92

Scottu2
Advocate
Advocate

John,

 

Should the following test as false?

 

The quick brown fox over jumps the lazy dog.

 

 

0 Likes
Message 48 of 92

john.uhden
Mentor
Mentor
No, it should test as T.
"jumped" would test as nil because there would be no "s" in the sentence.

John F. Uhden

0 Likes
Message 49 of 92

Scottu2
Advocate
Advocate

Look again... I swapped "jumped over"

0 Likes
Message 50 of 92

john.uhden
Mentor
Mentor

@Scottu2 

Umm, look again at what?

John F. Uhden

0 Likes
Message 51 of 92

Scottu2
Advocate
Advocate

The quick brown fox over jumps the lazy dog.

0 Likes
Message 52 of 92

john.uhden
Mentor
Mentor

@Scottu2 

Yeah, I guess he "over jumps" to be sure he doesn't land on the dog, who happens to really be a crocodile in a dog costume just taking a nap.  The fox ain't THAT quick.

John F. Uhden

0 Likes
Message 53 of 92

john.uhden
Mentor
Mentor

@Bruno-VDH , @pbejse, @dbroad, @kent1Cooper, @z9E3zK5E, @doaiena, @Paul_gander

Attached is the composite history of all the submitted functions (with comments).

Since some of the function names were duplicates and varied greatly in length, I took the liberty to shorten and enumerate them for time testing purposes.

The entire LSP file is attached as PANGRAM.TXT (thanks to @didier for the name) and it includes the time testing function.

Yes, you can (load "pangram.txt") because files don't have to have the .lsp extension.  It's just the default.

 

Also attached is "Pangram Test Results.txt" for your review.

Based on time alone, @pbejse's offerings appear to be the fastest with @dbroad's close behind.

But time cannot be used as the sole quality by which to judge each of the functions.  I happen to like Bruno's pangram10 the best for its brevity and non-use of any locals.  Sadly it suffers from the snailish behavior of the member function.  But we all gain for his having joined us, thanks to @didier.  Unfortunately I decided to eliminate @hak_vz's verbose offering as he seemed intent on dissecting every organ of possibility like Duckie (Dr. Mallard) on NCIS.

 

I have another challenge almost ready to go, and it's something that can be useful to us civil/survey types, yet it doesn't require Civil 3D at all.  But a PhD in statistics might help. 🤔

John F. Uhden

Message 54 of 92

Kent1Cooper
Consultant
Consultant

@Scottu2 wrote:

Look again... I swapped "jumped over"


If you're asking about word order, my interpretation would be that it doesn't matter -- only whether the overall contains each letter, in any order.

Kent Cooper, AIA
0 Likes
Message 55 of 92

john.uhden
Mentor
Mentor
Agreed.

John F. Uhden

0 Likes
Message 56 of 92

hak_vz
Advisor
Advisor

@john.uhden  What is wrong with my code posted at #41?

Here you have my code from post number number #41 and variation with list cutting using cdr that is not used in any of codes before. Attached are elapse times from my test

 

(defun pangram11 (str / bucket)
	(foreach x (vl-string->list (strcase str))
		(cond
			((< 64 x 91)
				(cond 
					((not bucket) (setq bucket (cons x bucket)))
					((member x bucket)(setq bucket (cons x bucket)))
				)
			)
		)
	)
	(= 26 (length bucket))
)

(defun pangram12 (str / bucket)
	(setq nlist (vl-string->list (strcase str)))
	(while nlist
		(cond
			((< 64 (setq x (car nlist)) 91)
				(cond 
					((not bucket) (setq bucket (cons x bucket)))
					((member x bucket)(setq bucket (cons x bucket)))
				)
			)
		)
		(setq nlist (cdr nlist))
	)
	(= 26 (length bucket))
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 57 of 92

john.uhden
Mentor
Mentor
@hak_vz

My most severe apologies...I forgot all about the bucket approach.

(PANGRAM11 "The quick brown fox jumps over the lazy dog.")
Author: @hak_vz
Result: T
Elapsed time for 10000 iterations: 1500 millisecs.

(PANGRAM11 "The quick brown fox jumped over the lazy dog.")
Author: @hak_vz
Result: nil
Elapsed time for 10000 iterations: 1484 millisecs.

I guess that's about the slowest time, but I really don't care about that.
I like the subliminal reference.

John F. Uhden

0 Likes
Message 58 of 92

hak_vz
Advisor
Advisor

@john.uhden 


@john.uhden wrote:
@hak_vz
I guess that's about the slowest time, but I really don't care about that.
I like the subliminal reference.

Neither do I, but have you checked results attached to my previous post? 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 59 of 92

john.uhden
Mentor
Mentor
@hak_vz
No.
I surely don't want to hurt your feelings, but...
As I had said, it was loaded with too many tests that I thought were
thorough but irrelevant. Hey, I posted PANGRAM.TXT which is actually a
.LSP file, so you can add to it and test it yourself.
Maybe my test method was improper anyway.
What was fun was seeing all the different approaches from the current day
masters. I learned a lot. Plus, it appeared to get a bundle of hits, so
hopefully the lurkers and neophytes learned a lot as well. Not that we
have to deal with pangrams more than 3D splines, whatever they are.

John F. Uhden

0 Likes
Message 60 of 92

doaiena
Collaborator
Collaborator

I thought bigger numbers were better... Who would have known 😉

0 Likes