Repository navigation
Add approaches (Dig Deeper) for sieve - #1024
Merged
Merged
Conversation
Three approaches: a mutable Array of marks, an immutable Set with foldLeft, and an endless LazyList of primes. The introduction explains why the well-known filter-based solution is trial division. Closes #988 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Hello 👋 Thanks for your PR. This repo does not currently have dedicated maintainers. Our cross-track maintainers team will attempt to review and merge your PR, but it will likely take longer for your PR to be reviewed. If you enjoy contributing to Exercism and have a track-record of doing so successfully, you might like to become an Exercism maintainer for this track. Please feel free to ask any questions, or chat to us about anything to do with this PR or the reviewing process on the Exercism forum. (cc @exercism/cross-track-maintainers) |
rabestro
marked this pull request as draft
November 14, 2026 22:03
rabestro
marked this pull request as ready for review
November 22, 2026 16:32
IsaacG
approved these changes
Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #988
sieve's "Dig Deeper" tab is empty on the Scala track. This adds an introduction and three approaches:
mutable-arrayArray[Boolean]of marks, aforwith two generators and a guard, multiples fromn * nwithby n(based on the current example, with a guard against array-size overflow)immutable-setfoldLeftover the numbers up to the square root of the limit,numbers -- (n * n to limit by n)lazylistLazyListthat generates primes on demand, taken while<= limitThe issue asks to refresh the exercise first. That is already done on
main: the suite is generated and the example is Scala 3 with anArray, so this PR only adds.approaches/.Notes:
lazylistis a genuine incremental sieve. AMapholds, for each prime, only its next multiple, and the mark is moved on by addition when the sieve gets there. The text walks through the numbers up to 10.lazylistcounts inLong: the square of a prime above 46340 does not fit in anInt, and the list has no limit that would keep the primes below that.filter(_ % head != 0)): why it is trial division, with a link to Melissa O'Neill's paper. It says plainly that this solution passes the tests.Checks
.scalafmt.conf.https://www.scala-lang.org/api/current/..., and every external link resolves.bin/configlet lintpasses.🤖 Generated with Claude Code