> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/o/one-two_primes.md).

# One-two primes

```ruby
say "Smallest n digit prime using only 1 and 2:"

for k in (0..20) {
    ['1','2'].variations_with_repetition(k, {|*a|
        var p = Num(a.join)
        if (p.is_prime) {
            printf("%4d. %s\n", k, p)
            break
        }
    })
}

for k in (100..2000 `by` 100) {
    ['1','2'].variations_with_repetition(k-1, {|*a|
        var p = Num(a.join + '1')
        if (p.is_prime) {
            var t = Str(p)
            var i = t.index('2')
            printf("%4d. (1 x %s) %s\n", k, i, t.substr(i))
            break
        }
    })
}
```

#### Output:

```
Smallest n digit prime using only 1 and 2:
   1. 2
   2. 11
   3. 211
   4. 2111
   5. 12211
   6. 111121
   7. 1111211
   8. 11221211
   9. 111112121
  10. 1111111121
  11. 11111121121
  12. 111111211111
  13. 1111111121221
  14. 11111111112221
  15. 111111112111121
  16. 1111111112122111
  17. 11111111111112121
  18. 111111111111112111
  19. 1111111111111111111
  20. 11111111111111212121
 100. (1 x 92) 21112211
 200. (1 x 192) 21112211
 300. (1 x 288) 211121112221
 400. (1 x 390) 2111122121
 500. (1 x 488) 221222111111
 600. (1 x 590) 2112222221
 700. (1 x 689) 21111111111
 800. (1 x 787) 2122222221111
 900. (1 x 891) 222221221
1000. (1 x 988) 222122111121
1100. (1 x 1087) 2112111121111
1200. (1 x 1191) 211222211
1300. (1 x 1289) 22121221121
1400. (1 x 1388) 222211222121
1500. (1 x 1489) 21112121121
1600. (1 x 1587) 2121222122111
1700. (1 x 1688) 212121211121
1800. (1 x 1791) 221211121
1900. (1 x 1889) 22212212211
2000. (1 x 1989) 22121121211
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/o/one-two_primes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
