Forums Register Login

Cyclops Regex

+Pie Number of slices to send: Send
Head spinning on this one...

'need a regex to find cyclop strings...

e.g., 101, 22722, 9993999,  etc

I wish to use it for this: http://robertjliguori.blogspot.com/2017/02/palindromeprimeutils.html as inspired by this: https://www.youtube.com/watch?v=HPfAnX5blO0

Can anyone help with the expression?

Thanks,
Robert
+Pie Number of slices to send: Send
Why do you have to/want to use a regex? It's easy to do by converting to a String and then using a loop.
+Pie Number of slices to send: Send
 

Jeanne Boyarsky wrote:Why do you have to/want to use a regex? It's easy to do by converting to a String and then using a loop.



Thanks, I'm working on it now... wish me luck.
+Pie Number of slices to send: Send
This is what I came up with... improvements?

+Pie Number of slices to send: Send
Three ideas for improvement:

1) There's no need to call new String because you already have a String from calling toString(). So you can simplify that one line to


2) StringBuilder would be better than StringBuffer. No need to have the old threadsafe class.

3)


Is the same as

Judgment call on which is easier to read.
+Pie Number of slices to send: Send
Thanks... I'll look at your code in a sec... I had an error in there, this fixes it:

+Pie Number of slices to send: Send
Another approach is to check for the length, must be uneven. Then make a frequency count of the characters. There should be two frequencies, of which one = 1. If so, check the middle character and the first character; they should be unequal.
+Pie Number of slices to send: Send
Or check the first/middle characters to check they are unequal. Then remove the middle char and check all others are the same.

Many ways .
+Pie Number of slices to send: Send
Ha Ha!!!

I discovered my own prime with this code, the Liguori Prime!

http://robertjliguori.blogspot.com/2017/02/liguori-primes.html
+Pie Number of slices to send: Send
My test was incomplete. Here is the code I was referring to:
+Pie Number of slices to send: Send
 

Piet Souris wrote:My test was incomplete. Here is the code I was referring to:



Thank you so much!  I will do some speed test and will use the fastest method... I'll let you know if yours is the fastest.
+Pie Number of slices to send: Send
 

Robert James Liguori wrote:

Piet Souris wrote:My test was incomplete. Here is the code I was referring to:



While I do like your algorithm better... it looks like mine is a tad faster...

For 1,000,000,000 iterations...

Cyclop algorithm #1:
Three minutes, five seconds.
25/02/17 22:41:10 START
25/02/17 22:44:15 END

Cyclop algorithm #2:
Six minutes, 3 seconds
25/02/17 22:44:36 START
25/02/17 22:50:39 END

* I believe we were equally as fast for smaller numbers (i.e., for 100,000,000 I was just two seconds faster)  , but yours slowed up as the numbers got bigger.


Thanks again though!!!
Robert

 
+Pie Number of slices to send: Send
It's the primes method I need to speed up... taking forever... and it's code i snagged from stackoverflow:

Anyone have a faster method to get square roots of BigIntegers?

Reference: https://github.com/robertjliguori/PalindronePrimeUtils/blob/master/src/main/java/com/stackoverflow/utils/BigIntSqRoot.java

Robert
You don't like waffles? Well, do you like this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2133 times.
Similar Threads
JavaFX NetBeans Sample Applications Demonstrated
Introducing JWindRose
Bad bad bad: Steve Jobs has passed
Multi String Replacer
Volunteer Moderators needed for new Gliesian Worldwide Interactive News (GWIN) website
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:06:59.