Skip to content

Commit 43e2452

Browse files
Add acronym exercise (#67)
1 parent 42d3c37 commit 43e2452

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@
105105
"prerequisites": [],
106106
"difficulty": 2
107107
},
108+
{
109+
"slug": "acronym",
110+
"name": "Acronym",
111+
"uuid": "970bea05-1a05-4f88-9401-2977b8358f5d",
112+
"practices": [],
113+
"prerequisites": [],
114+
"difficulty": 3
115+
},
108116
{
109117
"slug": "binary-search",
110118
"name": "Binary Search",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Instructions
2+
3+
Convert a phrase to its acronym.
4+
5+
Techies love their TLA (Three Letter Acronyms)!
6+
7+
Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).
8+
9+
Punctuation is handled as follows: hyphens are word separators (like whitespace); all other punctuation can be removed from the input.
10+
11+
For example:
12+
13+
| Input | Output |
14+
| ------------------------- | ------ |
15+
| As Soon As Possible | ASAP |
16+
| Liquid-crystal display | LCD |
17+
| Thank George It's Friday! | TGIF |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"keiravillekode"
4+
],
5+
"files": {
6+
"solution": [
7+
"acronym.fut"
8+
],
9+
"test": [
10+
"test.fut"
11+
],
12+
"example": [
13+
".meta/example.fut"
14+
]
15+
},
16+
"blurb": "Convert a long phrase to its acronym.",
17+
"source": "Julien Vanier",
18+
"source_url": "https://github.com/monkbroc"
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def abbreviate (phrase: []u8): []u8 =
2+
let (result, _) = loop (result, letter) = ("", false) for ch in phrase do
3+
if ch == '\'' then (result, letter) else
4+
if (ch & 223) - 'A' >= 26 then (result, false) else
5+
if letter then (result, true) else
6+
(result ++ [ch & 223], true)
7+
in
8+
result
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[1e22cceb-c5e4-4562-9afe-aef07ad1eaf4]
13+
description = "basic"
14+
15+
[79ae3889-a5c0-4b01-baf0-232d31180c08]
16+
description = "lowercase words"
17+
18+
[ec7000a7-3931-4a17-890e-33ca2073a548]
19+
description = "punctuation"
20+
21+
[32dd261c-0c92-469a-9c5c-b192e94a63b0]
22+
description = "all caps word"
23+
24+
[ae2ac9fa-a606-4d05-8244-3bcc4659c1d4]
25+
description = "punctuation without whitespace"
26+
27+
[0e4b1e7c-1a6d-48fb-81a7-bf65eb9e69f9]
28+
description = "very long abbreviation"
29+
30+
[6a078f49-c68d-4b7b-89af-33a1a98c28cc]
31+
description = "consecutive delimiters"
32+
33+
[5118b4b1-4572-434c-8d57-5b762e57973e]
34+
description = "apostrophes"
35+
36+
[adc12eab-ec2d-414f-b48c-66a4fc06cdef]
37+
description = "underscore emphasis"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def abbreviate (phrase: []u8): []u8 = ???

exercises/practice/acronym/test.fut

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import "acronym"
2+
3+
-- basic
4+
-- ==
5+
-- input { "Portable Network Graphics" }
6+
-- output { "PNG" }
7+
8+
-- lowercase words
9+
-- ==
10+
-- input { "Ruby on Rails" }
11+
-- output { "ROR" }
12+
13+
-- punctuation
14+
-- ==
15+
-- input { "First In, First Out" }
16+
-- output { "FIFO" }
17+
18+
-- all caps word
19+
-- ==
20+
-- input { "GNU Image Manipulation Program" }
21+
-- output { "GIMP" }
22+
23+
-- punctuation without whitespace
24+
-- ==
25+
-- input { "Complementary metal-oxide semiconductor" }
26+
-- output { "CMOS" }
27+
28+
-- very long abbreviation
29+
-- ==
30+
-- input { "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me" }
31+
-- output { "ROTFLSHTMDCOALM" }
32+
33+
-- consecutive delimiters
34+
-- ==
35+
-- input { "Something - I made up from thin air" }
36+
-- output { "SIMUFTA" }
37+
38+
-- apostrophes
39+
-- ==
40+
-- input { "Halley's Comet" }
41+
-- output { "HC" }
42+
43+
-- underscore emphasis
44+
-- ==
45+
-- input { "The Road _Not_ Taken" }
46+
-- output { "TRNT" }
47+
48+
def main (phrase: []u8): []u8 =
49+
abbreviate phrase

0 commit comments

Comments
 (0)