diff --git a/config.json b/config.json index c1b5f39..061a3c8 100644 --- a/config.json +++ b/config.json @@ -43,6 +43,19 @@ ], "prerequisites": [], "difficulty": 1 + }, + { + "uuid": "09af4822-c1da-4581-a88e-b44bbe275607", + "slug": "nucleotide-count", + "name": "Nucleotide Count", + "practices": [ + "basics", + "loops", + "arrays", + "conditionals" + ], + "prerequisites": [], + "difficulty": 1 } ] }, diff --git a/exercises/practice/nucleotide-count/.docs/instructions.md b/exercises/practice/nucleotide-count/.docs/instructions.md new file mode 100644 index 0000000..50c9c0d --- /dev/null +++ b/exercises/practice/nucleotide-count/.docs/instructions.md @@ -0,0 +1,23 @@ +# Description + +Each of us inherits from our biological parents a set of chemical instructions known as DNA that influence how our bodies are constructed. +All known life depends on DNA! + +> Note: You do not need to understand anything about nucleotides or DNA to complete this exercise. + +DNA is a long chain of other chemicals and the most important are the four nucleotides, adenine, cytosine, guanine and thymine. +A single DNA chain can contain billions of these four nucleotides and the order in which they occur is important! +We call the order of these nucleotides in a bit of DNA a "DNA sequence". + +We represent a DNA sequence as an ordered collection of these four nucleotides and a common way to do that is with a string of characters such as "ATTACG" for a DNA sequence of 6 nucleotides. +'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' for thymine. + +Given a string representing a DNA sequence, count how many of each nucleotide is present. +If the string contains characters that aren't A, C, G, or T then it is invalid and you should signal an error. + +For example: + +```text +"GATTACA" -> 'A': 3, 'C': 1, 'G': 1, 'T': 2 +"INVALID" -> error +``` diff --git a/exercises/practice/nucleotide-count/.meta/Example.bat b/exercises/practice/nucleotide-count/.meta/Example.bat new file mode 100644 index 0000000..473bdeb --- /dev/null +++ b/exercises/practice/nucleotide-count/.meta/Example.bat @@ -0,0 +1,24 @@ +@echo off +SETLOCAL EnableDelayedExpansion + +set "nucleotide=%~1" +set "nucleotide[A]=0" +set "nucleotide[C]=0" +set "nucleotide[G]=0" +set "nucleotide[T]=0" + +if "!nucleotide!"=="" goto :display_result +for /f "delims=ACGT" %%A in ("%nucleotide%") do ( + echo Invalid nucleotide in strand + exit /b +) + +set "index=0" +:strand_walker +if "!nucleotide:~%index%,1!"=="" goto :display_result +set /a "nucleotide[!nucleotide:~%index%,1!]+=1" +set /a index+=1 +goto :strand_walker + +:display_result +echo !nucleotide[A]!,!nucleotide[C]!,!nucleotide[G]!,!nucleotide[T]! diff --git a/exercises/practice/nucleotide-count/.meta/config.json b/exercises/practice/nucleotide-count/.meta/config.json new file mode 100644 index 0000000..0de1f20 --- /dev/null +++ b/exercises/practice/nucleotide-count/.meta/config.json @@ -0,0 +1,17 @@ +{ + "authors": ["sintrode", "GroophyLifefor"], + "files": { + "solution": [ + "NucleotideCount.bat" + ], + "test": [ + "NucleotideCountTest.bat" + ], + "example": [ + ".meta/Example.bat" + ] + }, + "blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.", + "source": "The Calculating DNA Nucleotides_problem at Rosalind", + "source_url": "https://rosalind.info/problems/dna/" +} diff --git a/exercises/practice/nucleotide-count/.meta/tests.toml b/exercises/practice/nucleotide-count/.meta/tests.toml new file mode 100644 index 0000000..73466d6 --- /dev/null +++ b/exercises/practice/nucleotide-count/.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/nucleotide-count/NucleotideCount.bat b/exercises/practice/nucleotide-count/NucleotideCount.bat new file mode 100644 index 0000000..ac73b98 --- /dev/null +++ b/exercises/practice/nucleotide-count/NucleotideCount.bat @@ -0,0 +1,13 @@ +@echo off +SETLOCAL EnableDelayedExpansion + +set "nucleotide=%~1" +set "nucleotide[A]=0" +set "nucleotide[C]=0" +set "nucleotide[G]=0" +set "nucleotide[T]=0" + +REM Your code goes here + + +echo !nucleotide[A]!,!nucleotide[C]!,!nucleotide[G]!,!nucleotide[T]! diff --git a/exercises/practice/nucleotide-count/NucleotideCountTest.bat b/exercises/practice/nucleotide-count/NucleotideCountTest.bat new file mode 100644 index 0000000..13fa764 --- /dev/null +++ b/exercises/practice/nucleotide-count/NucleotideCountTest.bat @@ -0,0 +1,109 @@ +@echo off +REM --------------------------------------------------- +REM NucleotideCount Unit Testing +REM --------------------------------------------------- + +:Main + REM Initalize result variable + set "slug=NucleotideCount" + + CALL :Initialize + + REM -------------------- + REM Test Case Start \/\/ + REM Resource: https://github.com/exercism/problem-specifications/blob/ce02684e726a1b78a1c1e591188e4e268fd27b15/exercises/nucleotide-count/canonical-data.json + REM -------------------- + set "expected=0,0,0,0" + set "if_success=Test passed" + set "if_failed=Test failed: empty strand." + CALL :Assert "" + + set "expected=0,0,1,0" + set "if_success=Test passed" + set "if_failed=Test failed: can count one nucleotide in single-character input." + CALL :Assert "G" + + set "expected=0,0,7,0" + set "if_success=Test passed" + set "if_failed=Test failed: strand with repeated nucleotide." + CALL :Assert "GGGGGGG" + + set "expected=20,12,17,21" + set "if_success=Test passed" + set "if_failed=Test failed: strand with multiple nucleotides." + CALL :Assert "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" + + set "expected=Invalid nucleotide in strand" + set "if_success=Test passed" + set "if_failed=Test failed: strand with invalid nucleotides - Print just 'Invalid nucleotide in strand'." + CALL :Assert "AGXXACT" + + 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=