Skip to content

Commit

Permalink
Merge branch 'main' into p82
Browse files Browse the repository at this point in the history
Brought in the restructuring which happened on the default branch.
  • Loading branch information
tfpf committed Sep 25, 2024
2 parents a836ae7 + 71a924c commit f81198a
Show file tree
Hide file tree
Showing 99 changed files with 9,201 additions and 2,151 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: lint
on: [push, workflow_dispatch]
on:
push:
paths:
- '.github/workflows/lint.yml'
- '**.rs'
workflow_dispatch:

jobs:
lint:
name: lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: cargo clippy
- run: cargo clippy -- --deny clippy::all
15 changes: 11 additions & 4 deletions .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
name: sanity
on: [push, workflow_dispatch]
on:
push:
paths:
- '.github/workflows/sanity.yml'
- 'Dockerfile'
- 'res/solutions/*.txt'
- '**.rs'
workflow_dispatch:

jobs:
sanity32:
Expand All @@ -15,13 +22,13 @@ jobs:
- uses: addnab/docker-run-action@v3
with:
image: sanity32
run: cargo -vv run --release
run: cargo -vv run -vv --release
sanity64:
name: sanity on 64-bit ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-12, ubuntu-22.04, windows-2022]
os: [macos-13, macos-14, ubuntu-22.04, windows-2022]
steps:
- uses: actions/checkout@v4
- run: cargo -vv run --release
- run: cargo -vv run -vv --release
10 changes: 8 additions & 2 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
name: style
on: [push, workflow_dispatch]
on:
push:
paths:
- '.github/workflows/style.yml'
- 'rustfmt.toml'
- '**.rs'
workflow_dispatch:

jobs:
style:
name: style
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: cargo fmt --check
- run: cargo fmt -v --check
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ name: tests
on:
push:
paths:
- src/utils.rs
- '.github/workflows/tests.yml'
- 'Dockerfile'
- 'src/lib.rs'
- 'src/utils.rs'
- 'res/tests/*.txt'
- 'src/utils/**.rs'
workflow_dispatch:

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
/.vscode
/Cargo.lock
3 changes: 3 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Code of Conduct

Just be cool (optional).
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Contributing

Not accepting pull requests, since this is my personal learning project.
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ name = "project-euler"
version = "1.0.0"
edition = "2021"

[dev-dependencies]
criterion = "0.4.0"

[[bench]]
name = "benches"
harness = false

[profile.release]
incremental = true
strip = true
overflow-checks = true
strip = "debuginfo"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/i386 alpine:3.19
RUN apk add cargo
WORKDIR /project-euler
WORKDIR /github.com/tfpf/project-euler
COPY . .
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Project Euler
Trying my hand at [Project Euler](https://projecteuler.net) as I stumble along learning Rust. I shall only add the
solutions to the first hundred problems here with the intention being to showcase whatever useful data structures I
build along the way. This is permitted according to the Project Euler guidelines.
build along the way. (This is permitted according to the Project Euler guidelines.) Further, I shall restrict myself to
the standard library.

[![style](https://github.com/tfpf/project-euler/actions/workflows/style.yml/badge.svg)](https://github.com/tfpf/project-euler/actions/workflows/style.yml)
[![lint](https://github.com/tfpf/project-euler/actions/workflows/lint.yml/badge.svg)](https://github.com/tfpf/project-euler/actions/workflows/lint.yml)
Expand All @@ -20,8 +21,21 @@ Run it without arguments to sequentially solve all problems for which I have wri
cargo r
```

Most solutions are rather concise; the heavy lifting is done in [`src/utils.rs`](src/utils.rs). This highlights the
intent of the code by hiding confounding implementation details.
Most solutions are rather concise; the heavy lifting is done in the `utils` module. This highlights the intent of the
code by hiding confounding implementation details. Items of particular note therein are the following.
* `is_prime`: fast prime checker which combines trial division and the Miller-Rabin algorithm.
* `pow`: modular exponentiation calculator, emulating the `pow` function of Python.
* `Long`: arbitrary-precision integer type with support for addition and multiplication.
* `Long::factorial`: factorial calculator.
* `Long::pow`: exponentiation calculator.
* `SieveOfAtkin`: fast prime-generating sieve.
[The sieve of Atkin is faster than the sieve of Eratosthenes.](https://github.com/tfpf/sieve-of-atkin)
* `SieveOfAtkin::is_prime`: prime checker for numbers the sieve is generated up to.
* `SieveOfAtkin::iter`: iterator over generated primes.
* `Polygonal`: figurate (triangle, quadrilateral, pentagon, hexagon, …) number generator. Uses only additions and
subtractions.
* `Polygonal::invert`: figurate number checker.
* `PythagoreanTriplets`: Pythagorean triplets generator.

<p align="center">
<img src="res/certified_human.svg" />
Expand Down Expand Up @@ -83,6 +97,7 @@ such as (but not limited to) Bard and ChatGPT.
|[48](https://projecteuler.net/problem=48)|[`self_powers.rs`](src/solutions/self_powers.rs)|
|[49](https://projecteuler.net/problem=49)|[`prime_permutations.rs`](src/solutions/prime_permutations.rs)|
|[50](https://projecteuler.net/problem=50)|[`consecutive_prime_sum.rs`](src/solutions/consecutive_prime_sum.rs)|
|[51](https://projecteuler.net/problem=51)|[`prime_digit_replacements.rs`](src/solutions/prime_digit_replacements.rs)|
|[52](https://projecteuler.net/problem=52)|[`permuted_multiples.rs`](src/solutions/permuted_multiples.rs)|
|[53](https://projecteuler.net/problem=53)|[`combinatoric_selections.rs`](src/solutions/combinatoric_selections.rs)|
|[54](https://projecteuler.net/problem=54)|[`poker_hands.rs`](src/solutions/poker_hands.rs)|
Expand All @@ -91,13 +106,26 @@ such as (but not limited to) Bard and ChatGPT.
|[57](https://projecteuler.net/problem=57)|[`square_root_convergents.rs`](src/solutions/square_root_convergents.rs)|
|[58](https://projecteuler.net/problem=58)|[`spiral_primes.rs`](src/solutions/spiral_primes.rs)|
|[59](https://projecteuler.net/problem=59)|[`xor_decryption.rs`](src/solutions/xor_decryption.rs)|
|[61](https://projecteuler.net/problem=61)|[`cyclical_figurate_numbers.rs`](src/solutions/cyclical_figurate_numbers.rs)|
|[62](https://projecteuler.net/problem=62)|[`cubic_permutations.rs`](src/solutions/cubic_permutations.rs)|
|[63](https://projecteuler.net/problem=63)|[`powerful_digit_counts.rs`](src/solutions/powerful_digit_counts.rs)|
|[64](https://projecteuler.net/problem=64)|[`odd_period_square_roots.rs`](src/solutions/odd_period_square_roots.rs)|
|[65](https://projecteuler.net/problem=65)|[`convergents_of_e.rs`](src/solutions/convergents_of_e.rs)|
|[66](https://projecteuler.net/problem=66)|[`diophantine_equation.rs`](src/solutions/diophantine_equation.rs)|
|[67](https://projecteuler.net/problem=67)|[`maximum_path_sum_ii.rs`](src/solutions/maximum_path_sum_ii.rs)|
|[68](https://projecteuler.net/problem=68)|[`magic_5_gon_ring.rs`](src/solutions/magic_5_gon_ring.rs)|
|[69](https://projecteuler.net/problem=69)|[`totient_maximum.rs`](src/solutions/totient_maximum.rs)|
|[71](https://projecteuler.net/problem=71)|[`ordered_fractions.rs`](src/solutions/ordered_fractions.rs)|
|[72](https://projecteuler.net/problem=72)|[`counting_fractions.rs`](src/solutions/counting_fractions.rs)|
|[74](https://projecteuler.net/problem=74)|[`digit_factorial_chains.rs`](src/solutions/digit_factorial_chains.rs)|
|[75](https://projecteuler.net/problem=75)|[`singular_integer_right_triangles.rs`](src/solutions/singular_integer_right_triangles.rs)|
|[76](https://projecteuler.net/problem=76)|[`counting_summations.rs`](src/solutions/counting_summations.rs)|
|[77](https://projecteuler.net/problem=77)|[`prime_summations.rs`](src/solutions/prime_summations.rs)|
|[78](https://projecteuler.net/problem=78)|[`coin_partitions.rs`](src/solutions/coin_partitions.rs)|
|[81](https://projecteuler.net/problem=81)|[`path_sum_two_ways.rs`](src/solutions/path_sum_two_ways.rs)|
|[82](https://projecteuler.net/problem=82)|[`path_sum_three_ways.rs`](src/solutions/path_sum_three_ways.rs)|
|[85](https://projecteuler.net/problem=85)|[`counting_rectangles.rs`](src/solutions/counting_rectangles.rs)|
|[87](https://projecteuler.net/problem=87)|[`prime_power_triples.rs`](src/solutions/prime_power_triples.rs)|
|[92](https://projecteuler.net/problem=92)|[`square_digit_chains.rs`](src/solutions/square_digit_chains.rs)|
|[97](https://projecteuler.net/problem=97)|[`large_non_mersenne_prime.rs`](src/solutions/large_non_mersenne_prime.rs)|
|[99](https://projecteuler.net/problem=99)|[`largest_exponential.rs`](src/solutions/largest_exponential.rs)|
50 changes: 0 additions & 50 deletions add_problem.py

This file was deleted.

16 changes: 16 additions & 0 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use project_euler::utils;

pub fn is_prime(c: &mut criterion::Criterion) {
c.bench_function("is_prime", |b| {
b.iter(|| (0..10i64.pow(5)).map(utils::is_prime).count())
});
}

pub fn sieve_of_atkin(c: &mut criterion::Criterion) {
c.bench_function("sieve_of_atkin", |b| {
b.iter(|| utils::SieveOfAtkin::new(10usize.pow(6)))
});
}

criterion::criterion_group!(benches, is_prime, sieve_of_atkin);
criterion::criterion_main!(benches);
Loading

0 comments on commit f81198a

Please sign in to comment.