Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

My solutions to some Project Euler problems. Emphasis on elegance (where possible) and performance.

License

NotificationsYou must be signed in to change notification settings

tfpf/project-euler

Repository files navigation

Trying my hand atProject Euler as I stumble along learning Rust. I shall only add thesolutions to the first hundred problems here with the intention being to showcase whatever useful data structures Ibuild along the way. (This is permitted according to the Project Euler guidelines.) Further, I shall restrict myself tothe standard library.

stylelintsanitytests

To solve, say, problem 16, enter the following command.

cargo r 16

Run it without arguments to sequentially solve all problems for which I have written solutions.

cargo r

Most solutions are rather concise; the heavy lifting is done in theutils module. This highlights the intent of thecode 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 thepow 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.
    • 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 andsubtractions.
    • Polygonal::invert: figurate number checker.
  • PythagoreanTriplets: Pythagorean triplets generator.

No part of the code in this repository has been written by or in consultation with artificial intelligence chatbotssuch as (but not limited to) Bard and ChatGPT.

Problems and Solutions

ProblemSolution
1multiples_of_3_or_5.rs
2even_fibonacci_numbers.rs
3largest_prime_factor.rs
4largest_palindrome_product.rs
5smallest_multiple.rs
6sum_square_difference.rs
7ten_thousand_and_first_prime.rs
8largest_product_in_a_series.rs
9special_pythagorean_triplet.rs
10summation_of_primes.rs
11largest_product_in_a_grid.rs
12highly_divisible_triangular_number.rs
13large_sum.rs
14longest_collatz_sequence.rs
15lattice_paths.rs
16power_digit_sum.rs
17number_letter_counts.rs
18maximum_path_sum_i.rs
19counting_sundays.rs
20factorial_digit_sum.rs
21amicable_numbers.rs
22names_scores.rs
23non_abundant_sums.rs
24lexicographic_permutations.rs
25thousand_digit_fibonacci_number.rs
26reciprocal_cycles.rs
27quadratic_primes.rs
28number_spiral_diagonals.rs
29distinct_powers.rs
30digit_fifth_powers.rs
31coin_sums.rs
32pandigital_products.rs
33digit_cancelling_fractions.rs
34digit_factorials.rs
35circular_primes.rs
36double_base_palindromes.rs
37truncatable_primes.rs
38pandigital_multiples.rs
39integer_right_triangles.rs
40champernownes_constant.rs
41pandigital_prime.rs
42coded_triangle_numbers.rs
43sub_string_divisibility.rs
44pentagon_numbers.rs
45triangular_pentagonal_and_hexagonal.rs
46goldbachs_other_conjecture.rs
47distinct_primes_factors.rs
48self_powers.rs
49prime_permutations.rs
50consecutive_prime_sum.rs
51prime_digit_replacements.rs
52permuted_multiples.rs
53combinatoric_selections.rs
54poker_hands.rs
55lychrel_numbers.rs
56powerful_digit_sum.rs
57square_root_convergents.rs
58spiral_primes.rs
59xor_decryption.rs
61cyclical_figurate_numbers.rs
62cubic_permutations.rs
63powerful_digit_counts.rs
64odd_period_square_roots.rs
65convergents_of_e.rs
66diophantine_equation.rs
67maximum_path_sum_ii.rs
68magic_5_gon_ring.rs
69totient_maximum.rs
71ordered_fractions.rs
72counting_fractions.rs
74digit_factorial_chains.rs
75singular_integer_right_triangles.rs
76counting_summations.rs
77prime_summations.rs
78coin_partitions.rs
81path_sum_two_ways.rs
85counting_rectangles.rs
87prime_power_triples.rs
92square_digit_chains.rs
97large_non_mersenne_prime.rs
99largest_exponential.rs

About

My solutions to some Project Euler problems. Emphasis on elegance (where possible) and performance.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp