Page 1 of 1

Quiz of the day...

Posted: Thu Apr 16, 2020 11:18 am
by Thierry
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

Re: Quiz of the day...

Posted: Thu Apr 16, 2020 11:44 am
by bogs
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:

Re: Quiz of the day...

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

YOU are asking US about regex stuff???

You???

Us???

Craig :wink:

Re: Quiz of the day...

Posted: Thu Apr 16, 2020 3:21 pm
by Thierry
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

Re: Quiz of the day...

Posted: Thu Apr 16, 2020 5:31 pm
by bn
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

Re: Quiz of the day...

Posted: Thu Apr 16, 2020 8:25 pm
by dunbarx
Oh, I thought he meant "dauphin". Though how the King of France got in this thread I could not figure out.

Craig

Re: Quiz of the day...

Posted: Thu Apr 16, 2020 8:35 pm
by bogs
The same way the pauper exchanged places with the prince.... ain't it?

Re: Quiz of the day...

Posted: Fri Apr 17, 2020 7:38 am
by Thierry
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

Re: Quiz of the day...

Posted: Fri Apr 17, 2020 11:59 am
by Thierry
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

Re: Quiz of the day...

Posted: Fri Apr 17, 2020 1:10 pm
by bogs
Good one, prime numbers never even entered my mind for some reason :wink: