Programming
A Tale of 2 Secrets › Forums › T.E.M.P.E.S.T. › Programming
Tagged: #answer
- This topic has 56 replies, 12 voices, and was last updated 1 month, 2 weeks ago by T.
-
AuthorPosts
-
31st October 2025 at 11:20 pm #112193F6EXB_the_frenchyParticipant
#112187
Because I check whether each substring of 4-digit prime numbers is in the list of 1, 2, or 3 digits prime numbers.
1st November 2025 at 12:43 pm #112199AndGigglesParticipant@ByteInBits I seem to recall this being one of the early Project Euler problems. Did you find this problem there or from elsewhere?
4th November 2025 at 5:40 pm #112424ByteInBitsParticipant@MyGiggle
From another source. Notice that like the source I asked for the only other 4 digit number.
However I relooked at PE and you are correct it is PE#37 and that is asking to sum all such numbers (11 of them) as the answer.
Do you engage with the PE questions?
I have solved all of the first 50, plus about 6 other scattered numbers.
Its nice to see all those tick marks 😉I completed #37 on Fri, 25 Apr 2025,
[Edited by Harry – Sorry, had to remove the info here, hope you understand, Harry]6th November 2025 at 2:40 pm #112157Robb27Participant@ByteInBits #112155
I don’t profess to be the best python programmer, but this worked for me: 3797 as well as 3137 per your original post.
Number 3137 is prime and meets the conditions:
Suffix 7 is prime
Suffix 37 is prime
Suffix 137 is prime
Prefix 3 is prime
Prefix 31 is prime
Prefix 313 is primeNumber 3797 is prime and meets the conditions:
Suffix 7 is prime
Suffix 97 is prime
Suffix 797 is prime
Prefix 3 is prime
Prefix 37 is prime
Prefix 379 is prime`from sympy import *
def check_prime():
for p in range(1000, 10000):
if not isprime(p):
continues = str(p)
prefixes = [int(s[:i]) for i in range(1, 4)]
suffixes = [int(s[-i:]) for i in range(1, 4)]# Check if all prefixes and suffixes are prime
if all(isprime(x) for x in prefixes + suffixes):
print(f”\nNumber {p} is prime and meets the conditions:”)
for x in suffixes:
print(f” Suffix {x} is prime”)
for x in prefixes:
print(f” Prefix {x} is prime”)check_prime()
6th November 2025 at 2:41 pm #112180F6EXB_the_frenchyParticipant@ByteInBits
#112155I have two others numbers with this property.
I did wonder if that would happen! Makes it interesting to think about how to think about the problem. Harry
6th November 2025 at 2:42 pm #112192ByteInBitsParticipant[Think there might be a typo in this one confusing X and Y? Might be worth checking and posting again. Harry]
6th November 2025 at 2:42 pm #112194ByteInBitsParticipantF6EXB_the_frenchy
#112193Now I understand, thank you 😉
6th November 2025 at 2:43 pm #112430AndGigglesParticipantI did most of the first hundred when I was in high school (there were a few I couldn’t figure out) to procrastinate from studying for my exams, but university took over and I haven’t looked at them in years. Now I suppose I am using the NCC as a way to procrastinate from doing my representation theory homework. My problem with this competition has always been that the interesting challenges are always scheduled for when I have exams, so I will need to decide in a month or so if I would rather have decent grades or if I want to solve 10B (it will be a tough choice).
I hope you make the right choice! Wouldn’t want to ruin your career! Harry
8th November 2025 at 6:45 pm #112850ByteInBitsParticipant@F6EXB_the_frenchy
#112180As far as I am aware there are only two 4 digit numbers with the property.
There are of course other numbers having other digit counts.
But if you can prove you have two more 4 digit numbers . . .
8th November 2025 at 6:45 pm #112851ByteInBitsParticipant@Robb27
Correct answers from nice clear code.Do I recall correctly that you sometimes use PARI/gp?
I left off using python for gp, here is my code:
\\ PARI/GP Calculator Version 2.13.3 Code
{
forprime(p=1009,99973,
v=digits(p);
a=fromdigits(v[2..4]);b=fromdigits(v[3..4]);c=v[4];
d=fromdigits(v[1..3]);e=fromdigits(v[1..2]);f=v[1];
if(isprime(a)&&isprime(b)&&isprime(c)&&isprime(d)&&isprime(e)&&isprime(f),
print1(” “p))
)
}
3137 37978th November 2025 at 6:47 pm #113017ByteInBitsParticipantAnother little task to while away the time 😉
A RATHER LONLY NUMBER
=====================
Take a positive (base 10) integer X > 100 not having a 1 or 0 as its last digit.
Let Y = the last digit of X.
Let Z = X*Y.
Remove the last digit (Y) from X and place it as the first digit of X giving W.
If W is equal to Z then X is the number we seek.Example using a 4 digit integer 1234
[X=1234] [Y=4] [Z=X*Y=4936] [W=4123] -> W = Z? 4123 = 4936? False.
So X = 1234 is NOT the number we seek.Task
Write Code to find the first integer X that satisfies the condition.
(Hint X is below 1,000,000)Post your code and its answer.
9th November 2025 at 9:14 pm #113080F6EXB_the_frenchyParticipant#113017
@byteinbits
An ugly program. I am too lazy to filter numbers with 1 as last digit.for X in range(102 , 999999): Y1 = str(X) # X ==> CHAINE #print("X :", Y1) Y = Y1[-1] # Y dernier caractère ==> CHAINE #print("Y :",Y) Z = X * int(Y) # produit de deux ENTIERS #print("Z :", Z) W = Y + Y1[0 : -1] #print("W :", W) if int(W) == Z: print("réponse", X)réponse 111
réponse 1111
réponse 11111
réponse 102564
réponse 11111110th November 2025 at 9:33 am #113098F6EXB_the_frenchyParticipantA cleaner program:
for X in range(102 , 999999): if str(X)[-1] != str(1): # saute les nombres terminés par 1 Y = str(X)[-1] # Y dernier caractère ==> CHAINE Z = X * int(Y) # produit de deux ENTIERS W = Y + str(X)[0 : -1] if int(W) == Z: print("réponse", X)10th November 2025 at 3:52 pm #113173Robb27Participant@ByteinBits #112851
You have a good memory. Yes, I do use PARI/GP from time to time. I ran your code and out dropped the list of numbers! Whilst not my job, I can program in a number of languages depending on what I am doing. PARI/gp is fast and is great for (very) large numbers.For anyone reading, like all new languages, it takes a bit of effort, but there is good documentation available. Well worth investing some time if you interested in facilitating number theory computations (and some maths puzzles on the NCC 😉
10th November 2025 at 4:52 pm #113175Robb27Participant@ByteInBits #113017
With the PARI/GP below I get 410256 as the number.
{ for (x=101,1000000, v=digits(x); len = #v; y = v[len]; \\ Check if last digit is 0 or 1 to skip if (y == 0, next()); if (y == 1, next()); z=x*y; remaining_digits = v[1..len-1]; swapped_v = concat([y, remaining_digits]); w = fromdigits(swapped_v); if(w==z, print1("number= ",w) ); ); } -
AuthorPosts
- You must be logged in to reply to this topic.