# Transforming the code to use recursion

**URL:** <https://racket.discourse.group/t/transforming-the-code-to-use-recursion/1236>\
**Category:** Questions & Answers\
**Created:** [August 16, 2022, 7:00pm UTC](https://racket.discourse.group/t/transforming-the-code-to-use-recursion/1236 "2022-08-16T19:00:34Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![alexh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexh/32/315_2.png) [@alexh](https://racket.discourse.group/u/alexh)\
**Post date:** [August 19, 2022, 11:16pm UTC](https://racket.discourse.group/t/transforming-the-code-to-use-recursion/1236/21 "2022-08-19T23:16:08Z")

</div>

Finding the first few hundred thousand primes is a trivial problem as many of the answers here show. If you are looking for a challenge with prime numbers try one of these:

- write a program that finds the N-th prime number, where N is supplied by the user when invoking the procedure. For example `(nth-prime 5)` would return 11 since 11 is the fifth prime (assuming primes start at 2). The user will test this function by passing values greater than 10000000 (ten million) to `nth-prime`.
- write a program that finds the first prime number (not a pseudo prime number) after a value X, where X is supplied by the user when invoking the procedure. For example `(first-prime-after 5)` would return 7, since 7 is the first prime greater than 5. The user will test this function by passing values greater than 18446744073709551616 to `first-prime-after` (i.e values larger than 64 bits).

Enjoy,  
Alex.

---

<div class="post-metadata">

**Author:** ![hendrikboom3](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/hendrikboom3/32/2748_2.png) [@hendrikboom3](https://racket.discourse.group/u/hendrikboom3)\
**Post date:** [August 23, 2022, 12:07pm UTC](https://racket.discourse.group/t/transforming-the-code-to-use-recursion/1236/22 "2022-08-23T12:07:29Z")

</div>

Natural number primes do start at 2.  
The elements of a ring are classified as

```
* zero
* units (those elements with multiplicative inverses)
* primes (which can be factored into multiple factors only if all but one factor is a unit)
* composites

```

So the natural number 1 is a unit, not a prime. 2 is a prime.  
In the integers, 1 and -1 are units, and -2 is a prime.  
In the reals, every real numner except 0 is a unit.

-- hendrik

[Previous page](https://racket.discourse.group/t/transforming-the-code-to-use-recursion/1236.md?page=1)
