A Kotlin project for finding polynomials that generate consecutive prime numbers. This project explores the fascinating mathematical problem of discovering quadratic polynomials of the form n² + an + b that produce the longest sequences of consecutive primes.
See detailed article: Finding the Optimal Prime-Generating Polynomial: A Journey Through Euler's Mathematical Legacy
- Prime number detection algorithms
- Polynomial evaluation and prime sequence generation
- Comprehensive test suite using Kotest
- Containerized development environment
- Java 8 or higher
- Gradle (wrapper included)
- Docker (optional, for containerized development)
DankPolynomials/
├── gradlew # Gradle wrapper script
├── gradle/wrapper/ # Gradle wrapper files
├── settings.gradle.kts # Multi-module project settings
├── Dockerfile # Docker configuration
└── app/ # Main application module
├── build.gradle.kts # Build configuration
└── src/
├── main/kotlin/com/dankpolynomials/
│ ├── DankPolynomials.kt # Core algorithms
│ └── Main.kt # Application entry point
└── test/kotlin/com/dankpolynomials/
└── DankPolynomialsTest.kt # Test suite
./gradlew build./gradlew run./gradlew test./gradlew clean buildThe project includes a Dockerfile for consistent development environments across different machines.
docker build -t dankpolynomials .docker run -it dankpolynomials# Run tests with detailed output
docker run -it dankpolynomials ./gradlew test
# Clean and run tests
docker run -it dankpolynomials ./gradlew clean test
# Force test execution (ignore up-to-date checks)
docker run -it dankpolynomials ./gradlew test --rerun-tasks# Start a shell inside the container
docker run -it dankpolynomials /bin/bash
# Then run any Gradle commands
./gradlew build
./gradlew test
./gradlew runFor active development, you can mount your local source code:
# Mount current directory for live code changes
docker run -it -v $(pwd):/app dankpolynomials /bin/bashThis project uses Kotest for testing, which provides:
- Property-based testing
- Powerful assertions
- Multiple testing styles
- JUnit 5 integration
The test suite includes:
- Prime number detection tests
- Edge case handling
- Polynomial evaluation validation
- Performance benchmarks
> Task :test
com.dankpolynomials.DankPolynomialsTest > isPrime should return true for prime numbers PASSED
com.dankpolynomials.DankPolynomialsTest > isPrime should return false for non-prime numbers PASSED
com.dankpolynomials.DankPolynomialsTest > isPrime should handle edge cases PASSED
com.dankpolynomials.DankPolynomialsTest > getBestPolynomial should return expected result STANDARD_OUT
Best Polynomial: n² + -61n + 971, Consecutive Primes: 71
com.dankpolynomials.DankPolynomialsTest > getBestPolynomial should return expected result PASSED
Results: SUCCESS (4 tests, 4 passed, 0 failed, 0 skipped)
- Base Image: Amazon Corretto 8 Alpine
- Size: Optimized for small footprint
- Build Cache: Leverages Gradle dependency caching
- Multi-stage: Separates dependency download from source compilation
- Downloads and caches Gradle dependencies
- Compiles Kotlin source code
- Runs the application by default
- Can be overridden to run tests or other tasks
This project explores quadratic polynomials that generate consecutive primes. The famous example is Euler's polynomial n² + n + 41, which generates 40 consecutive primes for n = 0, 1, 2, ..., 39.
The current implementation has found polynomials generating impressive sequences, such as:
n² + -61n + 971producing 71 consecutive primes
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
./gradlew test - Submit a pull request
- The project uses Java 8 toolchain for compatibility
- Gradle wrapper ensures consistent build environment
- Docker provides isolated, reproducible builds
- Kotest enables comprehensive testing strategies
Build fails with "Cannot find Java installation"
# Ensure JAVA_HOME is set or use the Docker environment
docker run -it dankpolynomials ./gradlew buildTests show "UP-TO-DATE" but don't run
# Force test execution
./gradlew test --rerun-tasks
# Or clean first
./gradlew clean testDocker build is slow
- First build downloads all dependencies (normal)
- Subsequent builds use layer caching and are much faster
- Only source code changes trigger recompilation