Skip to content

Commit

Permalink
Removed '->' from the return description of all functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tfpf committed Jun 2, 2024
1 parent cfcbda2 commit 73d42af
Show file tree
Hide file tree
Showing 25 changed files with 32 additions and 71 deletions.
4 changes: 1 addition & 3 deletions src/solutions/amicable_numbers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::utils;

/// Implement the `d` function.
/// Calculate the sum of the proper divisors of the given number.
///
/// * `num`
///
/// -> Sum of proper divisors of `num`.
fn sum_of_proper_divisors(num: usize) -> usize {
let divisors = utils::Divisors::new(num as i64);
(divisors.sum::<i64>() - num as i64) as usize
Expand Down
2 changes: 0 additions & 2 deletions src/solutions/champernownes_constant.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// Determine the digit at the given index in Champernowne's Constant.
///
/// * `idx` 1-based index.
///
/// -> Digit at said index.
fn digit_at(idx: u32) -> u32 {
// Obtain a 0-based index.
let mut idx = idx - 1;
Expand Down
6 changes: 2 additions & 4 deletions src/solutions/circular_primes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ use crate::utils;

/// Check whether the given number is a circular prime number.
///
/// * `num` Prime number.
/// * `sieve` Sieve of eratosthenes.
///
/// -> Whether the number is a circular prime.
/// * `num`
/// * `sieve` Sieve of Atkin.
fn is_circular_prime(mut num: i64, sieve: &utils::SieveOfAtkin) -> bool {
// Since the number is prime, only its rotations have to be checked.
let passes = utils::Digits::new(num).count() - 1;
Expand Down
2 changes: 0 additions & 2 deletions src/solutions/coin_partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use crate::utils;
/// positive integers is divisible by 1000000. Essentially, implement the
/// partition function (of number theory) for every number (storing values
/// modulo 1000000) until we find the answer.
///
/// -> Smallest number whose partition is divisible by 1000000.
pub fn coin_partitions() -> usize {
let mut p = vec![0; 100000];
p[0] = 1;
Expand Down
4 changes: 1 addition & 3 deletions src/solutions/convergents_of_e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::utils;
///
/// * `idx_max` Index of the convergent.
///
/// -> Value of the convergent; 0 if the index is non-positive.
/// Returns 0 if `idx_max` is 0. Returns the convergent otherwise.
fn generate_continued_fraction(idx_max: u32) -> utils::Fraction {
match idx_max {
..=0 => utils::Fraction::from(0, 1),
Expand All @@ -18,8 +18,6 @@ fn generate_continued_fraction(idx_max: u32) -> utils::Fraction {
///
/// * `idx` Current index.
/// * `idx_max` Index of the convergent.
///
/// -> Value of the convergent.
fn generate_continued_fraction_(idx: u32, idx_max: u32) -> utils::Fraction {
let addend = if idx % 3 == 0 { idx / 3 * 2 } else { 1 };
let mut fraction = if idx == idx_max {
Expand Down
6 changes: 2 additions & 4 deletions src/solutions/counting_sundays.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// Check for leap years.
/// Check whether the given year is a leap year.
///
/// * `year`
///
/// -> Whether the input is a leap year.
fn is_leap(year: i64) -> bool {
year % 4 == 0 && year % 100 != 0 || year % 400 == 0
}
Expand All @@ -12,7 +10,7 @@ fn is_leap(year: i64) -> bool {
/// * `year`
/// * `month` Number from 1 to 12.
///
/// -> Number of days, or 0 if the month is invalid.
/// Returns 0 if the month is invalid. Returns the number of days otherwise.
fn days_in(year: i64, month: i64) -> i64 {
match month {
1 | 3 | 5 | 7 | 8 | 10 | 12 => 31,
Expand Down
2 changes: 1 addition & 1 deletion src/solutions/cyclical_figurate_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::utils;
/// * `mask` Bitfield indicating the families we have not yet produced.
/// * `cyclical` Cyclical figurate numbers we have produced so far.
///
/// -> Whether the 6 numbers were produced.
/// Returns `true` if the 6 numbers were produced. Returns `false` otherwise.
fn generate_cyclical(numbitfield: &Vec<(i64, u8)>, mask: u8, cyclical: &mut Vec<i64>) -> bool {
// If numbers of all families have been produced, check the first and last
// numbers for the cyclic property.
Expand Down
4 changes: 1 addition & 3 deletions src/solutions/distinct_powers.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::utils;

/// Find the greatest exponent a number can be raised to so that the resultant
/// value is equal to given number. For instance, given 32, this function
/// value is equal to the given number. For instance, given 32, this function
/// should return 5, and given 36, it should return 2.
///
/// * `num`
/// * `primes` Prime numbers to use to calculate the exponent.
///
/// -> Exponent.
fn exponent(mut num: i64, primes: &[i64]) -> i64 {
// Calculate the greatest exponent of every prime in the given number.
let mut exponents = vec![0i64; primes.len()];
Expand Down
2 changes: 1 addition & 1 deletion src/solutions/distinct_primes_factors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::utils;

/// Find four consecutive integers which have at least four prime factors each.
///
/// -> First of the four integers.
/// Returns the first of the four integers.
fn four_distinct() -> i64 {
let primes = utils::SieveOfAtkin::new(1000).iter().collect::<Vec<i64>>();
let mut num = 644;
Expand Down
2 changes: 1 addition & 1 deletion src/solutions/double_base_palindromes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::utils;
///
/// * `num` Number to use to generate palindromes.
///
/// -> Sum of all double-base palindromes with binary `num` as their left half.
/// Returns the sum of all double-base palindromes with `num` as the left half.
fn double_base_palindrome_sum(num: i64) -> i64 {
// There are three ways to make a palindrome using this number. Having
// reversed its bits, one can: stick the reversed bits to its right, append
Expand Down
5 changes: 2 additions & 3 deletions src/solutions/largest_product_in_a_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::io::BufRead;
/// * `idx` Starting index.
/// * `delta` Step to increment the index by.
///
/// -> Vector of indices. Empty if `delta` is not one of [-1, 0, 1].
/// Returns an empty vector if `delta` is not one of [-1, 0, 1]. Returns a
/// vector of indices otherwise.
fn create_vector(idx: usize, delta: isize) -> Vec<usize> {
if delta == 1 {
(idx..20).collect::<Vec<usize>>()
Expand All @@ -28,8 +29,6 @@ fn create_vector(idx: usize, delta: isize) -> Vec<usize> {
/// * `outer_dy` How much to step the column index by in the outer loop.
/// * `inner_dx` How much to step the row index by in the inner loop.
/// * `inner_dy` How much to step the column index by in the inner loop.
///
/// -> Largest product.
fn find_largest(
grid: &[Vec<i32>],
x: usize,
Expand Down
9 changes: 2 additions & 7 deletions src/solutions/lexicographic_permutations.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
/// Find the digit which causes us to stay within 1_000_000 permutations.
///
/// * `digits` Pool of available digits.
/// * `count` Number of permutations we have already seen. Will get updated
/// to the number of permutations we have seen after the required digit is
/// found.
/// * `step` Number of permutations we will see if we pick a digit from
/// `digits`.
///
/// -> The correct digit of the 1_000_000th permutation.
/// * `count` Number of permutations we have already seen.
/// * `step` Number of permutations we will see if we pick from `digits`.
fn overshoot(digits: &[i32], count: &mut i32, step: i32) -> i32 {
for (&prev, &_) in digits.iter().zip(digits.iter().skip(1)) {
// If I set the digit `_`, how many permutations will I have seen
Expand Down
2 changes: 0 additions & 2 deletions src/solutions/longest_collatz_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
///
/// * `collatz_lengths` Array to cache the lengths. Indexable with `num`.
/// * `num` Number to find the length of the Collatz sequence for.
///
/// -> Length of Collatz sequence.
fn get_collatz_length(collatz_lengths: &mut Vec<i32>, num: usize) -> i32 {
if collatz_lengths[num] != 0 {
return collatz_lengths[num];
Expand Down
2 changes: 0 additions & 2 deletions src/solutions/number_letter_counts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// Convert a number into a string which indicates how it would be read.
///
/// * `num`
///
/// -> String representing how `num` would be read.
fn convert(num: usize) -> String {
// Handle numbers without any discernible pattern in their names.
let result = match num {
Expand Down
2 changes: 0 additions & 2 deletions src/solutions/pentagon_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::utils;

/// Find the smallest difference between two pentagonal numbers which is a
/// pentagonal number, while their sum is also a pentagonal number.
///
/// -> Smallest pentagonal difference.
fn minimum_pentagonal_difference() -> i64 {
let pentagons = utils::Polygonal::new(5).take(3000).collect::<Vec<i64>>();
for i in 1..pentagons.len() {
Expand Down
2 changes: 1 addition & 1 deletion src/solutions/prime_digit_replacements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::utils;
/// The number of fixed positions must be 3, 6 or 9. Otherwise, at least one
/// of the 8 numbers in the family will be divisible by 3.
///
/// -> Smallest member of the family.
/// Returns the smallest member of the family.
fn prime_digit_replacements() -> i64 {
const LIMIT: usize = 1000000;
let sieve = utils::SieveOfAtkin::new(LIMIT);
Expand Down
2 changes: 0 additions & 2 deletions src/solutions/prime_permutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::utils;

/// Find three prime numbers which are in arithmetic progression and consist of
/// the same digits.
///
/// -> Tuple of prime numbers.
fn prime_permutations() -> (i64, i64, i64) {
let sieve = utils::SieveOfAtkin::new(9999);
let primes = sieve.iter().skip_while(|&prime| prime < 1000).collect::<Vec<i64>>();
Expand Down
2 changes: 0 additions & 2 deletions src/solutions/reciprocal_cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use crate::utils;
/// reciprocal of a prime number.
///
/// * `prime` Prime number.
///
/// -> Recurrence cycle length.
fn recurrence_length(prime: i64) -> i64 {
// The digits (i.e. the sequence of quotients) will start repeating when
// the remainder becomes 1 for the second time.
Expand Down
6 changes: 4 additions & 2 deletions src/solutions/square_digit_chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::utils;
/// if we know the answer for those numbers, we can know the answer for any
/// number by taking the sum of the squares of its digits.
///
/// -> Array showing where the chain gets stuck in a loop.
/// Returns an array containing numbers at which chains starting at their
/// indices get stuck.
fn minimal_stuck() -> [u8; 568] {
let mut chain_stuck = [0u8; 568];
chain_stuck[1] = 1;
Expand All @@ -32,7 +33,8 @@ fn minimal_stuck() -> [u8; 568] {
/// * `digits` Digits of the number, ordered from most to least significant.
/// * `sqsum` Sum of the squares of the digits.
///
/// -> How many with these digits have digit square sum chains ending at 89.
/// Returns the count of numbers with these digits having digit square sum
/// chains ending at 89.
fn generate_ascending(chain_stuck: &[u8; 568], digits: &mut Vec<usize>, sqsum: usize) -> i32 {
const FACTORIAL: [i32; 10] = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880];

Expand Down
2 changes: 1 addition & 1 deletion src/solutions/sub_string_divisibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl DigitsSet {
/// * `value` Partially-built sub-string divisible number.
/// * `primes` Prime numbers, but offset for use with the index.
///
/// -> Sum of all numbers which can be built starting from the given resources.
/// Returns the sum of all numbers which can be built with the above resources.
fn sub_string_divisible_sum(ds: &mut DigitsSet, idx: usize, value: i64, primes: &[i64; 10]) -> i64 {
if idx >= 10 {
return value;
Expand Down
14 changes: 6 additions & 8 deletions src/solutions/truncatable_primes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::utils;
/// Check whether the number is a left-truncatable prime number.
///
/// * `digits` Digits of the number (in big-endian order) to check.
///
/// -> Whether the number is a left-truncatable prime.
fn left_truncatable(digits: &[i32]) -> bool {
// Instead of chopping off digits from the left, prepend digits to the
// left. This avoids division.
Expand All @@ -26,7 +24,7 @@ fn left_truncatable(digits: &[i32]) -> bool {
/// * `value` The partially-built number represented by `digits`.
/// * `idx` Index of the next digit to build.
///
/// -> Sum of all truncatable primes numbers having `value` as a prefix.
/// Returns the sum of all truncatable primes numbers having prefix `value`.
fn truncatable_sum(digits: &mut Vec<i32>, value: i32, idx: usize) -> i32 {
let available_digits = [1, 2, 3, 5, 7, 9];

Expand All @@ -39,8 +37,8 @@ fn truncatable_sum(digits: &mut Vec<i32>, value: i32, idx: usize) -> i32 {
let last = digits.len() - 1;
let sum = available_digits
.map(|digit| {
// The most significant digit must be 2, 3, 5 or 7. No other digit can
// be 2 or 5.
// The most significant digit must be 2, 3, 5 or 7. No other digit
// can be 2 or 5.
if idx == 0 && (digit == 1 || digit == 9) || idx != 0 && (digit == 2 || digit == 5) {
return 0;
}
Expand All @@ -51,9 +49,9 @@ fn truncatable_sum(digits: &mut Vec<i32>, value: i32, idx: usize) -> i32 {
return 0;
}

// The least significant digit must be 3 or 7. Hence, if we find either
// of those, check whether we have found a truncatable prime and then
// continue the search for more truncatable primes.
// The least significant digit must be 3 or 7. Hence, if we find
// either of those, check whether we have found a truncatable prime
// and then continue the search for more truncatable primes.
if (digit == 3 || digit == 7) && left_truncatable(digits) {
// Single-digit numbers do not count.
if idx == 0 {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/iterators/polygonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ impl Polygonal {
}
}
/// Find the index at which the given number would appear in a sequence of
/// polygonal numbers (if it is a polygonal number).
/// polygonal numbers.
///
/// * `sides` Number of sides of the polygon the sequence is based on.
/// * `num` Number whose index is to be found.
///
/// -> Index.
/// Returns the index of the number if it is a polygonal number of the
/// specified type. Returns the index of the nearest polygonal number of
/// that type otherwise.
pub fn invert(sides: i64, num: i64) -> Result<i64, i64> {
// A polygonal number is a quadratic function of the index it appears
// at. Solve for the positive root of the corresponding quadratic
Expand Down
8 changes: 0 additions & 8 deletions src/utils/objects/long.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ impl Long {
/// decimal digits.
///
/// * `s`
///
/// -> Arbitrary-precision integer.
pub fn new(s: &str) -> Long {
let mut long = Long { digits: vec![] };
let mut idx = s.len();
Expand Down Expand Up @@ -67,8 +65,6 @@ impl Long {
result
}
/// Obtain the number of decimal digits of this number (i.e. its length).
///
/// -> Length.
pub fn len(&self) -> usize {
match self.digits.len() {
0 => 0,
Expand All @@ -77,8 +73,6 @@ impl Long {
}
}
/// Calculate the sum of all decimal digits of this number.
///
/// -> Sum.
pub fn sum(&self) -> i64 {
self.digits
.iter()
Expand All @@ -88,8 +82,6 @@ impl Long {
/// Raise this number to the given power.
///
/// * `exp` Power.
///
/// -> Value of this number raised to the given power.
pub fn pow(&self, mut exp: u32) -> Long {
// Multiplication is expensive, so these checks will improve
// performance.
Expand Down
5 changes: 2 additions & 3 deletions src/utils/objects/pandigital_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ impl PandigitalChecker {
///
/// * `num` Number to update with.
///
/// -> Whether all digits of the number were in range and not seen earlier.
/// Returns `true` of all digits of the number were in range and not seen
/// earlier. Returns `false` otherwise.
pub fn update(&mut self, num: i64) -> bool {
for digit in utils::Digits::new(num) {
let digit = digit as usize;
Expand All @@ -35,8 +36,6 @@ impl PandigitalChecker {
}
/// Check whether all digits in the range have been seen. This indicates
/// pandigitality only if used in tandem with the above method.
///
/// -> Pandigitality.
pub fn check(&self) -> bool {
self.seen
.iter()
Expand Down
2 changes: 0 additions & 2 deletions src/utils/objects/sieve_of_atkin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ impl SieveOfAtkin {
/// Construct the sieve of Atkin up to and including the given number.
///
/// * `limit` Non-strict upper bound.
///
/// -> Sieve of Atkin.
pub fn new(limit: usize) -> SieveOfAtkin {
// Strict upper bound divisible by 60.
let limit_rounded = (limit - limit % 60)
Expand Down

0 comments on commit 73d42af

Please sign in to comment.