diff --git a/exercises/practice/armstrong-numbers/.docs/instructions.md b/exercises/practice/armstrong-numbers/.docs/instructions.md new file mode 100644 index 0000000..98985e9 --- /dev/null +++ b/exercises/practice/armstrong-numbers/.docs/instructions.md @@ -0,0 +1,14 @@ +# Description + +An [Armstrong number][armstrong-number] is a number that is the sum of its own digits each raised to the power of the number of digits. + +For example: + +- 9 is an Armstrong number, because `9 = 9^1 = 9` +- 10 is _not_ an Armstrong number, because `10 != 1^2 + 0^2 = 1` +- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153` +- 154 is _not_ an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190` + +Write some code to determine whether a number is an Armstrong number. + +[armstrong-number]: https://en.wikipedia.org/wiki/Narcissistic_number diff --git a/exercises/practice/armstrong-numbers/.meta/Example.bat b/exercises/practice/armstrong-numbers/.meta/Example.bat new file mode 100644 index 0000000..febcc57 --- /dev/null +++ b/exercises/practice/armstrong-numbers/.meta/Example.bat @@ -0,0 +1,41 @@ +@echo off +setlocal enabledelayedexpansion + +set "numbers=%1" +set "sum=" +call :strLen numbersLen numbers + +for /F "delims=" %%G in ('cmd /D /U /C echo %numbers%^| find /V ""') do ( + SET result=1 + FOR /L %%i IN (1,1,!numbersLen!) DO SET /A result*=%%G + set /a sum+=!result! +) + +if %numbers% equ %sum% ( + echo true +) else ( + echo false +) + +REM ********* function ***************************** +:strlen +( + setlocal EnableDelayedExpansion + (set^ tmp=!%~2!) + if defined tmp ( + set "len=1" + for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( + if "!tmp:~%%P,1!" NEQ "" ( + set /a "len+=%%P" + set "tmp=!tmp:~%%P!" + ) + ) + ) ELSE ( + set len=0 + ) +) +( + endlocal + set "%~1=%len%" + exit /b +) diff --git a/exercises/practice/armstrong-numbers/.meta/config.json b/exercises/practice/armstrong-numbers/.meta/config.json new file mode 100644 index 0000000..b11222e --- /dev/null +++ b/exercises/practice/armstrong-numbers/.meta/config.json @@ -0,0 +1,17 @@ +{ + "authors": ["GroophyLifefor"], + "files": { + "solution": [ + "ArmstrongNumbers.bat" + ], + "test": [ + "ArmstrongNumbersTest.bat" + ], + "example": [ + ".meta/Example.bat" + ] + }, + "blurb": "Determine if a number is an Armstrong number.", + "source": "Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/Narcissistic_number/" +} diff --git a/exercises/practice/armstrong-numbers/.meta/tests.toml b/exercises/practice/armstrong-numbers/.meta/tests.toml new file mode 100644 index 0000000..73466d6 --- /dev/null +++ b/exercises/practice/armstrong-numbers/.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/armstrong-numbers/ArmstrongNumbers.bat b/exercises/practice/armstrong-numbers/ArmstrongNumbers.bat new file mode 100644 index 0000000..68d02c1 --- /dev/null +++ b/exercises/practice/armstrong-numbers/ArmstrongNumbers.bat @@ -0,0 +1,10 @@ +@echo off +setlocal enabledelayedexpansion + +set "numbers=%1" +set "result=" + +REM Your code goes here + + +echo %result% diff --git a/exercises/practice/armstrong-numbers/ArmstrongNumbersTest.bat b/exercises/practice/armstrong-numbers/ArmstrongNumbersTest.bat new file mode 100644 index 0000000..9ec6a5a --- /dev/null +++ b/exercises/practice/armstrong-numbers/ArmstrongNumbersTest.bat @@ -0,0 +1,142 @@ +@echo off +REM --------------------------------------------------- +REM Armstrong Numbers Unit Testing +REM +REM sUnit Testing Framework version: 0.2 +REM --------------------------------------------------- + +:Main + REM Initalize result variable + set "slug=ArmstrongNumbers" + + CALL :Initialize + + REM -------------------- + REM Test Case Start \/\/ + REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/acronym/canonical-data.json + REM -------------------- + set "expected=true" + set "if_success=Test passed" + set "if_failed=Test failed: Zero is an Armstrong number." + CALL :Assert 0 + + set "expected=true" + set "if_success=Test passed" + set "if_failed=Test failed: Single-digit numbers are Armstrong numbers." + CALL :Assert 5 + + set "expected=false" + set "if_success=Test passed" + set "if_failed=Test failed: There are no two-digit Armstrong numbers." + CALL :Assert 10 + + set "expected=true" + set "if_success=Test passed" + set "if_failed=Test failed: Three-digit number that is an Armstrong number." + CALL :Assert 153 + + set "expected=false" + set "if_success=Test passed" + set "if_failed=Test failed: Three-digit number that is not an Armstrong number." + CALL :Assert 100 + + set "expected=true" + set "if_success=Test passed" + set "if_failed=Test failed: Four-digit number that is an Armstrong number." + CALL :Assert 9474 + + set "expected=false" + set "if_success=Test passed" + set "if_failed=Test failed: Four-digit number that is not an Armstrong number." + CALL :Assert 9475 + + set "expected=true" + set "if_success=Test passed" + set "if_failed=Test failed: Seven-digit number that is an Armstrong number." + CALL :Assert 9926315 + + set "expected=false" + set "if_success=Test passed" + set "if_failed=Test failed: Seven-digit number that is not an Armstrong number." + CALL :Assert 9926314 + + REM -- Batch Scripting does not support 64-bit integers -- + REM set "expected=true" + REM set "if_success=Test passed" + REM set "if_failed=Test failed: Armstrong number containing seven zeroes." + REM CALL :Assert 186709961001538790100634132976990 + + REM set "expected=true" + REM set "if_success=Test passed" + REM set "if_failed=Test failed: The largest and last Armstrong number." + REM CALL :Assert 115132219018763992565095597973971522401 + + 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=