diff --git a/config.json b/config.json index e1faa74..9cd41a8 100644 --- a/config.json +++ b/config.json @@ -101,10 +101,7 @@ "slug": "reverse-string", "name": "Reverse String", "uuid": "ba8c915a-85c0-4798-b21f-4adf4268b606", - "practices": [ - "loops", - "strings" - ], + "practices": ["loops", "strings"], "prerequisites": [], "difficulty": 1, "topics": [] @@ -186,6 +183,24 @@ "practices": [], "prerequisites": ["basics", "numbers", "loops"], "difficulty": 1 + }, + { + "slug": "nth-prime", + "name": "Nth Prime", + "uuid": "9fd3acaf-d5d7-4f95-addc-db31b4779844", + "practices": [], + "prerequisites": [ + "basics", + "bools", + "conditionals", + "comparisons", + "lists", + "list-methods", + "loops", + "numbers", + "strings" + ], + "difficulty": 2 } ] }, diff --git a/exercises/practice/nth-prime/.docs/instructions.md b/exercises/practice/nth-prime/.docs/instructions.md new file mode 100644 index 0000000..28dc99f --- /dev/null +++ b/exercises/practice/nth-prime/.docs/instructions.md @@ -0,0 +1,7 @@ +# Description + +Given a number n, determine what the nth prime is. + +By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. + +If your language provides methods in the standard library to deal with prime numbers, pretend they don't exist and implement them yourself. diff --git a/exercises/practice/nth-prime/.meta/Example.bat b/exercises/practice/nth-prime/.meta/Example.bat new file mode 100644 index 0000000..1b9caee --- /dev/null +++ b/exercises/practice/nth-prime/.meta/Example.bat @@ -0,0 +1,44 @@ +@echo off +setlocal enabledelayedexpansion + +set targetNTH=%~1 +set /a "currentNTH=0" +set "primeNumbers=" + +if %targetNTH% equ 0 ( + echo there is no zeroth prime + exit /b 0 +) + +for /L %%a in (1,1,10001) do ( + set index=%%a + 2>nul set /a "1/(!index! %% 2)" && ( + if !index! neq 1 ( + set divideableCheck=true + for %%b in (!primeNumbers!) do ( + set /a "remainder=!index! %% %%b" + if !remainder! equ 0 ( + set divideableCheck=false + ) + ) + + if !divideableCheck! equ true ( + set primeNumbers=!primeNumbers! !index! + set /a "currentNTH+=1" + if !currentNTH! equ %targetNTH% ( + echo !index! + exit /b 0 + ) + ) + ) + ) + + if !index! equ 2 ( + set primeNumbers=!primeNumbers! !index! + set /a "currentNTH+=1" + if !currentNTH! equ %targetNTH% ( + echo !index! + exit /b 0 + ) + ) +) diff --git a/exercises/practice/nth-prime/.meta/config.json b/exercises/practice/nth-prime/.meta/config.json new file mode 100644 index 0000000..134f2a0 --- /dev/null +++ b/exercises/practice/nth-prime/.meta/config.json @@ -0,0 +1,16 @@ +{ + "authors": ["dbenham", "GroophyLifefor"], + "files": { + "solution": [ + "NthPrime.bat" + ], + "test": [ + "NthPrimeTest.bat" + ], + "example": [ + ".meta/Example.bat" + ] + }, + "blurb": "Given a number n, determine what the nth prime is.", + "source": "A variation on Problem 7 at Project Euler" +} diff --git a/exercises/practice/nth-prime/.meta/tests.toml b/exercises/practice/nth-prime/.meta/tests.toml new file mode 100644 index 0000000..73466d6 --- /dev/null +++ b/exercises/practice/nth-prime/.meta/tests.toml @@ -0,0 +1,13 @@ +# 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. + +[af9ffe10-dc13-42d8-a742-e7bdafac449d] +description = "Say Hi!" diff --git a/exercises/practice/nth-prime/NthPrime.bat b/exercises/practice/nth-prime/NthPrime.bat new file mode 100644 index 0000000..2353f32 --- /dev/null +++ b/exercises/practice/nth-prime/NthPrime.bat @@ -0,0 +1,10 @@ +@echo off +setlocal enabledelayedexpansion + +set targetNTH=%~1 +set result= + +REM Your code goes here + + +echo %result% diff --git a/exercises/practice/nth-prime/NthPrimeTest.bat b/exercises/practice/nth-prime/NthPrimeTest.bat new file mode 100644 index 0000000..dc11a0b --- /dev/null +++ b/exercises/practice/nth-prime/NthPrimeTest.bat @@ -0,0 +1,116 @@ +@echo off +REM --------------------------------------------------- +REM Difference Of Squares Unit Testing +REM +REM sUnit Testing Framework version: 0.2 +REM --------------------------------------------------- + +:Main + REM Initalize result variable + set "slug=NthPrime" + + CALL :Initialize + + REM -------------------- + REM Test Case Start \/\/ + REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/nth-prime/canonical-data.json + REM -------------------- + set "expected=2" + set "if_success=Test passed" + set "if_failed=Test failed: first prime" + CALL :Assert "1" + + set "expected=3" + set "if_success=Test passed" + set "if_failed=Test failed: second prime" + CALL :Assert "2" + + set "expected=13" + set "if_success=Test passed" + set "if_failed=Test failed: sixth prime" + CALL :Assert "6" + + set "expected=229" + set "if_success=Test passed" + set "if_failed=Test failed: 50th prime" + CALL :Assert "50" + + set "expected=487" + set "if_success=Test passed" + set "if_failed=Test failed: 50th prime" + CALL :Assert "93" + + set "expected=there is no zeroth prime" + set "if_success=Test passed" + set "if_failed=Test failed: 50th prime" + CALL :Assert "0" + + REM -------------------- + REM Test Case End /\/\/\ + REM -------------------- + + CALL :ResolveStatus + exit /b %errorlevel% +REM End of Main + +REM --------------------------------------------------- +REM Assert [..Parameters(up to 9)] +REM --------------------------------------------------- +GOTO :End REM Prevents the code below from being executed +:Assert +set "stdout=" + +REM Run the program and capture the output then delete the file +CALL %slug%.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 > stdout.bin 2>&1 +set /p stdout=