Originally posted by ColdWizard
View Post
Announcement
Collapse
No announcement yet.
Let's make a deal!
Collapse
X
-
Originally posted by Hauldren Collider View PostThis is trivially solvable through brute force, although I am sure there are more elegant solutions. It just isn't worthwhile to try to find them.
Am currently writing a short solution in python.<p style="font-size:1024px">HTML is disabled in signatures</p>
Comment
-
Originally posted by loinburger View PostEnumerate the primes with the sieve of eratosthenes, stick them in a hash table, and test their rotations to see if they're in the hash table. And then eat a goat.
Damn, now I'm too lazy to finish my solution. I actually didn't know about the sieve of eratosthenes, so I was just doing modulo every number less than x to check primality. Yours is a very good way of doing it though.
I'll try doing it this way now. Will post results when finished.If there is no sound in space, how come you can hear the lasers?
){ :|:& };:
Comment
-
OK, that took longer than it should have because I took a break to eat, but here's my solution:
Code:1 #simple circular prime solver 2 def eratosthenes(max): 3 nums = [] 4 primes = [] 5 for n in range(0, max): 6 nums.append([n, 0]) 7 #edge cases 8 nums[0][1] = -1 9 nums[1][1] = -1 10 #the sieve 11 for n in range(2, max): 12 if nums[n][1]: #status has been assigned 13 continue 14 for m in range(n, max, n): 15 nums[m][1] = -1 16 nums[n][1] = 1 17 primes.append(n) 18 return (nums, primes) 19 20 def circulate(x, nums): 21 #make a list of the digits 22 y = list(str(x)) 23 for n in range(0, len(y)-1): 24 #rotate digits 25 y.insert(0,y.pop()) 26 #convert back to int 27 z = int("".join(y)) 28 if(nums[z][1] != 1): 29 return False 30 return True 31 32 (nums, primes) = eratosthenes(1000000) 33 t=0 34 a=[] 35 for p in primes: 36 if circulate(p, nums): 37 a.append(p) 38 t+=1 39 print "Number of circular primes: " + str(t) 40 print "Primes: " + str(a) 41
Number of circular primes: 55
Primes: [2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, 97, 113, 131, 197, 199, 311, 337, 373, 719, 733, 919, 971, 991, 1193, 1931, 3119, 3779, 7793, 7937, 9311, 9377, 11939, 19391, 19937, 37199, 39119, 71993, 91193, 93719, 93911, 99371, 193939, 199933, 319993, 331999, 391939, 393919, 919393, 933199, 939193, 939391, 993319, 999331]If there is no sound in space, how come you can hear the lasers?
){ :|:& };:
Comment
-
Looks reasonable to me. My usual practice with Project Euler puzzles is to say "I probably could(n't) solve that" and to leave it at that.<p style="font-size:1024px">HTML is disabled in signatures</p>
Comment
-
I think that over 90% of the real-life "puzzles" I've seen involve either deadlocks or race conditions or some combination of the two, and those are only really an issue if I can't switch to using optimistic concurrency for some reason (usually because my boss nixes the change because (s)he doesn't understand optimistic concurrency).<p style="font-size:1024px">HTML is disabled in signatures</p>
Comment
-
Originally posted by regexcellent View PostWhy everyone should take Operating Systems or some systems programming course<Reverend> IRC is just multiplayer notepad.
I like your SNOOPY POSTER! - While you Wait quote.
Comment
-
I'd rather that compsci students were taught how to program using lock-free concurrency - the code scales better and is ten times easier to maintain.
And I'd rather that everybody not have to take an operating systems course - it's already a pain in the ass fixing my relatives' computers without their knowing how to use the fiddly bits in Windows.<p style="font-size:1024px">HTML is disabled in signatures</p>
Comment
-
Originally posted by loinburger View PostThe sieve of eratosthenes is a good thing to know because for some reason job interviewers absolutely love to ask prime number enumeration questions.No, I did not steal that from somebody on Something Awful.
Comment
-
Originally posted by gribbler View PostWhat sort of microbrew would Dinner recommend to accompany goat meat?
[/pun]Last edited by Dinner; March 27, 2013, 02:14.Try http://wordforge.net/index.php for discussion and debate.
Comment
-
Originally posted by Braindead View PostNo. Dinner threadjacked it into a goateating thread. Dinner likes food threads.
You should move away from the grazing goats, very dangerous in case of a marine invasion.Try http://wordforge.net/index.php for discussion and debate.
Comment
Comment