+ Reply to Thread
Results 1 to 4 of 4

Thread: python maths post-shortened now. promise! please look

  1. #1
    Newbie amateur is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    8

    python maths post-shortened now. promise! please look

    could anyone give me the exact text i'd have to type into the python command line to make python check for integer solutions to:

    Code:
    n = log[base2]((7^(x)-1)/(2^(x)-1))= log[base2](7^(x)-1) - log[base2](2^(x)-1)

    what i want is the code i'd have to type into python to order it to look for integer solutions up to, say, n=10000, x=10000.
    Last edited by Jaan; 07-07-2009 at 07:03 PM.

  2. #2
    Newbie amateur is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    8

    Re: python maths post-shortened now. promise! please look

    could anyone at least refer me to a guide which, if read thoroughly, would give me the answer i need?

    none i have come across seem to offer answers about brute forcing...but someone on another forum claimed it was possible using python. they actually did it to an equation very similar to the one in my OP. but they ran off from the forum before i could ask them what could they typed into the command line...so i need some help from here.

  3. #3
    Code Warrior Brandon W is a name known to all Brandon W is a name known to all Brandon W is a name known to all Brandon W is a name known to all Brandon W is a name known to all Brandon W is a name known to all Brandon W's Avatar
    Join Date
    Sep 2008
    Location
    Australia
    Age
    16
    Posts
    4,824
    Blog Entries
    10

    Re: python maths post-shortened now. promise! please look

    I don't know Python so I don't know how the code would go but wouldn't you just type a few lines of code that will allow the end user to input a number which will be stored in the variable x. Then run that line of code with the value of x and then the answer would be stored in n.

    Just print the value of n then?
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

  4. #4
    Programming Expert Hignar will become famous soon enough Hignar's Avatar
    Join Date
    May 2009
    Posts
    399
    Blog Entries
    2

    Re: python maths post-shortened now. promise! please look

    To be honest I'm not sure what you are looking for. Do you want the program to try various values of x and see if n is an integer?

    I've not used the maths module for python so I don't know how you'd go about entering your formula but you need a loop like this

    Code:
    for x in range(1,10001):
        n = log[base2]((7^(x)-1)/(2^(x)-1))= log[base2](7^(x)-1) - log[base2](2^(x)-1)
        if n-int(n) == 0:
            print x
    unfortunately there is a problem with rounding error on floating point arithmetic ie if your function returns a value of 4.99999999999999999999 python will evaluate this to be 5.0 meaning the logic in the if statement above would return true. I'm not sure if there is a way round this problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Python Collection
    By reachpradeep in forum Python
    Replies: 1
    Last Post: 03-03-2007, 02:50 PM
  2. How to make Dumplings
    By ahsan16 in forum The Lounge
    Replies: 2
    Last Post: 01-11-2007, 10:55 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts