Skip to content

Commit

Permalink
adding meetup
Browse files Browse the repository at this point in the history
  • Loading branch information
kapitaali committed Apr 25, 2024
1 parent 8a480c0 commit bb597be
Show file tree
Hide file tree
Showing 11 changed files with 1,342 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@
"prerequisites": [],
"difficulty": 2
},
{
"slug": "meetup",
"name": "Meetup",
"uuid": "5eec226b-c30b-405d-9b6d-12cdf8ef4072",
"practices": [],
"prerequisites": [],
"difficulty": 4
},
{
"slug": "pascals-triangle",
"name": "Pascal's Triangle",
Expand Down
19 changes: 19 additions & 0 deletions exercises/practice/meetup/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Instructions

In this exercise, you will be given a general description of a meetup date and then asked to find the actual meetup date.

Examples of general descriptions are:

- First Monday of January 2022
- Third Tuesday of August 2021
- Teenth Wednesday of May 2022
- Teenth Sunday of July 2021
- Last Thursday of November 2021

The descriptors you are expected to process are: `first`, `second`, `third`, `fourth`, `fifth`, `last`, `teenth`.

Note that descriptor `teenth` is a made-up word.
There are exactly seven numbered days in a month that end with "teenth" ("thirteenth" to "nineteenth").
Therefore, it is guaranteed that each day of the week (Monday, Tuesday, ...) will have exactly one numbered day ending with "teenth" each month.

For example, if given "First Monday of January 2022", the correct meetup date is January 3, 2022.
23 changes: 23 additions & 0 deletions exercises/practice/meetup/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"authors": [
"kapitaali"
],
"files": {
"solution": [
"src/meetup.cob"
],
"test": [
"tst/meetup/meetup.cut"
],
"example": [
".meta/proof.ci.cob"
],
"invalidator": [
"test.sh",
"test.ps1"
]
},
"blurb": "Calculate the date of meetups.",
"source": "Jeremy Hinegardner mentioned a Boulder meetup that happens on the Wednesteenth of every month",
"source_url": "https://twitter.com/copiousfreetime"
}
123 changes: 123 additions & 0 deletions exercises/practice/meetup/.meta/proof.ci.cob
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. MEETUP.
AUTHOR. kapitaali.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-YEAR PIC 9999.
01 WS-MONTH PIC 99.
01 WS-WEEK PIC X(10).
01 WS-DAYOFWEEK PIC X(10).
01 WS-RESULT PIC X(40).
01 WEEKDAY PIC X(10).
01 MY-DATE PIC 9(8).
01 SOME-FLD PIC 9999.
01 MY-REM PIC 9999.
01 ITER PIC 99.
01 NO-OF-WDS PIC 9.
01 LEAP-YEAR PIC 9.

01 Weekdaytable.
02 WEEKDAYS-T PIC 99 OCCURS 6 TIMES.


PROCEDURE DIVISION.


GET-WEEKDAY.
DIVIDE FUNCTION INTEGER-OF-DATE(MY-DATE) BY 7
GIVING SOME-FLD REMAINDER MY-REM.
EVALUATE MY-REM
WHEN 0 MOVE 'Sunday' TO WEEKDAY
WHEN 1 MOVE 'Monday' TO WEEKDAY
WHEN 2 MOVE 'Tuesday' TO WEEKDAY
WHEN 3 MOVE 'Wednesday' TO WEEKDAY
WHEN 4 MOVE 'Thursday' TO WEEKDAY
WHEN 5 MOVE 'Friday' TO WEEKDAY
WHEN 6 MOVE 'Saturday' TO WEEKDAY
END-EVALUATE.


MEETUP.
INITIALIZE Weekdaytable.
MOVE ZEROES TO Weekdaytable.
PERFORM FIND-WEEKDAYS.
MOVE MY-DATE(1:4) TO WS-RESULT(1:4)
MOVE '-' TO WS-RESULT(5:1)
MOVE MY-DATE(5:2) TO WS-RESULT(6:2)
MOVE '-' TO WS-RESULT(8:1)
EVALUATE WS-WEEK
WHEN "first"
MOVE WEEKDAYS-T(1) TO WS-RESULT(9:2)
WHEN "second"
MOVE WEEKDAYS-T(2) TO WS-RESULT(9:2)
WHEN "third"
MOVE WEEKDAYS-T(3) TO WS-RESULT(9:2)
WHEN "fourth"
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
WHEN "teenth"
MOVE WEEKDAYS-T(6) TO WS-RESULT(9:2)
WHEN "last"
MOVE 0 TO LEAP-YEAR
PERFORM IS-IT-LEAP-YEAR
MOVE WEEKDAYS-T(5) TO ITER
MOVE ITER TO WS-RESULT(9:2)
IF ITER = 0 OR ITER > 31
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
END-IF
IF WS-MONTH = 2 AND LEAP-YEAR = 1 AND ITER > 29
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
END-IF
IF WS-MONTH = 2 AND LEAP-YEAR = 0 AND ITER > 28
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
END-IF
IF WS-MONTH = 4 AND LEAP-YEAR = 0 AND ITER > 30
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
END-IF
END-EVALUATE.


IS-IT-LEAP-YEAR.
* on every year that is evenly divisible by 4
IF FUNCTION MOD(WS-YEAR, 4) = 0
* except every year that is evenly divisible by 100
IF FUNCTION MOD(WS-YEAR, 100) = 0
* unless the year is also evenly divisible by 400
IF FUNCTION MOD(WS-YEAR, 400) = 0
MOVE 1 TO LEAP-YEAR
EXIT PARAGRAPH
ELSE
MOVE 0 TO LEAP-YEAR
EXIT PARAGRAPH
END-IF
MOVE 0 TO LEAP-YEAR
EXIT PARAGRAPH
ELSE
MOVE 1 TO LEAP-YEAR
EXIT PARAGRAPH
END-IF.


FIND-WEEKDAYS.
* moves date that matches day of week to table
MOVE 1 TO NO-OF-WDS.
PERFORM VARYING ITER FROM 1 BY 1 UNTIL ITER > 31
MOVE WS-YEAR TO MY-DATE(1:4)
MOVE WS-MONTH TO MY-DATE(5:2)
MOVE ITER TO MY-DATE(7:2)
PERFORM GET-WEEKDAY
IF WS-DAYOFWEEK IS EQUAL TO WEEKDAY
MOVE ITER TO WEEKDAYS-T(NO-OF-WDS)
ADD 1 TO NO-OF-WDS
END-IF
END-PERFORM.
* find teenth
PERFORM VARYING ITER FROM 13 BY 1 UNTIL ITER = 20
MOVE WS-YEAR TO MY-DATE(1:4)
MOVE WS-MONTH TO MY-DATE(5:2)
MOVE ITER TO MY-DATE(7:2)
PERFORM GET-WEEKDAY
IF WS-DAYOFWEEK IS EQUAL TO WEEKDAY
MOVE ITER TO WEEKDAYS-T(6)
END-IF
END-PERFORM.
63 changes: 63 additions & 0 deletions exercises/practice/meetup/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/meetup/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

0 comments on commit bb597be

Please sign in to comment.