From 956d058f901877455d44fa7e8fda803c942ead9c Mon Sep 17 00:00:00 2001 From: J R M Date: Sun, 12 Apr 2026 18:25:02 +0200 Subject: [PATCH 1/3] acronym --- config.json | 8 ++++ .../practice/acronym/.docs/instructions.md | 17 +++++++++ exercises/practice/acronym/.meta/config.json | 19 ++++++++++ exercises/practice/acronym/.meta/example.nu | 14 +++++++ exercises/practice/acronym/.meta/tests.toml | 37 +++++++++++++++++++ exercises/practice/acronym/acronym.nu | 3 ++ exercises/practice/acronym/tests.nu | 11 ++++++ 7 files changed, 109 insertions(+) create mode 100644 exercises/practice/acronym/.docs/instructions.md create mode 100644 exercises/practice/acronym/.meta/config.json create mode 100644 exercises/practice/acronym/.meta/example.nu create mode 100644 exercises/practice/acronym/.meta/tests.toml create mode 100644 exercises/practice/acronym/acronym.nu create mode 100644 exercises/practice/acronym/tests.nu diff --git a/config.json b/config.json index 7933d6b..3166d2a 100644 --- a/config.json +++ b/config.json @@ -133,6 +133,14 @@ "practices": [], "prerequisites": [], "difficulty": 5 + }, + { + "slug": "acronym", + "name": "Acronym", + "uuid": "16ede285-40d5-4df8-a582-f35b4d121d3c", + "practices": [], + "prerequisites": [], + "difficulty": 3 } ] }, diff --git a/exercises/practice/acronym/.docs/instructions.md b/exercises/practice/acronym/.docs/instructions.md new file mode 100644 index 0000000..133bd2c --- /dev/null +++ b/exercises/practice/acronym/.docs/instructions.md @@ -0,0 +1,17 @@ +# Instructions + +Convert a phrase to its acronym. + +Techies love their TLA (Three Letter Acronyms)! + +Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG). + +Punctuation is handled as follows: hyphens are word separators (like whitespace); all other punctuation can be removed from the input. + +For example: + +| Input | Output | +| ------------------------- | ------ | +| As Soon As Possible | ASAP | +| Liquid-crystal display | LCD | +| Thank George It's Friday! | TGIF | diff --git a/exercises/practice/acronym/.meta/config.json b/exercises/practice/acronym/.meta/config.json new file mode 100644 index 0000000..37975f3 --- /dev/null +++ b/exercises/practice/acronym/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "quintuple-mallard" + ], + "files": { + "solution": [ + "acronym.nu" + ], + "test": [ + "tests.nu" + ], + "example": [ + ".meta/example.nu" + ] + }, + "blurb": "Convert a long phrase to its acronym.", + "source": "Julien Vanier", + "source_url": "https://github.com/monkbroc" +} diff --git a/exercises/practice/acronym/.meta/example.nu b/exercises/practice/acronym/.meta/example.nu new file mode 100644 index 0000000..2be0215 --- /dev/null +++ b/exercises/practice/acronym/.meta/example.nu @@ -0,0 +1,14 @@ +def alphabetic [c: string] { + let c = $c | str downcase + $c >= a and $c <= z +} +export def abbreviate [phrase: string] { + $phrase + | split chars + | where (alphabetic $it) or $it in " -" + | str join + | split row -r "[ -]" + | each {|w| $w | split chars | first} + | str join + | str upcase +} diff --git a/exercises/practice/acronym/.meta/tests.toml b/exercises/practice/acronym/.meta/tests.toml new file mode 100644 index 0000000..6e3277c --- /dev/null +++ b/exercises/practice/acronym/.meta/tests.toml @@ -0,0 +1,37 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[1e22cceb-c5e4-4562-9afe-aef07ad1eaf4] +description = "basic" + +[79ae3889-a5c0-4b01-baf0-232d31180c08] +description = "lowercase words" + +[ec7000a7-3931-4a17-890e-33ca2073a548] +description = "punctuation" + +[32dd261c-0c92-469a-9c5c-b192e94a63b0] +description = "all caps word" + +[ae2ac9fa-a606-4d05-8244-3bcc4659c1d4] +description = "punctuation without whitespace" + +[0e4b1e7c-1a6d-48fb-81a7-bf65eb9e69f9] +description = "very long abbreviation" + +[6a078f49-c68d-4b7b-89af-33a1a98c28cc] +description = "consecutive delimiters" + +[5118b4b1-4572-434c-8d57-5b762e57973e] +description = "apostrophes" + +[adc12eab-ec2d-414f-b48c-66a4fc06cdef] +description = "underscore emphasis" diff --git a/exercises/practice/acronym/acronym.nu b/exercises/practice/acronym/acronym.nu new file mode 100644 index 0000000..824b84d --- /dev/null +++ b/exercises/practice/acronym/acronym.nu @@ -0,0 +1,3 @@ +export def abbreviate [phrase: string] { + error make {msg: "Please implement abbreviate"} +} diff --git a/exercises/practice/acronym/tests.nu b/exercises/practice/acronym/tests.nu new file mode 100644 index 0000000..34784f0 --- /dev/null +++ b/exercises/practice/acronym/tests.nu @@ -0,0 +1,11 @@ +use acronym.nu abbreviate +use std/assert +assert equal (abbreviate "Portable Network Graphics") "PNG" +assert equal (abbreviate "Ruby on Rails") "ROR" +assert equal (abbreviate "First In, First Out") "FIFO" +assert equal (abbreviate "GNU Image Manipulation Program") "GIMP" +assert equal (abbreviate "Complementary metal-oxide semiconductor") "CMOS" +assert equal (abbreviate "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me") "ROTFLSHTMDCOALM" +assert equal (abbreviate "Something - I made up from thin air") "SIMUFTA" +assert equal (abbreviate "Halley's Comet") "HC" +assert equal (abbreviate "The Road _Not_ Taken") "TRNT" From 3ba89b45ea1f0c3969425aa205c5bbc0a8a849ad Mon Sep 17 00:00:00 2001 From: J R M Date: Sat, 13 Jun 2026 18:45:59 +0200 Subject: [PATCH 2/3] robot-simulator --- config.json | 10 ++- .../robot-simulator/.docs/instructions.md | 25 +++++++ .../robot-simulator/.meta/config.json | 18 +++++ .../practice/robot-simulator/.meta/example.nu | 27 ++++++++ .../practice/robot-simulator/.meta/tests.toml | 66 +++++++++++++++++++ .../robot-simulator/robot-simulator.nu | 4 ++ exercises/practice/robot-simulator/tests.nu | 49 ++++++++++++++ 7 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 exercises/practice/robot-simulator/.docs/instructions.md create mode 100644 exercises/practice/robot-simulator/.meta/config.json create mode 100644 exercises/practice/robot-simulator/.meta/example.nu create mode 100644 exercises/practice/robot-simulator/.meta/tests.toml create mode 100644 exercises/practice/robot-simulator/robot-simulator.nu create mode 100644 exercises/practice/robot-simulator/tests.nu diff --git a/config.json b/config.json index 3166d2a..b4fcfee 100644 --- a/config.json +++ b/config.json @@ -141,6 +141,14 @@ "practices": [], "prerequisites": [], "difficulty": 3 + }, + { + "slug": "robot-simulator", + "name": "Robot Simulator", + "uuid": "26025a1c-21b8-428b-80a1-6068fbdf7834", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ] }, @@ -154,4 +162,4 @@ "typing/static", "used_for/scripts" ] -} \ No newline at end of file +} diff --git a/exercises/practice/robot-simulator/.docs/instructions.md b/exercises/practice/robot-simulator/.docs/instructions.md new file mode 100644 index 0000000..0ac96ce --- /dev/null +++ b/exercises/practice/robot-simulator/.docs/instructions.md @@ -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. diff --git a/exercises/practice/robot-simulator/.meta/config.json b/exercises/practice/robot-simulator/.meta/config.json new file mode 100644 index 0000000..418cca4 --- /dev/null +++ b/exercises/practice/robot-simulator/.meta/config.json @@ -0,0 +1,18 @@ +{ + "authors": [ + "quintuple-mallard" + ], + "files": { + "solution": [ + "robot-simulator.nu" + ], + "test": [ + "tests.nu" + ], + "example": [ + ".meta/example.nu" + ] + }, + "blurb": "Write a robot simulator.", + "source": "Inspired by an interview question at a famous company." +} diff --git a/exercises/practice/robot-simulator/.meta/example.nu b/exercises/practice/robot-simulator/.meta/example.nu new file mode 100644 index 0000000..00eda89 --- /dev/null +++ b/exercises/practice/robot-simulator/.meta/example.nu @@ -0,0 +1,27 @@ +const directions: list = [north east south west] +const offsets: list> = [[0 1] [1 0] [0 -1] [-1 0]] +def indexof [item: any]: list -> number { + $in | enumerate | where $it.item == $item | get index.0 +} +def advance [robot: record, direction: string>] { + let change = $offsets | get ($directions | indexof $robot.direction | into cell-path) + $robot | update position ({x: ($robot.position.x + $change.0), y: ($robot.position.y + $change.1)}) +} +def turnr [robot: record, direction: string>] { + let idx = $directions | indexof $robot.direction + $robot | update direction ($directions | get (($idx + 1) mod 4 | into cell-path)) +} +def turnl [robot: record, direction: string>] { + let idx = $directions | indexof $robot.direction + $robot | update direction ($directions | get (($idx - 1) mod 4 | into cell-path)) +} +export def run [instructions: string]: record, direction: string> -> record, direction: string> { + let robot = $in + $instructions | split chars | reduce --fold $robot {|c, robot| + match $c { + "A" => (advance $robot), + "R" => (turnr $robot), + "L" => (turnl $robot), + } + } +} diff --git a/exercises/practice/robot-simulator/.meta/tests.toml b/exercises/practice/robot-simulator/.meta/tests.toml new file mode 100644 index 0000000..f2e52b1 --- /dev/null +++ b/exercises/practice/robot-simulator/.meta/tests.toml @@ -0,0 +1,66 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[c557c16d-26c1-4e06-827c-f6602cd0785c] +description = "Create robot -> at origin facing north" +include = false + +[bf0dffce-f11c-4cdb-8a5e-2c89d8a5a67d] +description = "Create robot -> at negative position facing south" +include = false + +[8cbd0086-6392-4680-b9b9-73cf491e67e5] +description = "Rotating clockwise -> changes north to east" + +[8abc87fc-eab2-4276-93b7-9c009e866ba1] +description = "Rotating clockwise -> changes east to south" + +[3cfe1b85-bbf2-4bae-b54d-d73e7e93617a] +description = "Rotating clockwise -> changes south to west" + +[5ea9fb99-3f2c-47bd-86f7-46b7d8c3c716] +description = "Rotating clockwise -> changes west to north" + +[fa0c40f5-6ba3-443d-a4b3-58cbd6cb8d63] +description = "Rotating counter-clockwise -> changes north to west" + +[da33d734-831f-445c-9907-d66d7d2a92e2] +description = "Rotating counter-clockwise -> changes west to south" + +[bd1ca4b9-4548-45f4-b32e-900fc7c19389] +description = "Rotating counter-clockwise -> changes south to east" + +[2de27b67-a25c-4b59-9883-bc03b1b55bba] +description = "Rotating counter-clockwise -> changes east to north" + +[f0dc2388-cddc-4f83-9bed-bcf46b8fc7b8] +description = "Moving forward one -> facing north increments Y" + +[2786cf80-5bbf-44b0-9503-a89a9c5789da] +description = "Moving forward one -> facing south decrements Y" + +[84bf3c8c-241f-434d-883d-69817dbd6a48] +description = "Moving forward one -> facing east increments X" + +[bb69c4a7-3bbf-4f64-b415-666fa72d7b04] +description = "Moving forward one -> facing west decrements X" + +[e34ac672-4ed4-4be3-a0b8-d9af259cbaa1] +description = "Follow series of instructions -> moving east and north from README" + +[f30e4955-4b47-4aa3-8b39-ae98cfbd515b] +description = "Follow series of instructions -> moving west and north" + +[3e466bf6-20ab-4d79-8b51-264165182fca] +description = "Follow series of instructions -> moving west and south" + +[41f0bb96-c617-4e6b-acff-a4b279d44514] +description = "Follow series of instructions -> moving east and north" diff --git a/exercises/practice/robot-simulator/robot-simulator.nu b/exercises/practice/robot-simulator/robot-simulator.nu new file mode 100644 index 0000000..a45db0d --- /dev/null +++ b/exercises/practice/robot-simulator/robot-simulator.nu @@ -0,0 +1,4 @@ +export def run [instructions: string]: record, direction: string> -> record, direction: string> { + error make {msg: "Remove this line and implement grep"} + {position: {x: 0, y: 0}, direction: north} +} diff --git a/exercises/practice/robot-simulator/tests.nu b/exercises/practice/robot-simulator/tests.nu new file mode 100644 index 0000000..441dc2b --- /dev/null +++ b/exercises/practice/robot-simulator/tests.nu @@ -0,0 +1,49 @@ +use robot-simulator.nu run +use std/assert +# changes north to east +assert equal ({position: {x: 0, y: 0}, direction: north} | run R) {position: {x: 0, y: 0}, direction: east} + +# changes east to south +assert equal ({position: {x: 0, y: 0}, direction: east} | run R) {position: {x: 0, y: 0}, direction: south} + +# changes south to west +assert equal ({position: {x: 0, y: 0}, direction: south} | run R) {position: {x: 0, y: 0}, direction: west} + +# changes west to north +assert equal ({position: {x: 0, y: 0}, direction: west} | run R) {position: {x: 0, y: 0}, direction: north} + +# changes north to west +assert equal ({position: {x: 0, y: 0}, direction: north} | run L) {position: {x: 0, y: 0}, direction: west} + +# changes west to south +assert equal ({position: {x: 0, y: 0}, direction: west} | run L) {position: {x: 0, y: 0}, direction: south} + +# changes south to east +assert equal ({position: {x: 0, y: 0}, direction: south} | run L) {position: {x: 0, y: 0}, direction: east} + +# changes east to north +assert equal ({position: {x: 0, y: 0}, direction: east} | run L) {position: {x: 0, y: 0}, direction: north} + +# facing north increments Y +assert equal ({position: {x: 0, y: 0}, direction: north} | run A) {position: {x: 0, y: 1}, direction: north} + +# facing south decrements Y +assert equal ({position: {x: 0, y: 0}, direction: south} | run A) {position: {x: 0, y: -1}, direction: south} + +# facing east increments X +assert equal ({position: {x: 0, y: 0}, direction: east} | run A) {position: {x: 1, y: 0}, direction: east} + +# facing west decrements X +assert equal ({position: {x: 0, y: 0}, direction: west} | run A) {position: {x: -1, y: 0}, direction: west} + +# moving east and north from README +assert equal ({position: {x: 7, y: 3}, direction: north} | run RAALAL) {position: {x: 9, y: 4}, direction: west} + +# moving west and north +assert equal ({position: {x: 0, y: 0}, direction: north} | run LAAARALA) {position: {x: -4, y: 1}, direction: west} + +# moving west and south +assert equal ({position: {x: 2, y: -7}, direction: east} | run RRAAAAALA) {position: {x: -3, y: -8}, direction: south} + +# moving east and north +assert equal ({position: {x: 8, y: 4}, direction: south} | run LAAARRRALLLL) {position: {x: 11, y: 5}, direction: north} From 204ef1eb7fc4e24aa93fc2a6dede8ec0a640e405 Mon Sep 17 00:00:00 2001 From: J R M Date: Sun, 14 Jun 2026 12:05:23 +0200 Subject: [PATCH 3/3] difficulty --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index b4fcfee..6c35fea 100644 --- a/config.json +++ b/config.json @@ -148,7 +148,7 @@ "uuid": "26025a1c-21b8-428b-80a1-6068fbdf7834", "practices": [], "prerequisites": [], - "difficulty": 1 + "difficulty": 3 } ] }, @@ -162,4 +162,4 @@ "typing/static", "used_for/scripts" ] -} +} \ No newline at end of file