diff --git a/config.json b/config.json index 1ec192932..2cd8bf648 100644 --- a/config.json +++ b/config.json @@ -463,7 +463,6 @@ "slug": "resistor-color", "name": "Resistor Color", "uuid": "6bc57e73-1629-4a18-b2f0-0b93ef4f3b8c", - "difficulty": 1, "practices": [ "custom-types" ], @@ -471,25 +470,25 @@ "custom-types", "case-expressions", "lists" - ] + ], + "difficulty": 1 }, { "slug": "difference-of-squares", "name": "Difference Of Squares", "uuid": "ce45a52e-0541-4384-8abf-b787bd49cbf7", - "difficulty": 1, "practices": [ "ints" ], "prerequisites": [ "ints" - ] + ], + "difficulty": 1 }, { "slug": "two-fer", "name": "Two Fer", "uuid": "b0a6f0d2-0bba-4f8f-89ad-a41995a4b87d", - "difficulty": 1, "practices": [ "strings", "options" @@ -497,13 +496,13 @@ "prerequisites": [ "strings", "options" - ] + ], + "difficulty": 1 }, { "slug": "bob", "name": "Bob", "uuid": "c9f7d06c-a2fb-45c3-a320-b9a93fd88201", - "difficulty": 3, "practices": [ "strings" ], @@ -511,25 +510,25 @@ "case-expressions", "strings", "bools" - ] + ], + "difficulty": 3 }, { "slug": "leap", "name": "Leap", "uuid": "5f8fa8fe-3775-4b34-a602-d5cb47d83d8c", - "difficulty": 2, "practices": [ "ints" ], "prerequisites": [ "ints" - ] + ], + "difficulty": 2 }, { "slug": "accumulate", "name": "Accumulate", "uuid": "d04cd9d6-6494-4336-8e6c-2b9f612eba05", - "difficulty": 2, "practices": [ "lists", "recursion" @@ -539,13 +538,13 @@ "recursion", "case-expressions", "generics" - ] + ], + "difficulty": 2 }, { "slug": "pascals-triangle", "name": "Pascals Triangle", "uuid": "b6459bf2-1e93-42ea-a743-628548b79e2f", - "difficulty": 4, "practices": [ "lists" ], @@ -553,15 +552,14 @@ "lists", "results", "tuples" - ] + ], + "difficulty": 4 }, { "slug": "forth", "name": "Forth", "uuid": "8176ac78-d4fd-475f-ac8b-e205ca7b3a77", - "difficulty": 9, - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "strings", @@ -570,13 +568,13 @@ "lists", "case-expressions", "custom-types" - ] + ], + "difficulty": 9 }, { "slug": "bowling", "name": "Bowling", "uuid": "1d54b9d2-bf6f-473f-8bf6-668d3c0fd5f3", - "difficulty": 6, "practices": [ "lists", "custom-types" @@ -588,35 +586,35 @@ "lists", "ints", "results" - ] + ], + "difficulty": 6 }, { "slug": "freelancer-rates", "name": "Freelancer Rates", "uuid": "fee79e03-1496-476f-964f-e60632cb13dc", - "difficulty": 4, "practices": [], "prerequisites": [], + "difficulty": 4, "status": "deprecated" }, { "slug": "anagram", "name": "Anagram", "uuid": "093aa488-077f-4180-9d8c-59d0ad8837da", - "difficulty": 3, "practices": [ "lists" ], "prerequisites": [ "strings", "lists" - ] + ], + "difficulty": 3 }, { "slug": "pangram", "name": "Pangram", "uuid": "a70503ba-f1f3-4583-9226-c3ada98e9500", - "difficulty": 2, "practices": [ "sets", "strings" @@ -625,13 +623,13 @@ "sets", "bools", "strings" - ] + ], + "difficulty": 2 }, { "slug": "roman-numerals", "name": "Roman Numerals", "uuid": "de777d9f-7963-4a1f-a923-9fa0aad4eac8", - "difficulty": 3, "practices": [ "strings", "ints" @@ -639,14 +637,14 @@ "prerequisites": [ "strings", "ints" - ] + ], + "difficulty": 3 }, { "slug": "protein-translation", "name": "Protein Translation", "uuid": "612395a5-238e-4be0-8ce0-4ac66f57056e", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "lists", @@ -658,7 +656,6 @@ "slug": "dominoes", "name": "Dominoes", "uuid": "b59b630e-8648-4498-b8d8-fcfaf261ece3", - "difficulty": 7, "practices": [ "queues" ], @@ -667,7 +664,8 @@ "lists", "queues", "tuples" - ] + ], + "difficulty": 7 }, { "slug": "rna-transcription", @@ -1012,8 +1010,7 @@ "slug": "alphametics", "name": "Alphametics", "uuid": "5aef7d9d-3939-4014-8102-a7262fdde754", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "sets", @@ -1062,8 +1059,7 @@ "slug": "acronym", "name": "Acronym", "uuid": "21946b94-c304-4a10-a6b6-b9fd5bbe9966", - "practices": [ - ], + "practices": [], "prerequisites": [ "labelled-arguments", "regular-expressions", @@ -1204,8 +1200,7 @@ "slug": "prime-factors", "name": "Prime Factors", "uuid": "00d1a428-99c4-4175-bee2-e05fc034528f", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "lists", @@ -1218,8 +1213,7 @@ "slug": "run-length-encoding", "name": "Run-Length Encoding", "uuid": "22298714-cc36-49b7-8e70-cfb91ff42112", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "strings", @@ -1233,8 +1227,7 @@ "slug": "grains", "name": "Grains", "uuid": "b5b9be18-9141-4176-8f8c-3dd14d14bed5", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "case-expressions", @@ -1247,8 +1240,7 @@ "slug": "nucleotide-count", "name": "Nucleotide Count", "uuid": "3b7e1bbf-08b2-4e0e-ba5d-5a887deb4817", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "results", @@ -1262,8 +1254,7 @@ "slug": "hamming", "name": "Hamming", "uuid": "64a40995-c380-4233-a7af-98498dbc5c2d", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "strings", @@ -1277,8 +1268,7 @@ "slug": "proverb", "name": "Proverb", "uuid": "d2288ce0-3ef4-4a79-8e21-bf5624b5ab27", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "strings", @@ -1290,8 +1280,7 @@ "slug": "high-scores", "name": "High Scores", "uuid": "af720091-1352-4e07-96d2-0868588601f2", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "ints", @@ -1303,8 +1292,7 @@ "slug": "allergies", "name": "Allergies", "uuid": "f829a1af-0eaf-4880-b1d8-cd2cb3753fb0", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "lists", @@ -1317,22 +1305,20 @@ "slug": "twelve-days", "name": "Twelve Days", "uuid": "583b74dc-2c5c-48f8-85c2-c90623507682", - "difficulty": 3, - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "lists", "labelled-arguments", "ints" - ] + ], + "difficulty": 3 }, { "slug": "etl", "name": "ETL", "uuid": "1655d9f6-6199-4462-85bd-a5da5f25d30a", - "practices": [ - ], + "practices": [], "prerequisites": [ "maps", "lists", @@ -1345,8 +1331,7 @@ "slug": "queen-attack", "name": "Queen Attack", "uuid": "9caa195e-2273-4096-9aee-26ab5658e7f7", - "practices": [ - ], + "practices": [], "prerequisites": [ "custom-types", "case-expressions", @@ -1359,8 +1344,7 @@ "slug": "sublist", "name": "Sublist", "uuid": "6d4933cc-0845-4992-93ee-54f79a79fc5a", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "case-expressions", @@ -1374,8 +1358,7 @@ "slug": "rotational-cipher", "name": "Rotational Cipher", "uuid": "2e7fdb4d-3e75-4dc2-9fb7-ee1a9e1950f9", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "ints", @@ -1387,8 +1370,7 @@ "slug": "change", "name": "Change", "uuid": "8dc8aceb-fe74-415c-bf4b-956840155272", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "results", @@ -1401,8 +1383,7 @@ "slug": "flatten-array", "name": "Flatten Array", "uuid": "efdf70a3-57e6-474a-9fc2-09f26bb609b6", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "custom-types", @@ -1415,8 +1396,7 @@ "slug": "all-your-base", "name": "All Your Base", "uuid": "e9332e6f-a7e5-4f30-825c-64af0a278a70", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "lists", @@ -1430,8 +1410,7 @@ "slug": "knapsack", "name": "Knapsack", "uuid": "6e889724-656e-4f0c-aba1-08f103490e9d", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "custom-types", @@ -1460,8 +1439,7 @@ "slug": "dnd-character", "name": "D&D Character", "uuid": "65d80b55-02f0-4d40-a530-79843553252f", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "custom-types", @@ -1473,8 +1451,7 @@ "slug": "isbn-verifier", "name": "ISBN Verifier", "uuid": "d12ac283-8ca4-4b40-919a-9588e1e52d50", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "ints", @@ -1504,8 +1481,7 @@ "slug": "atbash-cipher", "name": "Atbash Cipher", "uuid": "3c850415-92fa-4019-b776-aaab30675680", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "lists", @@ -1518,8 +1494,7 @@ "slug": "square-root", "name": "Square Root", "uuid": "700f44e5-13a3-4e97-aad5-d383e25f9f9b", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "bools", @@ -1547,8 +1522,7 @@ "slug": "simple-cipher", "name": "Simple Cipher", "uuid": "37dd415b-1d67-434d-8705-19295d1438b8", - "practices": [ - ], + "practices": [], "prerequisites": [ "iterators", "strings", @@ -1562,8 +1536,7 @@ "slug": "crypto-square", "name": "Crypto Square", "uuid": "5bf01e81-b30a-4210-b1ed-1edbf3d28ab1", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "lists", @@ -1576,8 +1549,7 @@ "slug": "affine-cipher", "name": "Affine Cipher", "uuid": "594b6c1a-0a4c-4463-9535-62056c71404e", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "lists", @@ -1593,8 +1565,7 @@ "slug": "house", "name": "House", "uuid": "21421905-a33c-4040-9f09-78726b5d1167", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "lists", @@ -1607,8 +1578,7 @@ "slug": "connect", "name": "Connect", "uuid": "89c6bf7a-5cd8-4254-b3e0-1457a5390b46", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "maps", @@ -1624,8 +1594,7 @@ "slug": "clock", "name": "Clock", "uuid": "ad9cc1bd-d99b-4f43-941c-8e09b43801af", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "strings", @@ -1638,8 +1607,7 @@ "slug": "killer-sudoku-helper", "name": "Killer Sudoku Helper", "uuid": "4c6ed017-a02b-4826-a111-ef9733b7d315", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "ints", @@ -1651,8 +1619,7 @@ "slug": "luhn", "name": "Luhn", "uuid": "a66bbefd-db5a-44d0-ab4b-73d871756f08", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "lists", @@ -1667,8 +1634,7 @@ "slug": "wordy", "name": "Wordy", "uuid": "5031033b-bd21-4563-ae18-59ad02f4c489", - "practices": [ - ], + "practices": [], "prerequisites": [ "results", "strings", @@ -1684,8 +1650,7 @@ "slug": "largest-series-product", "name": "Largest Series Product", "uuid": "34293b12-1d94-43d9-a9cb-27b8bff92d67", - "practices": [ - ], + "practices": [], "prerequisites": [ "case-expressions", "ints", @@ -1698,8 +1663,7 @@ "slug": "minesweeper", "name": "Minesweeper", "uuid": "abbeeb8f-6ec1-4f57-86fc-2e18b3a62e29", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "lists", @@ -1713,8 +1677,7 @@ "slug": "say", "name": "Say", "uuid": "753fff04-5a64-4c3f-afd2-beee7e27efe8", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "case-expressions", @@ -1728,8 +1691,7 @@ "slug": "saddle-points", "name": "Saddle Points", "uuid": "e1103441-9391-4760-829b-1ec412762fab", - "practices": [ - ], + "practices": [], "prerequisites": [ "custom-types", "lists", @@ -1742,18 +1704,15 @@ "slug": "secret-handshake", "name": "Secret Handshake", "uuid": "22461f35-684d-4f75-9399-d07a4f483bdd", - "practices": [ - ], - "prerequisites": [ - ], + "practices": [], + "prerequisites": [], "difficulty": 2 }, { "slug": "matrix", "name": "Matrix", "uuid": "6fc59193-bc31-40af-902a-b13ad926bbb3", - "practices": [ - ], + "practices": [], "prerequisites": [ "lists", "strings", @@ -1766,8 +1725,7 @@ "slug": "grade-school", "name": "Grade School", "uuid": "836dddea-2a02-434f-a886-c8e1c429268f", - "practices": [ - ], + "practices": [], "prerequisites": [ "maps", "results", @@ -1783,8 +1741,7 @@ "slug": "variable-length-quantity", "name": "Variable Length Quantity", "uuid": "f7e33664-ea30-4885-8961-4aa984a1341d", - "practices": [ - ], + "practices": [], "prerequisites": [ "bit-strings", "case-expressions", @@ -1798,8 +1755,7 @@ "slug": "ocr-numbers", "name": "OCR Numbers", "uuid": "0ac6ba02-b2c0-4c81-8ca0-31c49a340e23", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "lists", @@ -1813,8 +1769,7 @@ "slug": "pig-latin", "name": "Pig Latin", "uuid": "dbc455de-1845-49f9-b5b5-082350e12811", - "practices": [ - ], + "practices": [], "prerequisites": [ "strings", "case-expressions", @@ -1826,8 +1781,7 @@ "slug": "nth-prime", "name": "Nth Prime", "uuid": "fda0001e-51b5-4041-a08a-2cb7dfef0f1c", - "practices": [ - ], + "practices": [], "prerequisites": [ "ints", "iterators", @@ -1865,6 +1819,14 @@ "ints" ], "difficulty": 2 + }, + { + "slug": "sieve", + "name": "Sieve", + "uuid": "146a0acd-cabf-431c-97a4-3c719903411f", + "practices": [], + "prerequisites": [], + "difficulty": 4 } ] }, @@ -2083,16 +2045,16 @@ } ], "tags": [ + "execution_mode/compiled", "paradigm/declarative", "paradigm/functional", - "typing/static", - "typing/strong", - "execution_mode/compiled", - "platform/windows", - "platform/mac", "platform/linux", + "platform/mac", "platform/web", + "platform/windows", "runtime/beam", + "typing/static", + "typing/strong", "used_for/backends", "used_for/frontends", "used_for/games", diff --git a/exercises/practice/sieve/.docs/instructions.md b/exercises/practice/sieve/.docs/instructions.md new file mode 100644 index 000000000..3adf1d551 --- /dev/null +++ b/exercises/practice/sieve/.docs/instructions.md @@ -0,0 +1,28 @@ +# Instructions + +Your task is to create a program that implements the Sieve of Eratosthenes algorithm to find prime numbers. + +A prime number is a number that is only divisible by 1 and itself. +For example, 2, 3, 5, 7, 11, and 13 are prime numbers. + +The Sieve of Eratosthenes is an ancient algorithm that works by taking a list of numbers and crossing out all the numbers that aren't prime. + +A number that is **not** prime is called a "composite number". + +To use the Sieve of Eratosthenes, you first create a list of all the numbers between 2 and your given number. +Then you repeat the following steps: + +1. Find the next unmarked number in your list. This is a prime number. +2. Mark all the multiples of that prime number as composite (not prime). + +You keep repeating these steps until you've gone through every number in your list. +At the end, all the unmarked numbers are prime. + +~~~~exercism/note +[Wikipedia's Sieve of Eratosthenes article][eratosthenes] has a useful graphic that explains the algorithm. + +The tests don't check that you've implemented the algorithm, only that you've come up with the correct list of primes. +A good first test is to check that you do not use division or remainder operations. + +[eratosthenes]: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes +~~~~ diff --git a/exercises/practice/sieve/.docs/introduction.md b/exercises/practice/sieve/.docs/introduction.md new file mode 100644 index 000000000..f6c1cf79a --- /dev/null +++ b/exercises/practice/sieve/.docs/introduction.md @@ -0,0 +1,7 @@ +# Introduction + +You bought a big box of random computer parts at a garage sale. +You've started putting the parts together to build custom computers. + +You want to test the performance of different combinations of parts, and decide to create your own benchmarking program to see how your computers compare. +You choose the famous "Sieve of Eratosthenes" algorithm, an ancient algorithm, but one that should push your computers to the limits. diff --git a/exercises/practice/sieve/.meta/config.json b/exercises/practice/sieve/.meta/config.json new file mode 100644 index 000000000..c42731076 --- /dev/null +++ b/exercises/practice/sieve/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "bcpeinhardt" + ], + "files": { + "solution": [ + "src/sieve.gleam" + ], + "test": [ + "test/sieve_test.gleam" + ], + "example": [ + ".meta/example.gleam" + ] + }, + "blurb": "Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number.", + "source": "Sieve of Eratosthenes at Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" +} diff --git a/exercises/practice/sieve/.meta/example.gleam b/exercises/practice/sieve/.meta/example.gleam new file mode 100644 index 000000000..4475b0bea --- /dev/null +++ b/exercises/practice/sieve/.meta/example.gleam @@ -0,0 +1,55 @@ +import gleam/list +import gleam/iterator +import gleam/bool +import gleam/set.{type Set} + +pub fn primes_up_to(upper_bound: Int) -> List(Int) { + // 2 is the first prime number. Smaller input values are invalid. + use <- bool.guard(when: upper_bound < 2, return: []) + + // Generate a list of all integers from 2 up to the upper bound. + let possible_primes = list.range(from: 2, to: upper_bound) + + // Run the sieve algorithm on the list of possible primes. + sieve([], set.new(), possible_primes, upper_bound) + |> list.reverse +} + +fn sieve( + primes: List(Int), + composites: Set(Int), + candidates: List(Int), + upper_bound: Int, +) -> List(Int) { + case candidates { + // BASE CASE: If there are no more candidates, we're done. + [] -> primes + + [next, ..rest] -> { + case set.contains(composites, next) { + // If the next candidate is a multiple of one of our discovered primes, skip it + True -> sieve(primes, composites, rest, upper_bound) + + // The next candidate is not a multiple of any of our discovered primes, so it's prime. + False -> { + // Generate a list from n^2 to the upper bound of the multiples of + // our newly discovered prime. + let multiples = + iterator.iterate(next * next, fn(state) { state + next }) + |> iterator.take_while(fn(n) { n <= upper_bound }) + |> iterator.to_list + |> set.from_list + + // Add the newly discovered prime to the list of primes, and + // add the multiples of the prime to the list of composites. + sieve( + [next, ..primes], + set.union(composites, multiples), + rest, + upper_bound, + ) + } + } + } + } +} diff --git a/exercises/practice/sieve/.meta/tests.toml b/exercises/practice/sieve/.meta/tests.toml new file mode 100644 index 000000000..fec5e1a1a --- /dev/null +++ b/exercises/practice/sieve/.meta/tests.toml @@ -0,0 +1,25 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[88529125-c4ce-43cc-bb36-1eb4ddd7b44f] +description = "no primes under two" + +[4afe9474-c705-4477-9923-840e1024cc2b] +description = "find first prime" + +[974945d8-8cd9-4f00-9463-7d813c7f17b7] +description = "find primes up to 10" + +[2e2417b7-3f3a-452a-8594-b9af08af6d82] +description = "limit is prime" + +[92102a05-4c7c-47de-9ed0-b7d5fcd00f21] +description = "find primes up to 1000" diff --git a/exercises/practice/sieve/gleam.toml b/exercises/practice/sieve/gleam.toml new file mode 100644 index 000000000..ca2a5e193 --- /dev/null +++ b/exercises/practice/sieve/gleam.toml @@ -0,0 +1,11 @@ +name = "sieve" +version = "0.1.0" + +[dependencies] +gleam_bitwise = "~> 1.2" +gleam_otp = "~> 0.7 or ~> 1.0" +gleam_stdlib = "~> 0.32 or ~> 1.0" +simplifile = "~> 1.0" + +[dev-dependencies] +exercism_test_runner = "~> 1.4" diff --git a/exercises/practice/sieve/manifest.toml b/exercises/practice/sieve/manifest.toml new file mode 100644 index 000000000..1f100088c --- /dev/null +++ b/exercises/practice/sieve/manifest.toml @@ -0,0 +1,26 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "argv", version = "1.0.1", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "A6E9009E50BBE863EB37D963E4315398D41A3D87D0075480FC244125808F964A" }, + { name = "exercism_test_runner", version = "1.7.0", build_tools = ["gleam"], requirements = ["simplifile", "argv", "gleam_erlang", "gap", "glance", "gleam_stdlib", "gleam_community_ansi", "gleam_json"], otp_app = "exercism_test_runner", source = "hex", outer_checksum = "2FC1BADB19BEC2AE77BFD2D3A606A014C85412A7B874CAFC4BA8CF04B0B257CD" }, + { name = "gap", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_stdlib"], otp_app = "gap", source = "hex", outer_checksum = "2EE1B0A17E85CF73A0C1D29DA315A2699117A8F549C8E8D89FA8261BE41EDEB1" }, + { name = "glance", version = "0.8.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "C486C920E1865F66A404AAB9A762C4226D95B60AC2C733D175B28C3F0920CE21" }, + { name = "gleam_bitwise", version = "1.3.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "B36E1D3188D7F594C7FD4F43D0D2CE17561DE896202017548578B16FE1FE9EFC" }, + { name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_community_colour"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" }, + { name = "gleam_community_colour", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "A49A5E3AE8B637A5ACBA80ECB9B1AFE89FD3D5351FF6410A42B84F666D40D7D5" }, + { name = "gleam_erlang", version = "0.24.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "26BDB52E61889F56A291CB34167315780EE4AA20961917314446542C90D1C1A0" }, + { name = "gleam_json", version = "1.0.0", build_tools = ["gleam"], requirements = ["thoas", "gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "8B197DD5D578EA6AC2C0D4BDC634C71A5BCA8E7DB5F47091C263ECB411A60DF3" }, + { name = "gleam_otp", version = "0.9.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "5FADBBEC5ECF3F8B6BE91101D432758503192AE2ADBAD5602158977341489F71" }, + { name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" }, + { name = "glexer", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "4484942A465482A0A100936E1E5F12314DB4B5AC0D87575A7B9E9062090B96BE" }, + { name = "simplifile", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "359CD7006E2F69255025C858CCC6407C11A876EC179E6ED1E46809E8DC6B1AAD" }, + { name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" }, +] + +[requirements] +exercism_test_runner = { version = "~> 1.4" } +gleam_bitwise = { version = "~> 1.2" } +gleam_otp = { version = "~> 0.7 or ~> 1.0" } +gleam_stdlib = { version = "~> 0.32 or ~> 1.0" } +simplifile = { version = "~> 1.0" } diff --git a/exercises/practice/sieve/src/sieve.gleam b/exercises/practice/sieve/src/sieve.gleam new file mode 100644 index 000000000..c81c3d854 --- /dev/null +++ b/exercises/practice/sieve/src/sieve.gleam @@ -0,0 +1,3 @@ +pub fn primes_up_to(upper_bound: Int) -> List(Int) { + todo +} diff --git a/exercises/practice/sieve/test/sieve_test.gleam b/exercises/practice/sieve/test/sieve_test.gleam new file mode 100644 index 000000000..26d9afe03 --- /dev/null +++ b/exercises/practice/sieve/test/sieve_test.gleam @@ -0,0 +1,50 @@ +import exercism/test_runner +import exercism/should +import sieve + +pub fn main() { + test_runner.main() +} + +pub fn no_primes_under_two_test() { + sieve.primes_up_to(1) + |> should.equal([]) + sieve.primes_up_to(0) + |> should.equal([]) + sieve.primes_up_to(-1) + |> should.equal([]) + sieve.primes_up_to(-20) + |> should.equal([]) +} + +pub fn find_first_prime_test() { + sieve.primes_up_to(2) + |> should.equal([2]) +} + +pub fn find_primes_up_to_10_test() { + sieve.primes_up_to(10) + |> should.equal([2, 3, 5, 7]) +} + +pub fn limit_is_prime_test() { + sieve.primes_up_to(13) + |> should.equal([2, 3, 5, 7, 11, 13]) +} + +pub fn find_primes_up_to_1000_test() { + sieve.primes_up_to(1000) + |> should.equal([ + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, + 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, + 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, + 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, + 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, + 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, + 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, + 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, + 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, + 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, + 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, + ]) +}