Skip to content

Commit 8a480c0

Browse files
authored
1 new exercise: robot-simulator (#139)
* adding robot-simulator, removing redundant introduction.md files * update config.json
1 parent ba62b36 commit 8a480c0

File tree

15 files changed

+653
-122
lines changed

15 files changed

+653
-122
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@
337337
"prerequisites": [],
338338
"difficulty": 1
339339
},
340+
{
341+
"slug": "robot-simulator",
342+
"name": "Robot Simulator",
343+
"uuid": "aa8d3ec5-da37-45e2-87c2-ec94eacf6cb4",
344+
"practices": [],
345+
"prerequisites": [],
346+
"difficulty": 2
347+
},
340348
{
341349
"slug": "pascals-triangle",
342350
"name": "Pascal's Triangle",

exercises/practice/binary-search/.docs/introduction.md

-35
This file was deleted.

exercises/practice/protein-translation/.docs/introduction.md

-42
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Instructions
2+
3+
Write a robot simulator.
4+
5+
A robot factory's test facility needs a program to verify robot movements.
6+
7+
The robots have three possible movements:
8+
9+
- turn right
10+
- turn left
11+
- advance
12+
13+
Robots are placed on a hypothetical infinite grid, facing a particular direction (north, east, south, or west) at a set of {x,y} coordinates,
14+
e.g., {3,8}, with coordinates increasing to the north and east.
15+
16+
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.
17+
18+
- The letter-string "RAALAL" means:
19+
- Turn right
20+
- Advance twice
21+
- Turn left
22+
- Advance once
23+
- Turn left yet again
24+
- Say a robot starts at {7, 3} facing north.
25+
Then running this stream of instructions should leave it at {9, 4} facing west.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"authors": [
3+
"kapitaali"
4+
],
5+
"files": {
6+
"solution": [
7+
"src/robot-simulator.cob"
8+
],
9+
"test": [
10+
"tst/robot-simulator/robot-simulator.cut"
11+
],
12+
"example": [
13+
".meta/proof.ci.cob"
14+
],
15+
"invalidator": [
16+
"test.sh",
17+
"test.ps1"
18+
]
19+
},
20+
"blurb": "Write a robot simulator.",
21+
"source": "Inspired by an interview question at a famous company."
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
IDENTIFICATION DIVISION.
2+
PROGRAM-ID. ROBOT-SIMULATOR.
3+
AUTHOR. kapitaali.
4+
ENVIRONMENT DIVISION.
5+
DATA DIVISION.
6+
WORKING-STORAGE SECTION.
7+
01 WS-X-COORD PIC S999.
8+
01 WS-Y-COORD PIC S999.
9+
01 WS-DIRECTION PIC X(20).
10+
01 WS-INSTRUCTIONS PIC X(60).
11+
01 INSTRU PIC X.
12+
01 LEN PIC 99.
13+
01 CC PIC 99.
14+
15+
16+
PROCEDURE DIVISION.
17+
18+
CREATE-ROBOT.
19+
CONTINUE.
20+
21+
22+
MOVE-ROBOT.
23+
PERFORM VARYING LEN FROM 60 BY -1
24+
UNTIL WS-INSTRUCTIONS(LEN:1) IS NOT EQUAL TO " "
25+
CONTINUE
26+
END-PERFORM.
27+
PERFORM VARYING CC FROM 1 BY 1 UNTIL CC > LEN
28+
MOVE WS-INSTRUCTIONS(CC:1) TO INSTRU
29+
PERFORM PROCESS-INSTRUCTION
30+
END-PERFORM.
31+
32+
33+
PROCESS-INSTRUCTION.
34+
EVALUATE INSTRU
35+
WHEN 'L'
36+
EVALUATE WS-DIRECTION
37+
WHEN 'north'
38+
MOVE 'west' TO WS-DIRECTION
39+
WHEN 'west'
40+
MOVE 'south' TO WS-DIRECTION
41+
WHEN 'south'
42+
MOVE 'east' TO WS-DIRECTION
43+
WHEN 'east'
44+
MOVE 'north' TO WS-DIRECTION
45+
END-EVALUATE
46+
WHEN 'R'
47+
EVALUATE WS-DIRECTION
48+
WHEN 'north'
49+
MOVE 'east' TO WS-DIRECTION
50+
WHEN 'west'
51+
MOVE 'north' TO WS-DIRECTION
52+
WHEN 'south'
53+
MOVE 'west' TO WS-DIRECTION
54+
WHEN 'east'
55+
MOVE 'south' TO WS-DIRECTION
56+
END-EVALUATE
57+
WHEN 'A'
58+
EVALUATE WS-DIRECTION
59+
WHEN 'north'
60+
ADD 1 TO WS-Y-COORD
61+
WHEN 'east'
62+
ADD 1 TO WS-X-COORD
63+
WHEN 'south'
64+
SUBTRACT 1 FROM WS-Y-COORD
65+
WHEN 'west'
66+
SUBTRACT 1 FROM WS-X-COORD
67+
END-EVALUATE
68+
END-EVALUATE.
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)