Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added 8 new exercises #105

Merged
merged 6 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,70 @@
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "acronym",
"name": "Acronym",
"uuid": "628083ab-c882-4cf8-a800-5985ba7c8769",
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "all-your-base",
"name": "All Your Base",
"uuid": "af67e38a-90e4-4016-8a02-1ad26121d50a",
"practices": [],
"prerequisites": [],
"difficulty": 4
},
{
"slug": "atbash-cipher",
"name": "Atbash Cipher",
"uuid": "00377c73-8113-4251-8445-526393f86194",
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "binary",
"name": "Binary",
"uuid": "970462fb-898f-457f-ace1-34da0849035b",
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "circular-buffer",
"name": "Circular Buffer",
"uuid": "cad7a7b5-4159-4cae-8459-c68b0732eee1",
"practices": [],
"prerequisites": [],
"difficulty": 4
},
{
"slug": "complex-numbers",
"name": "Complex Numbers",
"uuid": "2f4b350f-fcec-400a-a804-671a9e8cef91",
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "matching-brackets",
"name": "Matching Brackets",
"uuid": "15d35143-4ddc-4a8a-9e5e-136f831d2a6d",
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "pascals-triangle",
"name": "Pascal's Triangle",
"uuid": "bcfd99e2-3749-4cc9-9708-88de69e474ac",
"practices": [],
"prerequisites": [],
"difficulty": 5
}
]
},
Expand Down
17 changes: 17 additions & 0 deletions exercises/practice/acronym/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Description

Convert a phrase to its acronym.

Techies love their TLA (Three Letter Acronyms)!

Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).

Punctuation is handled as follows: hyphens are word separators (like whitespace); all other punctuation can be removed from the input.

For example:

|Input|Output|
|-|-|
|As Soon As Possible|ASAP|
|Liquid-crystal display|LCD|
|Thank George It's Friday!|TGIF|
23 changes: 23 additions & 0 deletions exercises/practice/acronym/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"authors": [
"kapitaali"
],
"files": {
"solution": [
"src/acronym.cob"
],
"test": [
"tst/acronym/acronym.cut"
],
"example": [
".meta/proof.ci.cob"
],
"invalidator": [
"test.sh",
"test.ps1"
]
},
"blurb": "Convert a phrase to its acronym.",
"source": "Julien Vanier",
"source_url": "https://github.com/monkbroc"
}
52 changes: 52 additions & 0 deletions exercises/practice/acronym/.meta/proof.ci.cob
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. acronym.
AUTHOR. kapitaali.
ENVIRONMENT DIVISION.
DATA DIVISION.
FILE SECTION.

WORKING-STORAGE SECTION.
01 WS-ACRONYM PIC X(80).
01 WS-RESULT PIC X(20).
01 LEN PIC 99.
01 PICKNEXT PIC 9.
01 COUNTER PIC 99.
01 IDX PIC 99.
01 CHAR PIC X.

PROCEDURE DIVISION.
ABBREVIATE.
PERFORM STR-LENGTH.
MOVE 1 TO IDX.
MOVE SPACES TO WS-RESULT.
MOVE 1 TO PICKNEXT.
PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER = LEN
MOVE WS-ACRONYM(COUNTER:1) TO CHAR
EVALUATE CHAR
WHEN "_"
CONTINUE
WHEN " "
MOVE 1 TO PICKNEXT
CONTINUE
WHEN "-"
MOVE 1 TO PICKNEXT
CONTINUE
WHEN OTHER
IF PICKNEXT = 1
MOVE FUNCTION UPPER-CASE(CHAR)
TO WS-RESULT(IDX:1)
ADD 1 TO IDX
END-IF
MOVE 0 TO PICKNEXT
END-PERFORM.

STR-LENGTH.
MOVE 0 TO LEN.
MOVE FUNCTION LENGTH(WS-ACRONYM) TO IDX.
PERFORM VARYING IDX FROM FUNCTION LENGTH(WS-ACRONYM)
BY -1 UNTIL WS-ACRONYM(IDX:1) <> " "
ADD 1 TO LEN
END-PERFORM.
COMPUTE LEN = 80 - LEN.


63 changes: 63 additions & 0 deletions exercises/practice/acronym/bin/fetch-cobolcheck
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
28 changes: 28 additions & 0 deletions exercises/practice/acronym/bin/fetch-cobolcheck.ps1
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
Loading
Loading