Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithm writing tips?
#5
KajitiSouls Wrote:Stereo, why would you set numbers concatenated with themselves as true? They aren't primes for the very obvious reason that they have a factor that is the parent prime. Other than that, I might take a look into your idea.

For comparison purposes.

ex 3 & 7 & 109 & 673 -> true for 3, 7, 109 and 673 (since all 4 numbers have a true in each of those 4 primes) -> they are a correct set of 4 primes.

Setting it true for itself just kinda indicates which number the array represents, instead of the normal "can concat with this number".


On further thought it might be worth the size hit to make the array of bits include all odd numbers (or all numbers of the form 6*k +- 1), for easier back conversion to what number an index represents. Not sure how often you'd use that function, though.

Code:
                for(int j = 0; j < list.length && isCompatible; j++){
                    String num1 = "" + list[j] + nextPrime;
                    String num2 = "" + nextPrime + list[j];
                    long n1 = Long.parseLong(num1);
                    long n2 = Long.parseLong(num2);
                    if((primesTable.contains(n1) || isPrime(n1)) &&
                    (primesTable.contains(n2) || isPrime(n2))){
                        primesTable.put(n1, true);
                        primesTable.put(n2, true);
                    }
This is the main thing it should hopefully speed up, you don't need to concat the same number multiple times (say "3" is in 50 different 4-tuples, or even 1000 since you said you're working into the 4 and 5 digit numbers, you'd check it with nextPrime once, instead of for each set)
Code:
get nextPrime
for i in Primes
    compare nextPrime+i, i+nextPrime
    if both prime
        i.cat[nextPrime.index] = true
        nextPrime.cat[i.index] = true
put nextPrime in Primes
nextPrime.cat[nextPrime.index] = true
Code:
check(n-tuple) returns n+1 tuple
for prime j in n-tuple
    if(j.cat[nextPrime.index] && nextPrime.cat[j.index])
        do nothing
    else
        return null
return nextPrime+n-tuple
Reply


Messages In This Thread
Algorithm writing tips? - by KajitiSouls - 2009-01-11, 10:40 PM
Algorithm writing tips? - by Stereo - 2009-01-11, 10:58 PM
Algorithm writing tips? - by KajitiSouls - 2009-01-11, 11:36 PM
Algorithm writing tips? - by Nikkey - 2009-01-12, 09:58 AM
Algorithm writing tips? - by Stereo - 2009-01-12, 11:52 AM
Algorithm writing tips? - by KajitiSouls - 2009-01-12, 03:53 PM
Algorithm writing tips? - by Nikkey - 2009-01-12, 04:19 PM
Algorithm writing tips? - by Stereo - 2009-01-12, 04:50 PM
Algorithm writing tips? - by KajitiSouls - 2009-01-12, 05:25 PM
Algorithm writing tips? - by Nikkey - 2009-01-12, 05:59 PM
Algorithm writing tips? - by GummyBear - 2009-01-12, 08:13 PM
Algorithm writing tips? - by KajitiSouls - 2009-01-12, 10:26 PM
Algorithm writing tips? - by Nikkey - 2009-01-13, 10:28 AM
Algorithm writing tips? - by GummyBear - 2009-01-13, 11:41 PM
Algorithm writing tips? - by Stereo - 2009-01-15, 10:38 AM
Algorithm writing tips? - by Nikkey - 2009-01-15, 11:02 AM
Algorithm writing tips? - by Kiley - 2009-01-16, 02:37 AM
Algorithm writing tips? - by KajitiSouls - 2009-01-18, 01:48 AM
Algorithm writing tips? - by Stereo - 2009-01-18, 04:46 PM
Algorithm writing tips? - by KajitiSouls - 2009-01-18, 05:37 PM
Algorithm writing tips? - by Nikkey - 2009-01-18, 06:26 PM
Algorithm writing tips? - by Stereo - 2009-01-18, 08:02 PM
Algorithm writing tips? - by KajitiSouls - 2009-01-18, 08:29 PM
Algorithm writing tips? - by Stereo - 2009-01-18, 10:45 PM
Algorithm writing tips? - by Nikkey - 2009-01-19, 02:10 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)