-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
parallel-letter-frequency
exercise
- Loading branch information
1 parent
be7f6ff
commit 696aa0a
Showing
7 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
exercises/practice/parallel-letter-frequency/.docs/instructions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Instructions | ||
|
||
Count the frequency of letters in texts using parallel computation. | ||
|
||
Parallelism is about doing things in parallel that can also be done sequentially. | ||
A common example is counting the frequency of letters. | ||
Employ parallelism to calculate the total frequency of each letter in a list of texts. |
17 changes: 17 additions & 0 deletions
17
exercises/practice/parallel-letter-frequency/.meta/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"authors": [ | ||
"erikschierboom" | ||
], | ||
"files": { | ||
"solution": [ | ||
"parallel-letter-frequency.ua" | ||
], | ||
"test": [ | ||
"tests.ua" | ||
], | ||
"example": [ | ||
".meta/example.ua" | ||
] | ||
}, | ||
"blurb": "Count the frequency of letters in texts using parallel computation." | ||
} |
4 changes: 4 additions & 0 deletions
4
exercises/practice/parallel-letter-frequency/.meta/example.ua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
LetterCount ← map ⊕⊃⊢⧻ ⊛.¯▽±.⌵ | ||
ParallelCounts ← wait≡spawn⍚LetterCount | ||
Merge ← map ⟜(≡(/◇+⍚(⬚0get:):))⊙¤⊸(⍆◴/◇⊂⍚(⊙◌°map)) | ||
Frequencies ← Merge ParallelCounts |
50 changes: 50 additions & 0 deletions
50
exercises/practice/parallel-letter-frequency/.meta/tests.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 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. | ||
|
||
[c054d642-c1fa-4234-8007-9339f2337886] | ||
description = "no texts" | ||
|
||
[818031be-49dc-4675-b2f9-c4047f638a2a] | ||
description = "one text with one letter" | ||
|
||
[c0b81d1b-940d-4cea-9f49-8445c69c17ae] | ||
description = "one text with multiple letters" | ||
|
||
[708ff1e0-f14a-43fd-adb5-e76750dcf108] | ||
description = "two texts with one letter" | ||
|
||
[1b5c28bb-4619-4c9d-8db9-a4bb9c3bdca0] | ||
description = "two texts with multiple letters" | ||
|
||
[6366e2b8-b84c-4334-a047-03a00a656d63] | ||
description = "ignore letter casing" | ||
|
||
[92ebcbb0-9181-4421-a784-f6f5aa79f75b] | ||
description = "ignore whitespace" | ||
|
||
[bc5f4203-00ce-4acc-a5fa-f7b865376fd9] | ||
description = "ignore punctuation" | ||
|
||
[68032b8b-346b-4389-a380-e397618f6831] | ||
description = "ignore numbers" | ||
|
||
[aa9f97ac-3961-4af1-88e7-6efed1bfddfd] | ||
description = "Unicode letters" | ||
include = false | ||
|
||
[7b1da046-701b-41fc-813e-dcfb5ee51813] | ||
description = "combination of lower- and uppercase letters, punctuation and white space" | ||
|
||
[4727f020-df62-4dcf-99b2-a6e58319cb4f] | ||
description = "large texts" | ||
|
||
[adf8e57b-8e54-4483-b6b8-8b32c115884c] | ||
description = "many small texts" |
3 changes: 3 additions & 0 deletions
3
exercises/practice/parallel-letter-frequency/parallel-letter-frequency.ua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Count the frequency of letters in texts using parallel computation. | ||
# Frequencies ? Texts | ||
Frequencies ← |1 ⊙(⍤"Please implement Frequencies" 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
~ "parallel-letter-frequency.ua" ~ Frequencies | ||
|
||
# no texts | ||
⍤⤙≍ 0 ⧻ Frequencies {} | ||
|
||
# one text with one letter | ||
⍤⤙≍ map "a" [1] Frequencies {"a"} | ||
|
||
# one text with multiple letters | ||
⍤⤙≍ map "bcd" [2 3 1] Frequencies {"bbcccd"} | ||
|
||
# two texts with one letter | ||
⍤⤙≍ map "ef" [1 1] Frequencies {"e" "f"} | ||
|
||
# two texts with multiple letters | ||
⍤⤙≍ map "ghi" [2 3 1] Frequencies {"ggh" "hhi"} | ||
|
||
# ignore letter casing | ||
⍤⤙≍ map "m" [2] Frequencies {"m" "M"} | ||
|
||
# ignore whitespace | ||
⍤⤙≍ 0 ⧻ Frequencies {" " " " "\n\t"} | ||
|
||
# ignore punctuation | ||
⍤⤙≍ 0 ⧻ Frequencies {"!" "?" ";" "," "."} | ||
|
||
# ignore numbers | ||
⍤⤙≍ 0 ⧻ Frequencies {"1" "2" "3" "4" "5" "6" "7" "8" "9"} | ||
|
||
# combination of lower- and uppercase letters, punctuation and white space | ||
Expected ← map "abcdefghiklmnoprstuvwy" [32 4 6 14 37 7 8 29 19 6 12 7 19 22 7 17 16 30 9 2 9 4] | ||
Texts ← {"There, peeping among the cloud-wrack above a dark tower high up in the mountains, Sam saw a white star twinkle for a while. The beauty of it smote his heart, as he looked up out of the forsaken land, and hope returned to him. For like a shaft, clear and cold, the thought pierced him that in the end, the shadow was only a small and passing thing: there was light and high beauty forever beyond its reach."} | ||
⍤⤙≍ Expected Frequencies Texts | ||
|
||
# many small texts | ||
Texts ← {"abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc" "abbccc"} | ||
⍤⤙≍ map "abc" [50 100 150] Frequencies Texts |