Quiz of the day...

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Quiz of the day...

Post by Thierry » Thu Apr 16, 2020 11:18 am

Hi all,

Here is an old function I've made a long time ago,
but I forget what's the use of it [1]

Any idea ? Bogs ? Bernd ? anyone ?

Code: Select all

function x y
	return not matchText(binaryEncode("A" & y," "),"^ ?$|^(  +?)\1+$")
end x

Stay Safe, stay healthy

Thierry


[1] don't need to believe everything on the Net
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Quiz of the day...

Post by bogs » Thu Apr 16, 2020 11:44 am

The answer is "false", unless it is "true" :D
Thierry wrote:
Thu Apr 16, 2020 11:18 am
[1] don't need to believe everything on the Net
Well I hear they can't put it on the interwebz if it isn't true :twisted:
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: Quiz of the day...

Post by dunbarx » Thu Apr 16, 2020 3:04 pm

Thierry.

YOU are asking US about regex stuff???

You???

Us???

Craig :wink:

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Quiz of the day...

Post by Thierry » Thu Apr 16, 2020 3:21 pm

dunbarx wrote:
Thu Apr 16, 2020 3:04 pm
Thierry.

YOU are asking US about regex stuff???
Us???
Craig :wink:
:lol:

Well, with the lockDown,
I thought you might have some free time to
jump into them and dive like a dolphin :) -- , not daulphin (French typo)

Regards,
Thierry
Last edited by Thierry on Fri Apr 17, 2020 9:23 am, edited 1 time in total.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Quiz of the day...

Post by bn » Thu Apr 16, 2020 5:31 pm

Thierry wrote:
Thu Apr 16, 2020 3:21 pm

Well, with the lockDown,
I thought you might have some free time to
jump into them and dive like a daulphin :)

Regards,
Thierry
Of course I am still scratching my head. Once I am bald as a dolphin I will jump in and dive... :D

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: Quiz of the day...

Post by dunbarx » Thu Apr 16, 2020 8:25 pm

Oh, I thought he meant "dauphin". Though how the King of France got in this thread I could not figure out.

Craig

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Quiz of the day...

Post by bogs » Thu Apr 16, 2020 8:35 pm

The same way the pauper exchanged places with the prince.... ain't it?
Image

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Quiz of the day...

Post by Thierry » Fri Apr 17, 2020 7:38 am

dunbarx wrote: Oh, I thought he meant "dauphin". Though how the King of France got in this thread I could not figure out.
Hi Craig,
was just a typo as dolphin in French is 'dauphin' :)

Why the King of France came here?
Just check his wife's country:

dauphin.png


Concerning the quiz, bogs is on the 1st position...

Enjoy your day,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Quiz of the day...

Post by Thierry » Fri Apr 17, 2020 11:59 am

Thierry wrote: What's the use of this?

Code: Select all

function x y
	return not matchText(binaryEncode("A" & y," "),"^ ?$|^(  +?)\1+$")
end x
Ok,here is the answer, only renaming the function:

Code: Select all

function isAprimeNumber aNumber
	return not matchText(binaryEncode("A" & aNumber," "),"^ ?$|^(  +?)\1+$")
end isAprimeNumber
Of course, it's just a one-liner script for fun, playing with LiveCode.
If you want to do this in a more traditonal and efficient way,
here is a working code:


primeNumbers.png



Credits to Abigail,the prolific Perl hacker Abigail
who is famous for posting enigmatic but ingenious one-liner scripts
in her signatures on newsgroups.

Here’s one that blew my mind, from comp.lang.perl.misc:

perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' [number]

and if you're curious about how this works:

http://neilk.net/blog/2000/06/01/abigai ... e-numbers/

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Quiz of the day...

Post by bogs » Fri Apr 17, 2020 1:10 pm

Good one, prime numbers never even entered my mind for some reason :wink:
Image

Post Reply