Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithm writing tips?
#1
Quote:The first four primes for which any two primes concatenate to produce another prime is 3, 7, 109, 673. For example, if you concatenate 7 and 109, you'll get the prime 7109, and concatenating 109 and 7 yields the prime 1097. The sum of these four primes is 792, and is the lowest sum for the set of four primes with this property.

Find a set of five primes for which any two primes concatenate to produce another prime, and has the lowest sum of such sets of five primes.

--You may use any programming language.
--The script must be written in a fashion that there are no other assumptions made about the nature of the problem without reasonable proof. For example, you may not assume that the highest prime number is below 1,000,000.
--The script execution time preferably produces the answer in under 1 minute for modestly powered computers.
--You may use Google or any other resource to help you. (so long as you don't cheat and look up the answer!)

This is a math problem meant for programming practice. The main problem I'm having is getting the execution time to below 1 minute, but I'm not sure how I can make my algorithm more efficient. Heck, it actually stops when it finds the first set of 5 primes, and it doesn't really check whether it has the lowest sum of all sets of 5 primes. About the only thing I can think of right now is avoiding redundant checks when trying to find larger sets of primes. If anyone has any crazy tips that I don't know about, please feel free to share =)

 Java algorithm

Btw, I know what the answer is, and it's not as simple as the example made it look. The second number, in ascending order, is 5197 o.O
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)