Jarhyn
Wizard
- Joined
- Mar 29, 2010
- Messages
- 14,819
- Gender
- Androgyne; they/them
- Basic Beliefs
- Natural Philosophy, Game Theoretic Ethicist
I've had a bug in my brain since reading to a shamefully early point in Fundamentals of Mathematics.
There was a question about proving something or other about the expression of all exponents as a unique product of prime squares.
Anyway, there wasn't much in the book about prime number theory up to that point and I wanted to just fuck around with a computer and I wanted to write something to fairly quickly calculate "whatever the next prime" was.
I started writing numbers in various bases, first unary (which is really just strings of 1's, where 0 would have to be "1-1"), then in binary, then in trinary, etc. and then saw the pattern of where primes occurred being only where they are the only base so far with a "zero" at its one's place, using a spreadsheed and some copy/paste mod operator. Essentialy, there are "holes" in the field of "zeroes" at every prime that can be answered by creating a new "zero" in the field.
This probably isn't interesting either.
But I wrote an algorithm that rolls a wheel for every prime found so far and determines if they all come up empty.
I'm aware there's probably some more efficient structures I could use, but this is what I have...
Anyway, after I wrote something that worked mostly after the way I worked the spreadsheet analysis.
After writing my program, I looked up something about calculating the next prime and came on this thing about prime sieves, and I figure this must be some variant of an existing thing. And then it was past the time I generally like to stay awake for the night. Something about using optimizations with base 60 numbers?
There are apparently 2262 primes less than 20k according to google, so this is seeming to yield a correct answer (the actual size needs adjustment since it adds an extra prime).
It also yields a depressing number of misses that I need to track down.
Enjoy criticizing the thing I wasted my Sunday afternoon on.
There was a question about proving something or other about the expression of all exponents as a unique product of prime squares.
Anyway, there wasn't much in the book about prime number theory up to that point and I wanted to just fuck around with a computer and I wanted to write something to fairly quickly calculate "whatever the next prime" was.
I started writing numbers in various bases, first unary (which is really just strings of 1's, where 0 would have to be "1-1"), then in binary, then in trinary, etc. and then saw the pattern of where primes occurred being only where they are the only base so far with a "zero" at its one's place, using a spreadsheed and some copy/paste mod operator. Essentialy, there are "holes" in the field of "zeroes" at every prime that can be answered by creating a new "zero" in the field.
This probably isn't interesting either.
But I wrote an algorithm that rolls a wheel for every prime found so far and determines if they all come up empty.
I'm aware there's probably some more efficient structures I could use, but this is what I have...
Code:
// number_stuff.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdint>
#include <vector>
#include <map>
int main()
{
//calculate all 64 bit prime numbers? sure, why not
uint64_t val = 1;
uint64_t jump = 1;
std::vector<uint64_t> primes;
std::map<uint64_t, int64_t> counters;
do
{
uint64_t numPrimes = primes.size();
uint64_t highest = 1;
std::map<uint64_t, uint64_t> is_not;
val += jump;
bool bFound = false;
for (int i = 0; i < numPrimes; i++)
{
int prime = primes[i];
int counter = counters[prime];
counter -= jump;
while (counter < 0)
counter += prime;
//a zero was found in the counter pool, not prime.
if (!counter)
bFound = true;
counters[prime] = counter;
}
if (!bFound)
{
printf("%d\r\n", val);
primes.push_back(val);
counters[val] = val;
}
else
{
printf("miss: %d\r\n", val);
}
for (uint64_t prime_idx = 0; prime_idx < primes.size(); prime_idx++)
{
//we need to find the hole. For each prime, there is certainly a place
//the hole will not be: at its next basic zero.
is_not[counters[primes[prime_idx]]] = counters[primes[prime_idx]];
}
for(highest = 1; is_not.count(highest); highest++);
jump = highest;
}while (val < 20000);
printf("%d, %d\r\n", val, primes.size() -1);
}
Anyway, after I wrote something that worked mostly after the way I worked the spreadsheet analysis.
After writing my program, I looked up something about calculating the next prime and came on this thing about prime sieves, and I figure this must be some variant of an existing thing. And then it was past the time I generally like to stay awake for the night. Something about using optimizations with base 60 numbers?
There are apparently 2262 primes less than 20k according to google, so this is seeming to yield a correct answer (the actual size needs adjustment since it adds an extra prime).
It also yields a depressing number of misses that I need to track down.
Enjoy criticizing the thing I wasted my Sunday afternoon on.