-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
854 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Instructions | ||
|
||
Given students' names along with the grade that they are in, create a roster | ||
for the school. | ||
|
||
In the end, you should be able to: | ||
|
||
- Add a student's name to the roster for a grade | ||
- "Add Jim to grade 2." | ||
- "OK." | ||
- Get a list of all students enrolled in a grade | ||
- "Which students are in grade 2?" | ||
- "We've only got Jim just now." | ||
- Get a sorted list of all students in all grades. Grades should sort | ||
as 1, 2, 3, etc., and students within a grade should be sorted | ||
alphabetically by name. | ||
- "Who all is enrolled in school right now?" | ||
- "Let me think. We have | ||
Anna, Barb, and Charlie in grade 1, | ||
Alex, Peter, and Zoe in grade 2 | ||
and Jim in grade 5. | ||
So the answer is: Anna, Barb, Charlie, Alex, Peter, Zoe and Jim" | ||
|
||
Note that all our students only have one name (It's a small town, what | ||
do you want?) and each student cannot be added more than once to a grade or the | ||
roster. | ||
In fact, when a test attempts to add the same student more than once, your | ||
implementation should indicate that this is incorrect. | ||
|
||
## For bonus points | ||
|
||
Did you get the tests passing and the code clean? If you want to, these | ||
are some additional things you could try: | ||
|
||
- If you're working in a language with mutable data structures and your | ||
implementation allows outside code to mutate the school's internal DB | ||
directly, see if you can prevent this. Feel free to introduce additional | ||
tests. | ||
|
||
Then please share your thoughts in a comment on the submission. Did this | ||
experiment make the code better? Worse? Did you learn anything from it? |
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,25 @@ | ||
{ | ||
"authors": [ | ||
"kapitaali" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/grade-school.cob" | ||
], | ||
"test": [ | ||
"tst/grade-school/grade-school.cut" | ||
], | ||
"example": [ | ||
".meta/proof.ci.cob" | ||
], | ||
"invalidator": [ | ||
"test.ps1", | ||
"test.sh", | ||
"bin/fetch-cobolcheck", | ||
"bin/fetch-cobolcheck.ps1", | ||
"config.properties" | ||
] | ||
}, | ||
"blurb": "Given students' names along with the grade that they are in, create a roster for the school.", | ||
"source": "A pairing session with Phil Battos at gSchool" | ||
} |
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,76 @@ | ||
IDENTIFICATION DIVISION. | ||
PROGRAM-ID. GRADE-SCHOOL. | ||
AUTHOR. kapitaali. | ||
ENVIRONMENT DIVISION. | ||
DATA DIVISION. | ||
WORKING-STORAGE SECTION. | ||
01 WS-STUDENTNAME PIC X(60). | ||
01 WS-STUDENTGRADE PIC 9. | ||
01 WS-DESIREDGRADE PIC 9. | ||
01 ENTRIES PIC 99 COMP. | ||
01 I PIC 99 COMP. | ||
01 J PIC 99 COMP. | ||
01 K PIC 99 COMP. | ||
01 TEMPNAME PIC X(60). | ||
01 TEMPGRADE PIC 9. | ||
|
||
01 STUDENTROSTER. | ||
02 ROSTER OCCURS 10 INDEXED BY INDX. | ||
05 ST-NAME PIC X(60). | ||
05 ST-GRADE PIC 9. | ||
|
||
|
||
PROCEDURE DIVISION. | ||
|
||
|
||
INIT-ROSTER. | ||
INITIALIZE STUDENTROSTER. | ||
MOVE 0 TO ENTRIES. | ||
SET INDX TO 0. | ||
|
||
|
||
ADD-STUDENT. | ||
SET INDX TO ENTRIES. | ||
SEARCH ROSTER VARYING INDX | ||
AT END PERFORM ADD-ENTRY | ||
WHEN ST-NAME(INDX) = WS-STUDENTNAME | ||
CONTINUE | ||
END-SEARCH. | ||
SORT ROSTER ASCENDING ST-GRADE ST-NAME. | ||
PERFORM MOVE-ENTRIES. | ||
|
||
|
||
MOVE-ENTRIES. | ||
COMPUTE J = 10 - ENTRIES. | ||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > ENTRIES | ||
COMPUTE K = I + J | ||
MOVE ST-NAME(K) TO TEMPNAME | ||
MOVE ST-GRADE(K) TO TEMPGRADE | ||
MOVE SPACES TO ST-NAME(K) | ||
MOVE 0 TO ST-GRADE(K) | ||
MOVE TEMPNAME TO ST-NAME(I) | ||
MOVE TEMPGRADE TO ST-GRADE(I) | ||
END-PERFORM. | ||
|
||
|
||
ADD-ENTRY. | ||
ADD 1 TO ENTRIES. | ||
MOVE WS-STUDENTGRADE TO ST-GRADE(ENTRIES). | ||
MOVE WS-STUDENTNAME TO ST-NAME(ENTRIES). | ||
|
||
|
||
GET-GRADE. | ||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10 | ||
IF WS-DESIREDGRADE IS NOT EQUAL TO ST-GRADE(I) | ||
MOVE SPACES TO ST-NAME(I) | ||
MOVE 0 TO ST-GRADE(I) | ||
END-IF | ||
END-PERFORM. | ||
SORT ROSTER ASCENDING ST-GRADE ST-NAME. | ||
MOVE 0 TO ENTRIES | ||
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10 | ||
IF ST-NAME(I) <> SPACES | ||
ADD 1 TO ENTRIES | ||
END-IF | ||
END-PERFORM. | ||
PERFORM MOVE-ENTRIES. |
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,63 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This file is a copy of the | ||
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet file. | ||
# Please submit bugfixes/improvements to the above file to ensure that all tracks benefit from the changes. | ||
|
||
# set -eo pipefail | ||
|
||
readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest' | ||
|
||
case "$(uname)" in | ||
Darwin*) os='mac' ;; | ||
Linux*) os='linux' ;; | ||
Windows*) os='windows' ;; | ||
MINGW*) os='windows' ;; | ||
MSYS_NT-*) os='windows' ;; | ||
*) os='linux' ;; | ||
esac | ||
|
||
case "${os}" in | ||
windows*) ext='.exe' ;; | ||
*) ext='' ;; | ||
esac | ||
|
||
arch="$(uname -m)" | ||
|
||
curlopts=( | ||
--silent | ||
--show-error | ||
--fail | ||
--location | ||
--retry 3 | ||
) | ||
|
||
if [[ -n "${GITHUB_TOKEN}" ]]; then | ||
curlopts+=(--header "authorization: Bearer ${GITHUB_TOKEN}") | ||
fi | ||
|
||
suffix="${os}-${arch}${ext}" | ||
|
||
get_download_url() { | ||
curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${LATEST}" | | ||
grep "\"browser_download_url\": \".*/download/.*/cobol-check.*${suffix}\"$" | | ||
cut -d'"' -f4 | ||
} | ||
|
||
main() { | ||
if [[ -d ./bin ]]; then | ||
output_dir="./bin" | ||
elif [[ $PWD == */bin ]]; then | ||
output_dir="$PWD" | ||
else | ||
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2 | ||
return 1 | ||
fi | ||
|
||
output_path="${output_dir}/cobolcheck${ext}" | ||
download_url="$(get_download_url)" | ||
curl "${curlopts[@]}" --output "${output_path}" "${download_url}" | ||
chmod +x "${output_path}" | ||
} | ||
|
||
main |
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,28 @@ | ||
# This file is a copy of the | ||
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.ps1 file. | ||
# Please submit bugfixes/improvements to the above file to ensure that all tracks | ||
# benefit from the changes. | ||
|
||
$ErrorActionPreference = "Stop" | ||
$ProgressPreference = "SilentlyContinue" | ||
|
||
$requestOpts = @{ | ||
Headers = If ($env:GITHUB_TOKEN) { @{ Authorization = "Bearer ${env:GITHUB_TOKEN}" } } Else { @{ } } | ||
MaximumRetryCount = 3 | ||
RetryIntervalSec = 1 | ||
} | ||
|
||
$arch = If ([Environment]::Is64BitOperatingSystem) { "amd64" } Else { "x86" } | ||
$fileName = "cobol-check-windows-$arch.exe" | ||
|
||
Function Get-DownloadUrl { | ||
$latestUrl = "https://api.github.com/repos/0xE282B0/cobol-check/releases/latest" | ||
Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts | ||
| Select-Object -ExpandProperty assets | ||
| Where-Object { $_.browser_download_url -match $FileName } | ||
| Select-Object -ExpandProperty browser_download_url | ||
} | ||
|
||
$downloadUrl = Get-DownloadUrl | ||
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe" | ||
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts |
Oops, something went wrong.