Mobile Apps - Questions and answers regarding iPhone/iPad, Droid, & Blackberry Apps
Please read the Discussion Board Rules before participating in the discussion boards.
"What is an App?" you may ask. An app is a self-contained program or piece of software designed to fulfill a particular purpose; an application, esp. as downloaded by a user to a mobile device. So far, GoldToken only offers a Droid App.

Please do be aware that GoldToken's Droid app is for internet users using Google's OS (operating system) on smart phones, cell phones and tablets. It is usable for iPhone and BlackBerry products as well, but it won't function quite as well as it should because it's specifically designed for Droid based phones and tablets.

You can download GoldToken's Droid App here: http://www.goldtoken.com/phone.html

Vine DividerVine DividerVine Divider

2 Red car The mobile site can be found at http://m.goldtoken.com/



.
Post a new comment                         Back to Mobile Apps                         Show all boards                         Subscribe Subscribe

(#5617794) Re: sounds good .. but ..
Posted by TabbyCat on 16 Jul 2024 at 5:47PM
I asked Perplexity.ai to do the following:
write Python code for determining the number of prime numbers there are between 1 and 1,000,000

Here's a Python script that determines the number of prime numbers between 1 and 1,000,000 using the Sieve of Eratosthenes algorithm, which is an efficient method for finding prime numbers up to a given limit:

```python
import time

def count_primes(limit):
   # Create a boolean array "is_prime[0..limit]" and initialize
   # all entries it as true. A value in is_prime[i] will
   # finally be false if i is Not a prime, else true.
   is_prime = [True] * (limit + 1)
   is_prime[0] = is_prime[1] = False

   for i in range(2, int(limit**0.5) + 1):
       if is_prime[i]:
           # Update all multiples of i
           for j in range(i*i, limit + 1, i):
               is_prime[j] = False

   # Count prime numbers
   return sum(is_prime)

  1. Set the limit
limit = 1_000_000

  1. Record the start time
start_time = time.time()

  1. Count the prime numbers
prime_count = count_primes(limit)

  1. Record the end time
end_time = time.time()

  1. Calculate the execution time
execution_time = end_time - start_time

print(f"Number of primes between 1 and {limit}: {prime_count}")
print(f"Execution time: {execution_time:.4f} seconds")
```

This script does the following:

1. We define a function `count_primes(limit)` that implements the Sieve of Eratosthenes algorithm.

2. We create a boolean array `is_prime` where each index represents a number, and the value at that index indicates whether the number is prime (True) or not (False).

3. We iterate through numbers from 2 to the square root of the limit. For each prime number found, we mark all its multiples as non-prime.

4. After the sieve is complete, we count the number of True values in the `is_prime` array, which gives us the count of prime numbers.

5. We use the `time` module to measure the execution time of the algorithm.

6. Finally, we print the count of prime numbers and the execution time.

When you run this script, it will output the number of prime numbers between 1 and 1,000,000 and how long it took to calculate. The result should be 78,498 prime numbers, and the execution time will depend on your computer's performance, but it should be relatively quick (typically less than a second on modern hardware).

This method is much faster than checking each number individually for primality, especially for large ranges like 1 to 1,000,000.
div>Replies to this message:
SubjectPosted ByDate & Time
5618961Re: sounds good .. but .. Steven S22 Jul 2024 7:50PM
5618915Re: sounds good .. but .. TabbyCat22 Jul 2024 12:48PM
5618799Re: sounds good .. but .. Steven S21 Jul 2024 7:44PM
5618734Re: sounds good .. but .. TabbyCat21 Jul 2024 1:42PM
5618732Re: sounds good .. but .. TabbyCat21 Jul 2024 1:40PM
5618552Re: sounds good .. but .. Steven S20 Jul 2024 5:50PM
5618515Re: sounds good .. but .. TabbyCat20 Jul 2024 1:57PM
5618362Re: sounds good .. but .. Steven S19 Jul 2024 7:07PM
5618357Re: sounds good .. but .. TabbyCat19 Jul 2024 6:07PM
5617800Re: sounds good .. but .. Steven S16 Jul 2024 6:05PM
5617794Re: sounds good .. but .. TabbyCat16 Jul 2024 5:47PM

Post a new comment                         Back to Mobile Apps                         Show all boards                         Subscribe Subscribe