I was not sure where to put this, because it is a math riddle. I figured I would get in less trouble for posting it here when it belongs in the Math section than I would for posting it in the Math section when it belongs here. Sorry if I guessed wrong.

I have an algorithm that takes a natural number as an input and outputs another natural number. However, not every input has an output. Here is the first 50 pairs where the left number is the input and right number is the output, with X representing non-existing outputs. I set it up vertically because I thought it would be easier to picture that way. Below that is the same information set up as a sequence. Can you guess my algorithm?

I'm guessing this has something to do with primes, because all outputs are primes, which is further supported by your accidental inclusion of 11 before taking it back. All odd numbers either map to 2 or nothing. All even numbers either map to 3, 5, or 7 in the given sequence. I would guess that if more numbers map to eleven and any other prime they would also be odd, because your eleven was accidentally mapped to an odd number, and the fact that you would indeed accidentally put an 11 suggests that an 11 appears somewhere further on in the sequence. Patterns from odd/even numbers Odd: 2,2,2,X,2,2,X,2,2,X,2,X,X,2,2,X,X,2,X,2,2,X,2,X,XEven:3,3,5,3,3,5,3,3,5,3,7,5,3,3,7,5,3,5,3,3,5,3,7,5,3Patterns I notice: every multiple of six maps to 5 except for 30, which maps to 7. Also two after every 7 comes a five. And two after every five comes a 3. Between each of those comes an XAlgorithm that comes close to yours: for each number, find the smallest prime that doesn't divide it. Then using consecutive numbers count down from that prime until you reach 2, where if the count isn't at a prime number return X. Then on the next number after the one mapped to 2 start over again and find the lowest prime number that doesn't divide it. This doesn't work for 22 or 46 in your sequence though, as 5 doesn't divide either of those and yet they both map to 7.Converting to a sequence of these counting down primes, each number n represents a sequence starting with the nth prime1,2,2,3,2,3,2,3,4,2,4,3,2,3,4I also can't help but notice that the numbers that recieve an X are all either primes or squares of primes, except for 33.Edit: Some of these have been blown out of the water by the most recent post, but I'm too tired to go further today.

I decided to give you guys some help and post some more numbers. I figured that even though most patterns should be solvable given 100 numbers, my pattern still gives really low numbers. I thought jumping to 1,000 would return numbers high enough to make the pattern easier to see, but nope. Still returns small stuff regularly. The biggest output between 1,000 and 1,100 is 19. So then I decided to jump to a million and got slightly better results. I even went to Wolfram Alpha and entered a simplified version, skipped to a trillion and STILL got small values small. I do not actually have a program written out to calculate the algorithm for me and I have a general rule to not do any calculations by hand that involve numbers in the trillions, so I do not know what the actually outputs would be. A cursory glance tells me that the outputs between 10^12 and 10^12 + 500 will be between 2 and ~120, with an average of ~30.

The output for n is always a prime p such that n + p is also prime. Furthermore, the output is almost always the smallest prime p such that n+p is prime, with the exceptions being at 90, 1002, 1080, 10^6 + 1, 10^6 + 12, 10^6 + 20, 10^6 + 26, 10^6 + 28 and 10^6 + 92.

sfwc wrote:Furthermore, the output is almost always the smallest prime p such that n+p is prime...

That actually is the pattern. The 'exceptions' are actually mistakes on my part, but give me a break. I calculated 400 outputs by hand and made 10 mistakes.

Now for the hidden second question! Can you make an algorithm that produces this pattern as a sequence without any Xs? I could not find an answer that did not have some kind of counter keeping track of how many Xs had been skipped, which means that to calculate term N, every term less than N had to calculated first.

"You are not running off with Cow-Skull Man Dracula Skeletor!" -Socrates

If we are able to calculate, as a function f, the number of primes less than or equal to a given number x, then we could iterate x0 = x, xi+1 = x+f(xi) until it converges, and use it to calculate our term N (or something similar to this method). After all, the only way an odd number will give an output of X is if it is two less than a composite number. However, there is one potential issue: what if an even number gives an output of X? That is, what if there is some even number that is not the difference of two primes? Maybe someone can point out a proof, but as far as I know this is still an open question.

Could you please explain that again? I do not understand. Also, there is a conjecture (I forget what it is called) that is generally accepted as true that if E is any even number and P is a prime number, then there are an infinite number of solutions to the equation E + P1 = P2

"You are not running off with Cow-Skull Man Dracula Skeletor!" -Socrates

Second point first: yes, that is a conjecture, and it is generally accepted as true, but to the best of my knowledge it has not yet actually been proved. If that conjecture happens to be false, the algorithm needs to be modified to take that into account.

First point second: Admittedly I misspoke in my statement of what I was looking for, I'll try again here.

Spoiler:

Suppose we have a function f(x) that outputs the number of primes less than or equal to x. Say we have some odd number 2x+1 and want to determine how many odd composite numbers are less than or equal to it. You would just take the number of odd positive integers (x+1) and subtract the number of primes less than or equal to 2x+1 (f(2x+1)) - in other words, calculate x+1-f(2x+1). This works because there is only one odd number that is neither prime nor composite (1), and there is only one prime number that is not odd (2), so those two cancel out in the count. By the same reasoning, for an even number 2x, we can find the number of odd composite numbers by calculating x-f(2x). Let the function that does this, that calculates the number of odd composite numbers less than or equal to x, be g(x). (Of course, this function may do weird things with values of x less than 2, but we are not considering the function for any values of x less than 3 anyway.)

Here is where the iteration happens. First, let x0=x. Then, for all i>0, let xi=x+g(xi-1). In other words, we skip however many odd composite numbers are less than x, when getting to x1. But in doing so, we may encounter new odd composite numbers that we need to skip, which is why we repeat the process and go to x2, and so on until the numbers stop increasing. This iterative function is a new function, that maps the set of positive integers to the set of positive integers that are not odd composites, in order. Let this function be h(x).

From this point, since the numbers we want to skip are those two less than odd composites, for any x, let y=h(x+2)-2, and then calculate the value for that y.

Poker wrote:Of course, this function may do weird things with values of x less than 2, but we are not considering the function for any values of x less than 3 anyway.

That may be a problem. Something I realized last night is that using 0 and negative numbers as inputs results in outputs that can be, but are not always, invalid (a.k.a. what I represent as 'X' in my examples). The exact definition of the pattern is [ T = P < Pminimized - N ], where 'T' is the term, 'N' is the term number, and 'P' is a prime number. As an algorithm, 'N' is the input and 'T' is the output.

It should be noted that the inequality is very important. Say that the for my algorithm, inputting 'A' results in 'B'. When 'B' is the input of a different algorithm the result is 'C'. Someone may think that putting '-A' in my algorithm would result in 'C'. This is incorrect, although it is an understandable mistake. I thought it was true until I wrote out the equation and started mapping negative numbers.

I made the pattern when I wondered what would happen if you listed the smallest twin prime, then cousin prime, then sexy prime... Eventually I decided that 2 can also be considered a sibling prime. This means that the smallest prime with the correct property is the output. Therefor, the smaller of a pair of sibling primes must be the answer.

Here are some inputs and outputs.

0, 2-1, 2-2, 3-3, 2-4, 3-5, 2-6, 5-7, X-8, 3-9, 2-10,3

P.S. Did you know that you cannot put a spoiler in a spoiler? The site does not match [ spoiler] to [ /spoiler] correctly, which I find rather funny considering the site's intended audience.

Quick aside: What is the correct mathematical notation meaning "The smallest possible value".

Spoiler:

Then, for all i>0, let xi= x +g(xi-1).

Unless I am missing something, which I probably am, you forgot to define x (a.k.a. the variable I made really big). This is not just me being a strangely well educated troll, I actual do not understand what you mean here. I am going to assume that you meant to put 'i'. Also, I think you put a '+' where you actually meant to put a '-'.

Spoiler:

In other words, we skip however many odd composite numbers are less than x, when getting to x1. But in doing so, we may encounter new odd composite numbers that we need to skip, which is why we repeat the process and go to x2, and so on until the numbers stop increasing.

If we are skipping numbers, why is the value increasing.

Spoiler:

From this point, since the numbers we want to skip are those two less than odd composites, for any x, let y=h(x+2)-2, and then calculate the value for that y.

I do not understand this. This is probably because I do not understand what came before it.

"You are not running off with Cow-Skull Man Dracula Skeletor!" -Socrates

jewish_scientist wrote:Thank you very much for the explanation. I have some more questions.

Spoiler:

Poker wrote:Of course, this function may do weird things with values of x less than 2, but we are not considering the function for any values of x less than 3 anyway.

That may be a problem. Something I realized last night is that using 0 and negative numbers as inputs results in outputs that can be, but are not always, invalid (a.k.a. what I represent as 'X' in my examples). The exact definition of the pattern is [ T = P < Pminimized - N ], where 'T' is the term, 'N' is the term number, and 'P' is a prime number. As an algorithm, 'N' is the input and 'T' is the output.

It should be noted that the inequality is very important. Say that the for my algorithm, inputting 'A' results in 'B'. When 'B' is the input of a different algorithm the result is 'C'. Someone may think that putting '-A' in my algorithm would result in 'C'. This is incorrect, although it is an understandable mistake. I thought it was true until I wrote out the equation and started mapping negative numbers.

I made the pattern when I wondered what would happen if you listed the smallest twin prime, then cousin prime, then sexy prime... Eventually I decided that 2 can also be considered a sibling prime. This means that the smallest prime with the correct property is the output. Therefor, the smaller of a pair of sibling primes must be the answer.

Here are some inputs and outputs.

0, 2-1, 2-2, 3-3, 2-4, 3-5, 2-6, 5-7, X-8, 3-9, 2-10,3

P.S. Did you know that you cannot put a spoiler in a spoiler? The site does not match [ spoiler] to [ /spoiler] correctly, which I find rather funny considering the site's intended audience.

Quick aside: What is the correct mathematical notation meaning "The smallest possible value".

Spoiler:

I'm not entirely sure where you're going with this. Could you give an example of where term N and term -N are unequal?

jewish_scientist wrote:

Spoiler:

Then, for all i>0, let xi= x +g(xi-1).

Unless I am missing something, which I probably am, you forgot to define x (a.k.a. the variable I made really big). This is not just me being a strangely well educated troll, I actual do not understand what you mean here. I am going to assume that you meant to put 'i'. Also, I think you put a '+' where you actually meant to put a '-'.

Spoiler:

What I am doing here, is creating a function h(x), that maps each value x to a value y, in order, excluding those numbers that are odd composites. In other words, h(7)=7, since there are no odd composites less than or equal to 7. h(8)=8 for the same reason. However, h(9)=10, skipping the number 9. The purpose for creating this function is to allow us to skip odd composite values. It's an index function, so to speak.

jewish_scientist wrote:

Spoiler:

In other words, we skip however many odd composite numbers are less than x, when getting to x1. But in doing so, we may encounter new odd composite numbers that we need to skip, which is why we repeat the process and go to x2, and so on until the numbers stop increasing.

If we are skipping numbers, why is the value increasing.

Spoiler:

This question is probably answered by my above explanation: we are not yet calculating your pattern itself. What we are doing is setting up an index function that allows us to skip the X's. So when we skip a particular value, 25, the index will move up to the next value, i.e. 26.

jewish_scientist wrote:

Spoiler:

From this point, since the numbers we want to skip are those two less than odd composites, for any x, let y=h(x+2)-2, and then calculate the value for that y.

I do not understand this. This is probably because I do not understand what came before it.

Spoiler:

The point of the +2/-2 part is so that when we put in 7 for x, we get h(9), which evaluates to 10, then subtract 2 to get 8. The seventh non-X value is the one we get when you plug in 8.

Poker wrote:I'm not entirely sure where you're going with this. Could you give an example of where term N and term -N are unequal?

'N' and '-N' will always give the same value, but it is a very reasonable mistake to think the opposite. In order for a number to be the output, it must be a sibling. Someone could say, 'Positive numbers give the smaller sibling and negative numbers give the larger sibling of the same pair.' This is wrong, because output is always the smallest number that exists in a pair. Although, I looked back at my equation and I think it is wrong. I'll have to review it some more.

Insert Stuff

What I am doing here, is creating a function h(x), that maps each value x to a value y, in order, excluding those numbers that are odd composites. In other words, h(7)=7, since there are no odd composites less than or equal to 7.

Let me work through this step by step:

Spoiler:

h(11) = ?x = 11x0 = 0

x1 = 11 + g(x1-1)x1 = 11 + g(x0)x1 = 11 + g(0)x1 = 11 + 0 = 11

x2 = 11 + g(x2-1)x2 = 11 + g(x1)x2 = 11 + g(11)x2 = 11 + 1 = 12

x3 = 11 + g(x3-1)x3 = 11 + g(x2)x3 = 11 + g(12)x3 = 11 + 1 = 12

x4 = 11 + g(x4-1)x4 = 11 + g(x3)x4 = 11 + g(12)x4 = 11 + 1 = 12

x4 = x3return x3h(11) = 12

Is this correct?

"You are not running off with Cow-Skull Man Dracula Skeletor!" -Socrates

Poker wrote:I'm not entirely sure where you're going with this. Could you give an example of where term N and term -N are unequal?

'N' and '-N' will always give the same value, but it is a very reasonable mistake to think the opposite. In order for a number to be the output, it must be a sibling. Someone could say, 'Positive numbers give the smaller sibling and negative numbers give the larger sibling of the same pair.' This is wrong, because output is always the smallest number that exists in a pair. Although, I looked back at my equation and I think it is wrong. I'll have to review it some more.

Ok, I think I was misinterpreting what you were saying, that's all.

jewish_scientist wrote:

Insert Stuff

What I am doing here, is creating a function h(x), that maps each value x to a value y, in order, excluding those numbers that are odd composites. In other words, h(7)=7, since there are no odd composites less than or equal to 7.

Let me work through this step by step:

Spoiler:

h(11) = ?x = 11x0 = 0

x1 = 11 + g(x1-1)x1 = 11 + g(x0)x1 = 11 + g(0)x1 = 11 + 0 = 11

x2 = 11 + g(x2-1)x2 = 11 + g(x1)x2 = 11 + g(11)x2 = 11 + 1 = 12

x3 = 11 + g(x3-1)x3 = 11 + g(x2)x3 = 11 + g(12)x3 = 11 + 1 = 12

x4 = 11 + g(x4-1)x4 = 11 + g(x3)x4 = 11 + g(12)x4 = 11 + 1 = 12

x4 = x3return x3h(11) = 12

Is this correct?

Spoiler:

Technically x0 = x, not 0, but when x0 = 0, x1 would equal x anyway, so all that does is delay it a step - the result is still the same. Also, you could've stopped at x3 since x2 = x3, but the result is still the same. Neither of those "mistakes" change the result, nor to the best of my knowledge would they ever change the result, so yes, that is correct.

Poker wrote:From this point, since the numbers we want to skip are those two less than odd composites, for any x, let y=h(x+2)-2, and then calculate the value for that y.

x = 9y = h(9 + 2) - 2y = h( 11 ) - 2y = 12 - 2y = 109,10

However, the correct mapping is 9,2.

First of all, for what I'm trying to accomplish, there is one X that we're skipping (for 7), so the final output for 9 should be 3, corresponding to the 10th term of the original sequence.

Which brings me to my second point, which I now realize was not given enough emphasis/worded in a confusing manner: the function h(x) is not the end of the story. It merely tells us what term of the original sequence (X's included) should be used in the new sequence (X's excluded).

Poker wrote:Which brings me to my second point, which I now realize was not given enough emphasis/worded in a confusing manner: the function h(x) is not the end of the story. It merely tells us what term of the original sequence (X's included) should be used in the new sequence (X's excluded).

Aww, I got that now. One last more question: If M() represents my algorithm and M(x) = X, then what does h(x) equal?

"You are not running off with Cow-Skull Man Dracula Skeletor!" -Socrates

Poker wrote:Which brings me to my second point, which I now realize was not given enough emphasis/worded in a confusing manner: the function h(x) is not the end of the story. It merely tells us what term of the original sequence (X's included) should be used in the new sequence (X's excluded).

Aww, I got that now. One last more question: If M() represents my algorithm and M(x) = X, then what does h(x) equal?

It will equal some y where M(y) =/= X (after taking into account the +2/-2 shifting).