Skip to content

Commit a027603

Browse files
committed
adding diamond
1 parent c5ce548 commit a027603

File tree

11 files changed

+585
-0
lines changed

11 files changed

+585
-0
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@
321321
"prerequisites": [],
322322
"difficulty": 3
323323
},
324+
{
325+
"slug": "diamond",
326+
"name": "Diamond",
327+
"uuid": "b8e1e5e1-6d46-4601-af80-c60c54401bf8",
328+
"practices": [],
329+
"prerequisites": [],
330+
"difficulty": 2
331+
},
324332
{
325333
"slug": "secret-handshake",
326334
"name": "Secret Handshake",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Instructions
2+
3+
The diamond kata takes as its input a letter, and outputs it in a diamond
4+
shape. Given a letter, it prints a diamond starting with 'A', with the
5+
supplied letter at the widest point.
6+
7+
## Requirements
8+
9+
* The first row contains one 'A'.
10+
* The last row contains one 'A'.
11+
* All rows, except the first and last, have exactly two identical letters.
12+
* All rows have as many trailing spaces as leading spaces. (This might be 0).
13+
* The diamond is horizontally symmetric.
14+
* The diamond is vertically symmetric.
15+
* The diamond has a square shape (width equals height).
16+
* The letters form a diamond shape.
17+
* The top half has the letters in ascending order.
18+
* The bottom half has the letters in descending order.
19+
* The four corners (containing the spaces) are triangles.
20+
21+
## Examples
22+
23+
In the following examples, spaces are indicated by `·` characters.
24+
25+
Diamond for letter 'A':
26+
27+
```text
28+
A
29+
```
30+
31+
Diamond for letter 'C':
32+
33+
```text
34+
··A··
35+
·B·B·
36+
C···C
37+
·B·B·
38+
··A··
39+
```
40+
41+
Diamond for letter 'E':
42+
43+
```text
44+
····A····
45+
···B·B···
46+
··C···C··
47+
·D·····D·
48+
E·······E
49+
·D·····D·
50+
··C···C··
51+
···B·B···
52+
····A····
53+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"authors": [
3+
"kapitaali"
4+
],
5+
"files": {
6+
"solution": [
7+
"src/diamond.cob"
8+
],
9+
"test": [
10+
"tst/diamond/diamond.cut"
11+
],
12+
"example": [
13+
".meta/proof.ci.cob"
14+
],
15+
"invalidator": [
16+
"test.ps1",
17+
"test.sh",
18+
"bin/fetch-cobolcheck",
19+
"bin/fetch-cobolcheck.ps1",
20+
"config.properties"
21+
]
22+
},
23+
"blurb": "Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.",
24+
"source": "Seb Rose",
25+
"source_url": "http://claysnow.co.uk/recycling-tests-in-tdd/"
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
IDENTIFICATION DIVISION.
2+
PROGRAM-ID. DIAMOND.
3+
AUTHOR. kapitaali.
4+
ENVIRONMENT DIVISION.
5+
DATA DIVISION.
6+
WORKING-STORAGE SECTION.
7+
01 WS-INPUTVARS.
8+
05 WS-LETTER PIC X.
9+
05 WS-ROWS PIC 99.
10+
01 WS-OUTPUTTABLE.
11+
05 WS-TABLEROW OCCURS 1 TO 60 DEPENDING ON WS-ROWS.
12+
10 WS-LINE PIC X(60).
13+
14+
01 MY-WORKVARS.
15+
05 CHARS PIC X(26) VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
16+
05 ALINE PIC X(60).
17+
05 MIDDLEPOINT PIC 99.
18+
05 A PIC 99.
19+
05 B PIC 99.
20+
05 C PIC 99.
21+
05 D PIC 99.
22+
05 COUNTER PIC 99.
23+
05 ADD-THIS PIC S99.
24+
25+
26+
PROCEDURE DIVISION.
27+
28+
GET-TABLE-SIZE.
29+
PERFORM VARYING A FROM 1 BY 1 UNTIL A = 27
30+
IF CHARS(A:1) = WS-LETTER
31+
EXIT PARAGRAPH
32+
END-IF
33+
END-PERFORM.
34+
35+
36+
DIAMOND.
37+
EVALUATE WS-LETTER
38+
WHEN 'A'
39+
MOVE 1 TO WS-ROWS
40+
INITIALIZE WS-OUTPUTTABLE
41+
MOVE 'A' TO WS-TABLEROW(1)
42+
WHEN 'B'
43+
MOVE 3 TO WS-ROWS
44+
INITIALIZE WS-OUTPUTTABLE
45+
MOVE " A " TO WS-TABLEROW(1)
46+
MOVE "B B" TO WS-TABLEROW(2)
47+
MOVE " A " TO WS-TABLEROW(3)
48+
WHEN OTHER
49+
PERFORM GET-TABLE-SIZE
50+
COMPUTE WS-ROWS = 2 + 2*(A - 2) + 1
51+
COMPUTE MIDDLEPOINT = (WS-ROWS - 1) / 2
52+
INITIALIZE WS-OUTPUTTABLE
53+
MOVE SPACES TO ALINE
54+
COMPUTE D = MIDDLEPOINT + 1
55+
MOVE CHARS(1:1) TO ALINE(D:1)
56+
MOVE ALINE TO WS-TABLEROW(1)
57+
MOVE ALINE TO WS-TABLEROW(WS-ROWS)
58+
MOVE 0 TO COUNTER
59+
MOVE 1 TO ADD-THIS
60+
PERFORM VARYING A FROM 2 BY 1 UNTIL A = WS-ROWS
61+
MOVE SPACES TO ALINE
62+
IF COUNTER = MIDDLEPOINT
63+
MOVE -1 TO ADD-THIS
64+
END-IF
65+
COMPUTE COUNTER = COUNTER + ADD-THIS
66+
COMPUTE B = MIDDLEPOINT - COUNTER
67+
COMPUTE C = COUNTER + 1
68+
COMPUTE D = B + 1
69+
MOVE CHARS(C:1) TO ALINE(D:1)
70+
COMPUTE B = MIDDLEPOINT + COUNTER
71+
COMPUTE C = COUNTER + 1
72+
COMPUTE D = B + 1
73+
MOVE CHARS(C:1) TO ALINE(D:1)
74+
MOVE ALINE TO WS-TABLEROW(A)
75+
END-PERFORM
76+
END-EVALUATE.
77+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
# This file is a copy of the
4+
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet file.
5+
# Please submit bugfixes/improvements to the above file to ensure that all tracks benefit from the changes.
6+
7+
# set -eo pipefail
8+
9+
readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'
10+
11+
case "$(uname)" in
12+
Darwin*) os='mac' ;;
13+
Linux*) os='linux' ;;
14+
Windows*) os='windows' ;;
15+
MINGW*) os='windows' ;;
16+
MSYS_NT-*) os='windows' ;;
17+
*) os='linux' ;;
18+
esac
19+
20+
case "${os}" in
21+
windows*) ext='.exe' ;;
22+
*) ext='' ;;
23+
esac
24+
25+
arch="$(uname -m)"
26+
27+
curlopts=(
28+
--silent
29+
--show-error
30+
--fail
31+
--location
32+
--retry 3
33+
)
34+
35+
if [[ -n "${GITHUB_TOKEN}" ]]; then
36+
curlopts+=(--header "authorization: Bearer ${GITHUB_TOKEN}")
37+
fi
38+
39+
suffix="${os}-${arch}${ext}"
40+
41+
get_download_url() {
42+
curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${LATEST}" |
43+
grep "\"browser_download_url\": \".*/download/.*/cobol-check.*${suffix}\"$" |
44+
cut -d'"' -f4
45+
}
46+
47+
main() {
48+
if [[ -d ./bin ]]; then
49+
output_dir="./bin"
50+
elif [[ $PWD == */bin ]]; then
51+
output_dir="$PWD"
52+
else
53+
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
54+
return 1
55+
fi
56+
57+
output_path="${output_dir}/cobolcheck${ext}"
58+
download_url="$(get_download_url)"
59+
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
60+
chmod +x "${output_path}"
61+
}
62+
63+
main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is a copy of the
2+
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.ps1 file.
3+
# Please submit bugfixes/improvements to the above file to ensure that all tracks
4+
# benefit from the changes.
5+
6+
$ErrorActionPreference = "Stop"
7+
$ProgressPreference = "SilentlyContinue"
8+
9+
$requestOpts = @{
10+
Headers = If ($env:GITHUB_TOKEN) { @{ Authorization = "Bearer ${env:GITHUB_TOKEN}" } } Else { @{ } }
11+
MaximumRetryCount = 3
12+
RetryIntervalSec = 1
13+
}
14+
15+
$arch = If ([Environment]::Is64BitOperatingSystem) { "amd64" } Else { "x86" }
16+
$fileName = "cobol-check-windows-$arch.exe"
17+
18+
Function Get-DownloadUrl {
19+
$latestUrl = "https://api.github.com/repos/0xE282B0/cobol-check/releases/latest"
20+
Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts
21+
| Select-Object -ExpandProperty assets
22+
| Where-Object { $_.browser_download_url -match $FileName }
23+
| Select-Object -ExpandProperty browser_download_url
24+
}
25+
26+
$downloadUrl = Get-DownloadUrl
27+
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe"
28+
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts

0 commit comments

Comments
 (0)