Skip to main content
The National Cipher Challenge

Programming

A Tale of 2 Secrets Forums T.E.M.P.E.S.T. Programming

Tagged: 

Viewing 15 posts - 31 through 45 (of 57 total)
  • Author
    Posts
  • #112193
    F6EXB_the_frenchy
    Participant

    #112187

    Because I check whether each substring of 4-digit prime numbers is in the list of 1, 2, or 3 digits prime numbers.

    #112199
    AndGiggles
    Participant

    @ByteInBits I seem to recall this being one of the early Project Euler problems. Did you find this problem there or from elsewhere?

    #112424
    ByteInBits
    Participant

    @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]

    #112157
    Robb27
    Participant

    @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 prime

    Number 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):
    continue

    s = 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()

    #112180
    F6EXB_the_frenchy
    Participant

    @ByteInBits
    #112155

    I 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

    #112192
    ByteInBits
    Participant

    [Think there might be a typo in this one confusing X and Y? Might be worth checking and posting again. Harry]

    #112194
    ByteInBits
    Participant

    F6EXB_the_frenchy
    #112193

    Now I understand, thank you 😉

    #112430
    AndGiggles
    Participant

    I 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

    #112850
    ByteInBits
    Participant

    @F6EXB_the_frenchy
    #112180

    As 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 . . .

    #112851
    ByteInBits
    Participant

    @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 3797

    #113017
    ByteInBits
    Participant

    Another 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.

    #113080
    F6EXB_the_frenchy
    Participant

    #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 111111

    #113098
    F6EXB_the_frenchy
    Participant

    A 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)
    
    #113173
    Robb27
    Participant

    @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 😉

    #113175
    Robb27
    Participant

    @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)
          );
        );
    }
Viewing 15 posts - 31 through 45 (of 57 total)
  • You must be logged in to reply to this topic.
Report a problem