Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python competiton
#1
Make a script, that will when give a product of two prime factors, prints those two.


Example:

Product(x*y): 15
x = 3
y = 5

That's actually a program that can decrypt RSA password, when given x and y.
Which would take (on personal computer) about as long as the universe is old. (That's long)


+Rep to the one who makes it first.


________________________________________________

Oh, come on it's not that hard.Oui

For the proposes of understanding, this is a contest, I have already written this script and I don't want someone to do it for me.
Reply
#2
Quote:#Created by Socrates. If you would like to copy this give credit at least Tongue
#Make sure the numbers you enter are prime and it will transpute them.
def prime():
prime = raw_input("Enter your number:")
print prime,"1"

Reply
#3
No, no, no. He's asking for you to basically find whether or not the number you are given is a product of 2 prime number, and if it is, what are the 2 prime numbers.

I've actually been working on this since you started the competition, and been looking online for functions or something to test if a number is prime, but my effort has been in vain. I'm still learning so I'll get back to you on this.
Reply
#4
yeah i did test it out
Reply
#5
Code:
def isprime(Number):
    if Number < 2 or not Number & 1:
        return False
    if Number == 2:
        return True
    for x in range(3, int(Number**0.5)+1, 2):
        if Number % x == 0:
            return False
    return True
[Image: nv70ad.png]
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
Reply
#6
I can throw you that up quick in enough, but only in C. But you someone should be able to translate it. What's the biggest possible number to be entered (eg. max value of x*y)?

Edit:
Here's your solution in C, maybe someone can take the concept and write it down in Python.
Code:
//Include standard input-output.
#include <stdio.h>
//Function to check, whether the provided number is a prime, if it is, returns 0.
int start(int a)
{
int i;
for(i=2;i<(a/2)+1;i++)
{
if(a%i==0)
return 1;
}
return 0;
}
//My lovely main function.
int main()
{
//Lets the user know the program is online.
printf("Starting...\n");
//A variable to set the amout of primes to calculate.
//The program calculates l+1 first primes.
int l;
l=9999;
//Declaring my variables and an array large enough, to hold the primes.
int i,n,d,a,primes[l];
//The first prime is 2, ergo i=2 at kickoff.
i=2;
n=0;
//While the array is not filled with primes...
while(n<=l)
{
//Find primes. If i is a prime, stick it in the array.
if(start(i)==0)
{primes[n]=i;
n++;
i++;}
else
//If it isn't, keep searching.
{i++;}
}
//Notify of the results, how many primes were calculated, etc.
printf("Done calculating the first %d primes into an array.\n",(l+1));
printf("The last calulated prime is %d,\nso the entered number has to be smaller than the square of that.\n",primes[l]);
printf("Please enter your number: ");
//Read in the number the user is interested in.
scanf("%d",&d);
printf("Searching now...\n");
//Check if the provided number can be produced by multiplying numbers from the array, which holds the primes.
for(a=0;a<n;a++)
{
for(i=0;i<n;i++)
if(primes[a]*primes[i]==d)
{
//If yes, print out the numbers.
printf("Gotcha, your primes are %d and %d!",primes[a],primes[i]);
getchar();
getchar();
return 0;
}
}
//If not, be sad. =(
printf("No primes identified.");
getchar();
getchar();
return 0;
}
//Written by Etheryte, released to the free world.
Reply
#7
Lol ok Fallen won!
Reply
#8
Fallen did the ispirme function.
But the whole script has to check if the given number (in this case 15) is dividable by 3 if not try dividing with 5 and so on.
That's the easy part.
(10-09-2009, 04:31 AM)Etheryte Wrote: I can throw you that up quick in enough, but only in C. But you someone should be able to translate it. What's the biggest possible number to be entered (eg. max value of x*y)?

Edit:
Here's your solution in C, maybe someone can take the concept and write it down in Python.
To test the exe version of my code, just download it.
Code:
//Include standard input-output.
#include <stdio.h>
//Function to check, whether the provided number is a prime, if it is, returns 0.
int start(int a)
{
int i;
for(i=2;i<(a/2)+1;i++)
{
if(a%i==0)
return 1;
}
return 0;
}
//My lovely main function.
int main()
{
//Lets the user know the program is online.
printf("Starting...\n");
//A variable to set the amout of primes to calculate.
//The program calculates l+1 first primes.
int l;
l=9999;
//Declaring my variables and an array large enough, to hold the primes.
int i,n,d,a,primes[l];
//The first prime is 2, ergo i=2 at kickoff.
i=2;
n=0;
//While the array is not filled with primes...
while(n<=l)
{
//Find primes. If i is a prime, stick it in the array.
if(start(i)==0)
{primes[n]=i;
n++;
i++;}
else
//If it isn't, keep searching.
{i++;}
}
//Notify of the results, how many primes were calculated, etc.
printf("Done calculating the first %d primes into an array.\n",(l+1));
printf("The last calulated prime is %d,\nso the entered number has to be smaller than the square of that.\n",primes[l]);
printf("Please enter your number: ");
//Read in the number the user is interested in.
scanf("%d",&d);
printf("Searching now...\n");
//Check if the provided number can be produced by multiplying numbers from the array, which holds the primes.
for(a=0;a<n;a++)
{
for(i=0;i<n;i++)
if(primes[a]*primes[i]==d)
{
//If yes, print out the numbers.
printf("Gotcha, your primes are %d and %d!",primes[a],primes[i]);
getchar();
getchar();
return 0;
}
}
//If not, be sad. =(
printf("No primes identified.");
getchar();
getchar();
return 0;
}
//Written by Etheryte, released to the free world.

I don't know if there's a limit with number size in C, but the script I written in Python should work with all numbers. But the process itself takes ridiculously long at big numbers.
Reply
#9
Rebuilt the code so it can work with any number provided. No matter what language you choose, it will take a long time if the number is large, the size of the number and the time needed create an exponential function.
Reply
#10
So, now that they did this thing.. what does it do?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 2,036 09-30-2019, 12:59 AM
Last Post: samsmith001
  Simple Python Python Compiler Canoris 21 9,349 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,720 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 925 02-12-2010, 09:07 PM
Last Post: Kharnage
  "==" and "is" in Python Canoris 1 858 02-07-2010, 03:55 PM
Last Post: uber1337

Forum Jump:


Users browsing this thread: 5 Guest(s)