-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new exercise - series * new exercise - series [no important files changed]
- Loading branch information
1 parent
8cf00ab
commit e9ec01c
Showing
8 changed files
with
267 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Description | ||
|
||
Given a string of digits, output all the contiguous substrings of length `n` in that string in the order that they appear. | ||
|
||
For example, the string "49142" has the following 3-digit series: | ||
|
||
- "491" | ||
- "914" | ||
- "142" | ||
|
||
And the following 4-digit series: | ||
|
||
- "4914" | ||
- "9142" | ||
|
||
And if you ask for a 6-digit series from a 5-digit string, you deserve whatever you get. | ||
|
||
Note that these series are only required to occupy _adjacent positions_ in the input; | ||
the digits need not be _numerically consecutive_. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@echo off | ||
setlocal EnableDelayedExpansion | ||
|
||
set "series=%~1" | ||
set "sliceLength=%~2" | ||
set "result=" | ||
|
||
call :getLength "%series%" seriesLen | ||
|
||
if %sliceLength% GTR %seriesLen% ( | ||
echo slice length cannot be greater than series length | ||
exit /b | ||
) | ||
|
||
if %sliceLength% EQU 0 ( | ||
echo slice length cannot be zero | ||
exit /b | ||
) | ||
|
||
if %sliceLength% LSS 0 ( | ||
echo slice length cannot be negative | ||
exit /b | ||
) | ||
|
||
if [%series%] EQU [] ( | ||
echo series cannot be empty | ||
exit /b | ||
) | ||
|
||
for /l %%x in (0, 1, %seriesLen%) do ( | ||
set "variation=!series:~%%x,%sliceLength%!" | ||
call :getLength "!variation!" variationLen | ||
if !variationLen! EQU !sliceLength! ( | ||
set result=!result! !variation! | ||
) | ||
) | ||
echo !result:~1! | ||
exit /b | ||
|
||
:getLength | ||
setlocal EnableDelayedExpansion | ||
set "s=#%~1" | ||
set "len=0" | ||
for %%N in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( | ||
if "!s:~%%N,1!" neq "" ( | ||
set /a "len+=%%N" | ||
set "s=!s:~%%N!" | ||
) | ||
) | ||
endlocal&if "%~2" neq "" (set %~2=%len%) else echo %len% | ||
exit /b |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"authors": ["GroophyLifefor"], | ||
"files": { | ||
"solution": [ | ||
"Series.bat" | ||
], | ||
"test": [ | ||
"SeriesTest.bat" | ||
], | ||
"example": [ | ||
".meta/Example.bat" | ||
] | ||
}, | ||
"blurb": "Given a string of digits, output all the contiguous substrings of length `n` in that string.", | ||
"source": "A subset of the Problem 8 at Project Euler." | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@echo off | ||
setlocal EnableDelayedExpansion | ||
|
||
set "series=%~1" | ||
set "sliceLength=%~2" | ||
set "result=" | ||
|
||
REM Your code goes here | ||
|
||
|
||
echo %result% |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
@echo off | ||
REM --------------------------------------------------- | ||
REM Series Unit Testing | ||
REM --------------------------------------------------- | ||
|
||
:Main | ||
REM Initalize result variable | ||
set "slug=Series" | ||
|
||
CALL :Initialize | ||
|
||
REM -------------------- | ||
REM Test Case Start \/\/ | ||
REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/series/canonical-data.json | ||
REM -------------------- | ||
set "expected=1" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slices of one from one." | ||
CALL :Assert "1" "1" | ||
|
||
set "expected=1 2" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slices of one from two." | ||
CALL :Assert "12" "1" | ||
|
||
set "expected=35" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slices of two." | ||
CALL :Assert "35" "2" | ||
|
||
set "expected=91 14 42" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slices of two overlap." | ||
CALL :Assert "9142" "2" | ||
|
||
set "expected=777 777 777 777" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slices can include duplicates." | ||
CALL :Assert "777777" "3" | ||
|
||
set "expected=91849 18493 84939 49390 93904 39042 90424 04243" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slices of a long series." | ||
CALL :Assert "918493904243" "5" | ||
|
||
set "expected=slice length cannot be greater than series length" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slice length is too large." | ||
CALL :Assert "12345" "6" | ||
|
||
set "expected=slice length cannot be greater than series length" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slice length is way too large." | ||
CALL :Assert "12345" "42" | ||
|
||
set "expected=slice length cannot be zero" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slice length cannot be zero." | ||
CALL :Assert "12345" "0" | ||
|
||
set "expected=slice length cannot be negative" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: slice length cannot be negative." | ||
CALL :Assert "12345" "-1" | ||
|
||
set "expected=series cannot be empty" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: empty series is invalid." | ||
CALL :Assert "" "1" | ||
|
||
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=<stdout.bin | ||
del stdout.bin | ||
|
||
REM Check if the result is correct | ||
if "%stdout%" == "%expected%" ( | ||
if defined if_success ( | ||
echo %if_success% | ||
|
||
REM Reset the variable to avoid duplicating the message. | ||
set "if_success=" | ||
set "if_failed=" | ||
) | ||
|
||
REM If the result is correct, exit with code 0 | ||
set /a successCount+=1 | ||
exit /b 0 | ||
) else ( | ||
if defined if_failed ( | ||
echo %if_failed% | ||
echo Expected: %expected% | ||
echo Actually: %stdout% | ||
|
||
REM Reset the variable to avoid duplicating the message. | ||
set "if_success=" | ||
set "if_failed=" | ||
) | ||
|
||
REM If the result is incorrect, exit with code 1 | ||
set /a failCount+=1 | ||
exit /b 1 | ||
) | ||
GOTO :EOF REM Go back to the line after the call to :Assert | ||
|
||
:Initialize | ||
REM It's for initialize, not about checking empty file | ||
set "successCount=0" | ||
set "failCount=0" | ||
GOTO :EOF REM Go back to the line after the call to :CheckEmptyFile | ||
|
||
:ResolveStatus | ||
set "status=" | ||
if %failCount% gtr 0 ( | ||
REM status: Fail | ||
REM message: The test failed. | ||
exit /b 1 | ||
|
||
) else ( | ||
REM status: Pass | ||
exit /b 0 | ||
|
||
) | ||
GOTO :EOF REM Go back to the line after the call to :ExportResultAsJson | ||
|
||
:End |