Playing with coding using my AI assistant to help, and we cranked out some code that can crank through multiple millions of primes a second.
Being a little rusty I was asking my chatbot for help with C data types and defines and letting it give me little coding snippets. It is the smallest possible model that still works, so it has limitations, but it did the best it could. It really was motivating to have the give and take, and just having a sounding board helped me work through issues rapidly.
When I went to a number over 1000000001 I had errors, but google gave me a web result to have me put an L at the end of the number, which let me go to 200 million and 400 million primes.
I was able to use google and a web page of primes to check my answers, but once I went over 32 bit values for primes nobody has that on the internet.
I did it!!! I reached the edge of the Internet!!!!
Whooooooooooo!!!!
% time ./a.outThe 100000001 prime number is: 2038074751./a.out 33.60s user 0.77s system 98% cpu 35.051 total% time ./a.outThe 200000001 prime number is: 4222234763./a.out 75.01s user 2.64s system 92% cpu 1:23.71 total%time ./a.outThe 400000001 prime number is: 8736028073./a.out 166.52s user 83.27s system 76% cpu 5:27.65 total
This last value is the one I don't know is real or not. The values are scaling pretty linearly. But I think the reason that the last one took so long is that the prime sieve I was using used up all the memory.
I have a trick to not encode 2's, so this table will immediately drop by half when I use this trick, and initializing the table will take half the time too.
Forgot how much fun coding can be. :D
No comments:
Post a Comment