Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exercises(sum-of-multiples): implement #268

Merged
merged 16 commits into from
Sep 4, 2023

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Mar 24, 2023

This is one of the first exercises for which a user can reasonably use a HashMap (as a set of integers). Put this exercise towards the end.

A u64 is sufficient for the maximum value of the sum of multiples when the limit is a u32. The maximum sum of multiples occurs for

const factors = [_]u32{1};
const limit = 4_294_967_295 // the maximum value of a u32

and the sum of integers from 1 (inclusive) to n (exclusive) is

n(n - 1) / 2

which is always less than n^2. So the sum from 1 to an integer less than 2^32 is always less than 2^64.


To-do:

  • configlet sync --docs Edit: Don't do this for now.
  • Test sum that is larger than maximum value of a u32
  • config.json: decide on exercise ordering after merging other exercises
  • Final nits

@ee7 ee7 requested a review from ErikSchierboom March 24, 2023 15:09
@ee7 ee7 self-assigned this Mar 28, 2023
ee7 added 7 commits September 3, 2023 11:29
A u64 is sufficient for the maximum value of the sum when the limit is a
u32. The maximum sum occurs for

    const factors = [_]u32{1};
    const limit = 4_294_967_295 // the maximum value of a u32

and resulting sum of the integers from 1 to 4_294_967_295 is:

     9_223_372_034_707_292_160

which is less than the maximum value of a u64:

    18_446_744_073_709_551_615
@ee7 ee7 merged commit 074fe8e into exercism:main Sep 4, 2023
@ee7 ee7 deleted the implement-sum-of-multiples branch September 4, 2023 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants