Skip to content

Commit ad6fa32

Browse files
Add acronym exercise (#53)
1 parent 4303d76 commit ad6fa32

File tree

14 files changed

+521
-0
lines changed

14 files changed

+521
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
"prerequisites": [],
6666
"difficulty": 1
6767
},
68+
{
69+
"slug": "acronym",
70+
"name": "Acronym",
71+
"uuid": "d7e61409-7640-4323-be6a-278f77d5c585",
72+
"practices": [],
73+
"prerequisites": [],
74+
"difficulty": 2
75+
},
6876
{
6977
"slug": "bob",
7078
"name": "Bob",
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Acronym
2+
3+
def abbreviate (phrase : String) : String :=
4+
let rec helper (input : List Char) (acc : List Char) (inWord : Bool) : String :=
5+
match input with
6+
| [] => (List.reverse acc).asString
7+
| c :: rest =>
8+
if Char.isAlpha c && !inWord
9+
then helper rest ((Char.toUpper c) :: acc) true
10+
else helper rest acc ((Char.isAlpha c) || (inWord && c == '\''))
11+
helper phrase.toList [] false
12+
13+
end Acronym
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.lean"
8+
],
9+
"test": [
10+
"AcronymTest.lean"
11+
],
12+
"example": [
13+
".meta/Example.lean"
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: 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Acronym
2+
3+
def abbreviate (phrase : String) : String :=
4+
sorry
5+
6+
end Acronym
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import LeanTest
2+
import Acronym
3+
4+
open LeanTest
5+
6+
def acronymTests : TestSuite :=
7+
(TestSuite.empty "Acronym")
8+
|>.addTest "basic" (do
9+
return assertEqual "PNG" (Acronym.abbreviate "Portable Network Graphics"))
10+
|>.addTest "lowercase words" (do
11+
return assertEqual "ROR" (Acronym.abbreviate "Ruby on Rails"))
12+
|>.addTest "punctuation" (do
13+
return assertEqual "FIFO" (Acronym.abbreviate "First In, First Out"))
14+
|>.addTest "all caps word" (do
15+
return assertEqual "GIMP" (Acronym.abbreviate "GNU Image Manipulation Program"))
16+
|>.addTest "punctuation without whitespace" (do
17+
return assertEqual "CMOS" (Acronym.abbreviate "Complementary metal-oxide semiconductor"))
18+
|>.addTest "very long abbreviation" (do
19+
return assertEqual "ROTFLSHTMDCOALM" (Acronym.abbreviate "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"))
20+
|>.addTest "consecutive delimiters" (do
21+
return assertEqual "SIMUFTA" (Acronym.abbreviate "Something - I made up from thin air"))
22+
|>.addTest "apostrophes" (do
23+
return assertEqual "HC" (Acronym.abbreviate "Halley's Comet"))
24+
|>.addTest "underscore emphasis" (do
25+
return assertEqual "TRNT" (Acronym.abbreviate "The Road _Not_ Taken"))
26+
27+
def main : IO UInt32 := do
28+
runTestSuitesWithExitCode [acronymTests]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name = "acronym"
2+
version = "0.1.0"
3+
defaultTargets = ["AcronymTest"]
4+
testDriver = "AcronymTest"
5+
6+
[[lean_lib]]
7+
name = "LeanTest"
8+
srcDir = "vendor/LeanTest"
9+
10+
[[lean_lib]]
11+
name = "Acronym"
12+
13+
[[lean_exe]]
14+
name = "AcronymTest"
15+
root = "AcronymTest"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
leanprover/lean4:v4.25.2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- This module serves as the root of the `LeanTest` library.
2+
-- Import modules here that should be built as part of the library.
3+
import LeanTest.Assertions
4+
import LeanTest.Test

0 commit comments

Comments
 (0)