mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Puzzles (https://www.mersenneforum.org/forumdisplay.php?f=18)
-   -   Upside Down Primes (https://www.mersenneforum.org/showthread.php?t=14152)

CRGreathouse 2010-11-07 18:46

[QUOTE=science_man_88;235945]see my first idea was to invert a vector of some kind but I bet that's slow as well.[/QUOTE]

Probably, especially since I don't know of a fast way to re-join it.

science_man_88 2010-11-07 18:48

[QUOTE=CRGreathouse;235947]Probably, especially since I don't know of a fast way to re-join it.[/QUOTE]

I was thinking of just inverting the index but that overwrites half the indexes improperly lol

[CODE]v=vector(input());a=#v;forstep(i=a,1,-1,v=concat(v,v[i]));[/CODE]

this might work with you vector shift code on the end to shift out the first a values.

and i may change it to Vec to allow the <93> stuff then the hard part is making a code to convert the strings into individual or groups of digits to test the primality.

[B][U]NOTE[/U][/B]:this was not my original code.

CRGreathouse 2010-11-07 19:41

That would be extremely slow. Here's the right way of doing that:

[code]rev(n)={
my(v=eval(Vec(Str(n))),u=vector(#v,i,v[#v+1-i]));
sum(i=0,#u-1,u[#u-i]*10^i)
};[/code]

My code (last post) takes 4.17 seconds to reverse the numbers from 1 to a million; this code takes 9.2 seconds. Both can be improved substantially, but I would rather start from that one than this.

davieddy 2010-11-07 21:02

True story
 
[QUOTE=davar55;235544]The digits 0, 1, 2, 5, 6, 8, and 9 have a kind of collective symmetry
upon turning a decimal number 180 degrees (clockwise), with 0, 1, and 8
transforming to themselves, 2 and 5 also (using some imagination),
and 6 and 9 transforming into each other.

If a number and its upside down transform are both prime (and different),
like 19 and 61, or 109 and 601, these numbers are "partners".

Find as large a pair of partners as possible that contain all 7 of these
digits at least once. (I include the last condition because it might be
too easy to find a rep-unit or a form 10^n + 9).[/QUOTE]

The other day, my front door was repainted. I opted for Oxford blue.
The painter jested that the whole estate would end up looking like
a Butlin's holiday camp. He needed to unscrew the number 19 from
the door, and we jested about the four different ways they might get
reinstated.
The numbers sat outside for a few days until some well-meaning
person screwed them back on.
I now live at number16.

David

[URL="http://www.youtube.com/watch?v=Hr97qzUVdgE"]You're Sixteen[/URL]

axn 2010-11-07 21:04

[QUOTE=science_man_88;235935]are you making a string reversing code I've tried but I can't get tit to work right now lol if i do maybe i can finally care about this.[/QUOTE]

String reversal is not enough. We're talking about string "rotation". And no, I don't do string reversal/rotation -- instead I've chosen patterns that gives me matched pairs directly.

bsquared 2010-11-08 01:39

[QUOTE=science_man_88;235935]are you making a string reversing code I've tried but I can't get tit to work right now lol if i do maybe i can finally care about this.[/QUOTE]

As others have said, you need rotation, not reversal. I do it with a vector of bytes:

[CODE]void rotVec(char *vecin, char *vecout, int num)
{
int i;

for (i=0; i<num; i++)
{
switch (vecin[i])
{
case 0:
case 1:
case 8:
case 2:
case 5:
vecout[num-i-1] = vecin[i];
break;
case 6:
vecout[num-i-1] = 9;
break;
case 9:
vecout[num-i-1] = 6;
break;
}
}


return;
}[/CODE]

Extremely straightforward... but effective enough. It can rotate a vector of 10 million entries in 50 milliseconds or so, but of course I never need to rotate anything that big.

Batalov 2010-11-08 05:47

1268*10^3605+8951 and 1268*10^3605+8951 ? :rolleyes:

Yeah, ok, you want different. Let's search for these now.

science_man_88 2010-11-08 13:34

[QUOTE=Batalov;236029]1268*10^3605+8951 and 1268*10^3605+8951 ? :rolleyes:

Yeah, ok, you want different. Let's search for these now.[/QUOTE]

it must be a A002385 because you list the same number twice hence it's the same backwards and forwards.

davar55 2010-12-19 19:20

[quote=science_man_88;236065]it must be a A002385 because you list the same number twice hence it's the same backwards and forwards.[/quote]

I really specified the OP to make this an interesting and solvable puzzle.

This last result is a perfect extension, and would make a nice sequence too.

Anyone want to work on the first 100 integers in those two sequences?

davar55 2011-01-09 20:57

The OP defined upside down partnered primes.
The example of a big one that partnered itself
was an add-on to the original puzzle, and the
sequence of these would be another related
new sequence.

If anyone would compute, say, the first 100 terms
of each of these sequences, it might be interesting.
We already have some big ones.

davar55 2012-08-05 00:42

Just learned that M1061 has been factored, as P1 x P2 (two prime factors).

Since 1061 and 1901 are prime upside-down partners ,
I ran factorbd on 2^1901-1 and found a P501 as largest factor.

I think it computed rather than did a lookup.

Is this P501 previously unrecorded? Just thought I'd ask.


All times are UTC. The time now is 05:34.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.