-
-
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.
1 new exercise: robot-simulator (#139)
* adding robot-simulator, removing redundant introduction.md files * update config.json
- Loading branch information
Showing
15 changed files
with
653 additions
and
122 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 was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
exercises/practice/protein-translation/.docs/introduction.md
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
# Instructions | ||
|
||
Write a robot simulator. | ||
|
||
A robot factory's test facility needs a program to verify robot movements. | ||
|
||
The robots have three possible movements: | ||
|
||
- turn right | ||
- turn left | ||
- advance | ||
|
||
Robots are placed on a hypothetical infinite grid, facing a particular direction (north, east, south, or west) at a set of {x,y} coordinates, | ||
e.g., {3,8}, with coordinates increasing to the north and east. | ||
|
||
The robot then receives a number of instructions, at which point the testing facility verifies the robot's new position, and in which direction it is pointing. | ||
|
||
- The letter-string "RAALAL" means: | ||
- Turn right | ||
- Advance twice | ||
- Turn left | ||
- Advance once | ||
- Turn left yet again | ||
- Say a robot starts at {7, 3} facing north. | ||
Then running this stream of instructions should leave it at {9, 4} facing west. |
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,22 @@ | ||
{ | ||
"authors": [ | ||
"kapitaali" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/robot-simulator.cob" | ||
], | ||
"test": [ | ||
"tst/robot-simulator/robot-simulator.cut" | ||
], | ||
"example": [ | ||
".meta/proof.ci.cob" | ||
], | ||
"invalidator": [ | ||
"test.sh", | ||
"test.ps1" | ||
] | ||
}, | ||
"blurb": "Write a robot simulator.", | ||
"source": "Inspired by an interview question at a famous company." | ||
} |
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,68 @@ | ||
IDENTIFICATION DIVISION. | ||
PROGRAM-ID. ROBOT-SIMULATOR. | ||
AUTHOR. kapitaali. | ||
ENVIRONMENT DIVISION. | ||
DATA DIVISION. | ||
WORKING-STORAGE SECTION. | ||
01 WS-X-COORD PIC S999. | ||
01 WS-Y-COORD PIC S999. | ||
01 WS-DIRECTION PIC X(20). | ||
01 WS-INSTRUCTIONS PIC X(60). | ||
01 INSTRU PIC X. | ||
01 LEN PIC 99. | ||
01 CC PIC 99. | ||
|
||
|
||
PROCEDURE DIVISION. | ||
|
||
CREATE-ROBOT. | ||
CONTINUE. | ||
|
||
|
||
MOVE-ROBOT. | ||
PERFORM VARYING LEN FROM 60 BY -1 | ||
UNTIL WS-INSTRUCTIONS(LEN:1) IS NOT EQUAL TO " " | ||
CONTINUE | ||
END-PERFORM. | ||
PERFORM VARYING CC FROM 1 BY 1 UNTIL CC > LEN | ||
MOVE WS-INSTRUCTIONS(CC:1) TO INSTRU | ||
PERFORM PROCESS-INSTRUCTION | ||
END-PERFORM. | ||
|
||
|
||
PROCESS-INSTRUCTION. | ||
EVALUATE INSTRU | ||
WHEN 'L' | ||
EVALUATE WS-DIRECTION | ||
WHEN 'north' | ||
MOVE 'west' TO WS-DIRECTION | ||
WHEN 'west' | ||
MOVE 'south' TO WS-DIRECTION | ||
WHEN 'south' | ||
MOVE 'east' TO WS-DIRECTION | ||
WHEN 'east' | ||
MOVE 'north' TO WS-DIRECTION | ||
END-EVALUATE | ||
WHEN 'R' | ||
EVALUATE WS-DIRECTION | ||
WHEN 'north' | ||
MOVE 'east' TO WS-DIRECTION | ||
WHEN 'west' | ||
MOVE 'north' TO WS-DIRECTION | ||
WHEN 'south' | ||
MOVE 'west' TO WS-DIRECTION | ||
WHEN 'east' | ||
MOVE 'south' TO WS-DIRECTION | ||
END-EVALUATE | ||
WHEN 'A' | ||
EVALUATE WS-DIRECTION | ||
WHEN 'north' | ||
ADD 1 TO WS-Y-COORD | ||
WHEN 'east' | ||
ADD 1 TO WS-X-COORD | ||
WHEN 'south' | ||
SUBTRACT 1 FROM WS-Y-COORD | ||
WHEN 'west' | ||
SUBTRACT 1 FROM WS-X-COORD | ||
END-EVALUATE | ||
END-EVALUATE. |
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 |
28 changes: 28 additions & 0 deletions
28
exercises/practice/robot-simulator/bin/fetch-cobolcheck.ps1
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.