-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
12 changed files
with
462 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,8 @@ | ||
# Instructions | ||
|
||
Your task is to count the number of 1 bits in the binary representation of a number. | ||
|
||
## Restrictions | ||
|
||
Keep your hands off that bit-count functionality provided by your standard library! | ||
Solve this one yourself using other basic tools instead. |
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,47 @@ | ||
# Introduction | ||
|
||
Your friend Eliud inherited a farm from her grandma Tigist. | ||
Her granny was an inventor and had a tendency to build things in an overly complicated manner. | ||
The chicken coop has a digital display showing an encoded number representing the positions of all eggs that could be picked up. | ||
|
||
Eliud is asking you to write a program that shows the actual number of eggs in the coop. | ||
|
||
The position information encoding is calculated as follows: | ||
|
||
1. Scan the potential egg-laying spots and mark down a `1` for an existing egg or a `0` for an empty spot. | ||
2. Convert the number from binary to decimal. | ||
3. Show the result on the display. | ||
|
||
Example 1: | ||
|
||
```text | ||
Chicken Coop: | ||
_ _ _ _ _ _ _ | ||
|E| |E|E| | |E| | ||
Resulting Binary: | ||
1 0 1 1 0 0 1 | ||
Decimal number on the display: | ||
89 | ||
Actual eggs in the coop: | ||
4 | ||
``` | ||
|
||
Example 2: | ||
|
||
```text | ||
Chicken Coop: | ||
_ _ _ _ _ _ _ _ | ||
| | | |E| | | | | | ||
Resulting Binary: | ||
0 0 0 1 0 0 0 0 | ||
Decimal number on the display: | ||
16 | ||
Actual eggs in the coop: | ||
1 | ||
``` |
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,26 @@ | ||
{ | ||
"authors": [ | ||
"kapitaali" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/eliuds-eggs.cob" | ||
], | ||
"test": [ | ||
"tst/eliuds-eggs/eliuds-eggs.cut" | ||
], | ||
"example": [ | ||
".meta/proof.ci.cob" | ||
], | ||
"invalidator": [ | ||
"test.ps1", | ||
"test.sh", | ||
"bin/fetch-cobolcheck", | ||
"bin/fetch-cobolcheck.ps1", | ||
"config.properties" | ||
] | ||
}, | ||
"blurb": "Help Eliud count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation.", | ||
"source": "Christian Willner, Eric Willigers", | ||
"source_url": "https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5" | ||
} |
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,24 @@ | ||
IDENTIFICATION DIVISION. | ||
PROGRAM-ID. ELIUDS-EGGS. | ||
AUTHOR. kapitaali. | ||
ENVIRONMENT DIVISION. | ||
DATA DIVISION. | ||
WORKING-STORAGE SECTION. | ||
01 WS-INPUTVARS. | ||
05 WS-INPUT PIC 9(10). | ||
01 WS-OUTPUTVARS. | ||
05 WS-RESULT PIC 9999. | ||
|
||
01 MY-WORKVARS. | ||
05 REMAIN PIC 9. | ||
|
||
PROCEDURE DIVISION. | ||
|
||
EGG-COUNT. | ||
MOVE ZERO TO WS-RESULT. | ||
PERFORM UNTIL WS-INPUT = 0 | ||
DIVIDE WS-INPUT BY 2 GIVING WS-INPUT REMAINDER REMAIN | ||
IF REMAIN = 1 | ||
ADD 1 TO WS-RESULT | ||
END-IF | ||
END-PERFORM. |
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.