# Twin primes

```ruby
func twin_primes_count(upto) {
    var count = 0
    var p1 = 2
    each_prime(3, upto, {|p2|
        if (p2 - p1 == 2) {
            ++count
        }
        p1 = p2
    })
    return count
}

for n in (1..9) {
    var count = twin_primes_count(10**n)
    say "There are #{count} twin primes <= 10^#{n}"
}
```

## Output:

```
There are 2 twin primes <= 10^1
There are 8 twin primes <= 10^2
There are 35 twin primes <= 10^3
There are 205 twin primes <= 10^4
There are 1224 twin primes <= 10^5
There are 8169 twin primes <= 10^6
There are 58980 twin primes <= 10^7
There are 440312 twin primes <= 10^8
There are 3424506 twin primes <= 10^9
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/t/twin_primes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
