From 39a144c85aa4229345463280d4f61266350a6527 Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 8 Sep 2021 22:26:42 +0530 Subject: Raku: Acronym: Add solution --- README.org | 1 + raku/acronym/Acronym.rakumod | 5 +++ raku/acronym/HELP.md | 32 ++++++++++++++++ raku/acronym/README.md | 27 +++++++++++++ raku/acronym/acronym.rakutest | 89 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 raku/acronym/Acronym.rakumod create mode 100644 raku/acronym/HELP.md create mode 100644 raku/acronym/README.md create mode 100644 raku/acronym/acronym.rakutest diff --git a/README.org b/README.org index 7d5a0b0..8924540 100644 --- a/README.org +++ b/README.org @@ -88,6 +88,7 @@ My solutions for [[https://exercism.io][Exercism]] exercises. - [X] Luhn - [ ] Phone Number - [ ] RNA Transcription +- [ ] Acronym * Rust [2/3] diff --git a/raku/acronym/Acronym.rakumod b/raku/acronym/Acronym.rakumod new file mode 100644 index 0000000..401d867 --- /dev/null +++ b/raku/acronym/Acronym.rakumod @@ -0,0 +1,5 @@ +unit module Acronym; + +sub abbreviate(Str $phrase --> Str) is export { + $phrase.split((' ', '-'), :skip-empty).map(*.comb(/<[a..zA..Z]>/).first).join.uc +} diff --git a/raku/acronym/HELP.md b/raku/acronym/HELP.md new file mode 100644 index 0000000..dce79ca --- /dev/null +++ b/raku/acronym/HELP.md @@ -0,0 +1,32 @@ +# Help + +## Running the tests + +You can run the test suite for the exercise by executing the command +`prove6 .` in the exercise directory. + +## Submitting your solution + +You can submit your solution using the `exercism submit Acronym.rakumod` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Raku track's documentation](https://exercism.org/docs/tracks/raku) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Raku resources](https://raku.org/resources/) +- [/r/rakulang](https://www.reddit.com/r/rakulang) is the Raku subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/raku) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/raku/acronym/README.md b/raku/acronym/README.md new file mode 100644 index 0000000..d2ca89c --- /dev/null +++ b/raku/acronym/README.md @@ -0,0 +1,27 @@ +# Acronym + +Welcome to Acronym on Exercism's Raku Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## 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). + +## Source + +### Created by + +- @dcampos + +### Contributed to by + +- @m-dango + +### Based on + +Julien Vanier - https://github.com/monkbroc \ No newline at end of file diff --git a/raku/acronym/acronym.rakutest b/raku/acronym/acronym.rakutest new file mode 100644 index 0000000..fad0fe4 --- /dev/null +++ b/raku/acronym/acronym.rakutest @@ -0,0 +1,89 @@ +#!/usr/bin/env raku +use Test; +use JSON::Fast; +use lib $?FILE.IO.dirname; +use Acronym; +plan 9; + +my @test-cases = from-json($=pod[*-1].contents).List; +for @test-cases -> %case { + is abbreviate(%case), |%case; +} + +=head2 Test Cases +=begin code +[ + { + "description": "basic", + "expected": "PNG", + "input": { + "phrase": "Portable Network Graphics" + }, + "property": "abbreviate" + }, + { + "description": "lowercase words", + "expected": "ROR", + "input": { + "phrase": "Ruby on Rails" + }, + "property": "abbreviate" + }, + { + "description": "punctuation", + "expected": "FIFO", + "input": { + "phrase": "First In, First Out" + }, + "property": "abbreviate" + }, + { + "description": "all caps word", + "expected": "GIMP", + "input": { + "phrase": "GNU Image Manipulation Program" + }, + "property": "abbreviate" + }, + { + "description": "punctuation without whitespace", + "expected": "CMOS", + "input": { + "phrase": "Complementary metal-oxide semiconductor" + }, + "property": "abbreviate" + }, + { + "description": "very long abbreviation", + "expected": "ROTFLSHTMDCOALM", + "input": { + "phrase": "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me" + }, + "property": "abbreviate" + }, + { + "description": "consecutive delimiters", + "expected": "SIMUFTA", + "input": { + "phrase": "Something - I made up from thin air" + }, + "property": "abbreviate" + }, + { + "description": "apostrophes", + "expected": "HC", + "input": { + "phrase": "Halley's Comet" + }, + "property": "abbreviate" + }, + { + "description": "underscore emphasis", + "expected": "TRNT", + "input": { + "phrase": "The Road _Not_ Taken" + }, + "property": "abbreviate" + } +] +=end code -- cgit 1.4.1-2-gfad0