Skip to content

Commit 1cf2e6e

Browse files
authored
Add isogram exercise (#531)
1 parent efcf98e commit 1cf2e6e

File tree

13 files changed

+212
-0
lines changed

13 files changed

+212
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,14 @@
557557
"practices": [],
558558
"prerequisites": [],
559559
"difficulty": 4
560+
},
561+
{
562+
"slug": "isogram",
563+
"name": "Isogram",
564+
"uuid": "fe419d81-481d-49af-8e24-80defb0692f2",
565+
"practices": [],
566+
"prerequisites": [],
567+
"difficulty": 3
560568
}
561569
]
562570
},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Instructions
2+
3+
Determine if a word or phrase is an isogram.
4+
5+
An isogram (also known as a "non-pattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.
6+
7+
Examples of isograms:
8+
9+
- lumberjacks
10+
- background
11+
- downstream
12+
- six-year-old
13+
14+
The word _isograms_, however, is not an isogram, because the s repeats.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"authors": [
3+
"kahgoh"
4+
],
5+
"files": {
6+
"solution": [
7+
"isogram.ml"
8+
],
9+
"test": [
10+
"test.ml"
11+
],
12+
"example": [
13+
".meta/example.ml"
14+
],
15+
"editor": [
16+
"isogram.mli"
17+
]
18+
},
19+
"blurb": "Determine if a word or phrase is an isogram.",
20+
"source": "Wikipedia",
21+
"source_url": "https://en.wikipedia.org/wiki/Isogram"
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let tail (word: string) =
2+
String.sub word 1 ((String.length word) - 1)
3+
4+
let rec is_unique (ch: char) (word: string) : bool =
5+
match (ch, word) with
6+
| (_, "") -> true
7+
| (c, w) when c < 'a' || c > 'z' -> is_unique (String.get w 0) (tail w)
8+
| (c, w) when (String.contains w c) -> false
9+
| (_, w) -> is_unique (String.get w 0) (tail w)
10+
11+
let is_isogram (word: string) : bool =
12+
let lower_word = String.lowercase_ascii word in
13+
match lower_word with
14+
| "" -> true
15+
| w -> is_unique(String.get w 0) (tail w)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
[a0e97d2d-669e-47c7-8134-518a1e2c4555]
13+
description = "empty string"
14+
15+
[9a001b50-f194-4143-bc29-2af5ec1ef652]
16+
description = "isogram with only lower case characters"
17+
18+
[8ddb0ca3-276e-4f8b-89da-d95d5bae78a4]
19+
description = "word with one duplicated character"
20+
21+
[6450b333-cbc2-4b24-a723-0b459b34fe18]
22+
description = "word with one duplicated character from the end of the alphabet"
23+
24+
[a15ff557-dd04-4764-99e7-02cc1a385863]
25+
description = "longest reported english isogram"
26+
27+
[f1a7f6c7-a42f-4915-91d7-35b2ea11c92e]
28+
description = "word with duplicated character in mixed case"
29+
30+
[14a4f3c1-3b47-4695-b645-53d328298942]
31+
description = "word with duplicated character in mixed case, lowercase first"
32+
33+
[423b850c-7090-4a8a-b057-97f1cadd7c42]
34+
description = "hypothetical isogrammic word with hyphen"
35+
36+
[93dbeaa0-3c5a-45c2-8b25-428b8eacd4f2]
37+
description = "hypothetical word with duplicated character following hyphen"
38+
39+
[36b30e5c-173f-49c6-a515-93a3e825553f]
40+
description = "isogram with duplicated hyphen"
41+
42+
[cdabafa0-c9f4-4c1f-b142-689c6ee17d93]
43+
description = "made-up name that is an isogram"
44+
45+
[5fc61048-d74e-48fd-bc34-abfc21552d4d]
46+
description = "duplicated character in the middle"
47+
48+
[310ac53d-8932-47bc-bbb4-b2b94f25a83e]
49+
description = "same first and last characters"
50+
51+
[0d0b8644-0a1e-4a31-a432-2b3ee270d847]
52+
description = "word with duplicated character and with two hyphens"

exercises/practice/isogram/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
default: clean test
2+
3+
test:
4+
dune runtest
5+
6+
clean:
7+
dune clean
8+
9+
.PHONY: clean

exercises/practice/isogram/dune

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(executable
2+
(name test)
3+
(libraries base ounit2))
4+
5+
(alias
6+
(name runtest)
7+
(deps (:x test.exe))
8+
(action (run %{x})))
9+
10+
(alias
11+
(name buildtest)
12+
(deps (:x test.exe)))
13+
14+
(env
15+
(dev
16+
(flags (:standard -warn-error -A))))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(lang dune 1.1)
2+
(version 1.0)

exercises/practice/isogram/isogram.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let is_isogram (word: string) : bool =
2+
failwith "'is_isogram' is missing"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val is_isogram : string -> bool

0 commit comments

Comments
 (0)