Skip to content

Commit bb597be

Browse files
committed
adding meetup
1 parent 8a480c0 commit bb597be

File tree

11 files changed

+1342
-0
lines changed

11 files changed

+1342
-0
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@
345345
"prerequisites": [],
346346
"difficulty": 2
347347
},
348+
{
349+
"slug": "meetup",
350+
"name": "Meetup",
351+
"uuid": "5eec226b-c30b-405d-9b6d-12cdf8ef4072",
352+
"practices": [],
353+
"prerequisites": [],
354+
"difficulty": 4
355+
},
348356
{
349357
"slug": "pascals-triangle",
350358
"name": "Pascal's Triangle",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Instructions
2+
3+
In this exercise, you will be given a general description of a meetup date and then asked to find the actual meetup date.
4+
5+
Examples of general descriptions are:
6+
7+
- First Monday of January 2022
8+
- Third Tuesday of August 2021
9+
- Teenth Wednesday of May 2022
10+
- Teenth Sunday of July 2021
11+
- Last Thursday of November 2021
12+
13+
The descriptors you are expected to process are: `first`, `second`, `third`, `fourth`, `fifth`, `last`, `teenth`.
14+
15+
Note that descriptor `teenth` is a made-up word.
16+
There are exactly seven numbered days in a month that end with "teenth" ("thirteenth" to "nineteenth").
17+
Therefore, it is guaranteed that each day of the week (Monday, Tuesday, ...) will have exactly one numbered day ending with "teenth" each month.
18+
19+
For example, if given "First Monday of January 2022", the correct meetup date is January 3, 2022.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"authors": [
3+
"kapitaali"
4+
],
5+
"files": {
6+
"solution": [
7+
"src/meetup.cob"
8+
],
9+
"test": [
10+
"tst/meetup/meetup.cut"
11+
],
12+
"example": [
13+
".meta/proof.ci.cob"
14+
],
15+
"invalidator": [
16+
"test.sh",
17+
"test.ps1"
18+
]
19+
},
20+
"blurb": "Calculate the date of meetups.",
21+
"source": "Jeremy Hinegardner mentioned a Boulder meetup that happens on the Wednesteenth of every month",
22+
"source_url": "https://twitter.com/copiousfreetime"
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
IDENTIFICATION DIVISION.
2+
PROGRAM-ID. MEETUP.
3+
AUTHOR. kapitaali.
4+
ENVIRONMENT DIVISION.
5+
DATA DIVISION.
6+
WORKING-STORAGE SECTION.
7+
01 WS-YEAR PIC 9999.
8+
01 WS-MONTH PIC 99.
9+
01 WS-WEEK PIC X(10).
10+
01 WS-DAYOFWEEK PIC X(10).
11+
01 WS-RESULT PIC X(40).
12+
01 WEEKDAY PIC X(10).
13+
01 MY-DATE PIC 9(8).
14+
01 SOME-FLD PIC 9999.
15+
01 MY-REM PIC 9999.
16+
01 ITER PIC 99.
17+
01 NO-OF-WDS PIC 9.
18+
01 LEAP-YEAR PIC 9.
19+
20+
01 Weekdaytable.
21+
02 WEEKDAYS-T PIC 99 OCCURS 6 TIMES.
22+
23+
24+
PROCEDURE DIVISION.
25+
26+
27+
GET-WEEKDAY.
28+
DIVIDE FUNCTION INTEGER-OF-DATE(MY-DATE) BY 7
29+
GIVING SOME-FLD REMAINDER MY-REM.
30+
EVALUATE MY-REM
31+
WHEN 0 MOVE 'Sunday' TO WEEKDAY
32+
WHEN 1 MOVE 'Monday' TO WEEKDAY
33+
WHEN 2 MOVE 'Tuesday' TO WEEKDAY
34+
WHEN 3 MOVE 'Wednesday' TO WEEKDAY
35+
WHEN 4 MOVE 'Thursday' TO WEEKDAY
36+
WHEN 5 MOVE 'Friday' TO WEEKDAY
37+
WHEN 6 MOVE 'Saturday' TO WEEKDAY
38+
END-EVALUATE.
39+
40+
41+
MEETUP.
42+
INITIALIZE Weekdaytable.
43+
MOVE ZEROES TO Weekdaytable.
44+
PERFORM FIND-WEEKDAYS.
45+
MOVE MY-DATE(1:4) TO WS-RESULT(1:4)
46+
MOVE '-' TO WS-RESULT(5:1)
47+
MOVE MY-DATE(5:2) TO WS-RESULT(6:2)
48+
MOVE '-' TO WS-RESULT(8:1)
49+
EVALUATE WS-WEEK
50+
WHEN "first"
51+
MOVE WEEKDAYS-T(1) TO WS-RESULT(9:2)
52+
WHEN "second"
53+
MOVE WEEKDAYS-T(2) TO WS-RESULT(9:2)
54+
WHEN "third"
55+
MOVE WEEKDAYS-T(3) TO WS-RESULT(9:2)
56+
WHEN "fourth"
57+
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
58+
WHEN "teenth"
59+
MOVE WEEKDAYS-T(6) TO WS-RESULT(9:2)
60+
WHEN "last"
61+
MOVE 0 TO LEAP-YEAR
62+
PERFORM IS-IT-LEAP-YEAR
63+
MOVE WEEKDAYS-T(5) TO ITER
64+
MOVE ITER TO WS-RESULT(9:2)
65+
IF ITER = 0 OR ITER > 31
66+
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
67+
END-IF
68+
IF WS-MONTH = 2 AND LEAP-YEAR = 1 AND ITER > 29
69+
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
70+
END-IF
71+
IF WS-MONTH = 2 AND LEAP-YEAR = 0 AND ITER > 28
72+
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
73+
END-IF
74+
IF WS-MONTH = 4 AND LEAP-YEAR = 0 AND ITER > 30
75+
MOVE WEEKDAYS-T(4) TO WS-RESULT(9:2)
76+
END-IF
77+
END-EVALUATE.
78+
79+
80+
IS-IT-LEAP-YEAR.
81+
* on every year that is evenly divisible by 4
82+
IF FUNCTION MOD(WS-YEAR, 4) = 0
83+
* except every year that is evenly divisible by 100
84+
IF FUNCTION MOD(WS-YEAR, 100) = 0
85+
* unless the year is also evenly divisible by 400
86+
IF FUNCTION MOD(WS-YEAR, 400) = 0
87+
MOVE 1 TO LEAP-YEAR
88+
EXIT PARAGRAPH
89+
ELSE
90+
MOVE 0 TO LEAP-YEAR
91+
EXIT PARAGRAPH
92+
END-IF
93+
MOVE 0 TO LEAP-YEAR
94+
EXIT PARAGRAPH
95+
ELSE
96+
MOVE 1 TO LEAP-YEAR
97+
EXIT PARAGRAPH
98+
END-IF.
99+
100+
101+
FIND-WEEKDAYS.
102+
* moves date that matches day of week to table
103+
MOVE 1 TO NO-OF-WDS.
104+
PERFORM VARYING ITER FROM 1 BY 1 UNTIL ITER > 31
105+
MOVE WS-YEAR TO MY-DATE(1:4)
106+
MOVE WS-MONTH TO MY-DATE(5:2)
107+
MOVE ITER TO MY-DATE(7:2)
108+
PERFORM GET-WEEKDAY
109+
IF WS-DAYOFWEEK IS EQUAL TO WEEKDAY
110+
MOVE ITER TO WEEKDAYS-T(NO-OF-WDS)
111+
ADD 1 TO NO-OF-WDS
112+
END-IF
113+
END-PERFORM.
114+
* find teenth
115+
PERFORM VARYING ITER FROM 13 BY 1 UNTIL ITER = 20
116+
MOVE WS-YEAR TO MY-DATE(1:4)
117+
MOVE WS-MONTH TO MY-DATE(5:2)
118+
MOVE ITER TO MY-DATE(7:2)
119+
PERFORM GET-WEEKDAY
120+
IF WS-DAYOFWEEK IS EQUAL TO WEEKDAY
121+
MOVE ITER TO WEEKDAYS-T(6)
122+
END-IF
123+
END-PERFORM.
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)