Skip to content

Commit

Permalink
Add series exercise (#13)
Browse files Browse the repository at this point in the history
* Add `series` exercise

* Update series.ua

Co-authored-by: Christian Willner <34183939+vaeng@users.noreply.github.com>

---------

Co-authored-by: Christian Willner <34183939+vaeng@users.noreply.github.com>
  • Loading branch information
ErikSchierboom and vaeng authored Nov 14, 2024
1 parent dc44e7f commit 1bcad8a
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
"prerequisites": [],
"difficulty": 5
},
{
"slug": "series",
"name": "Series",
"uuid": "8a0bf181-02b7-4320-b7cf-83ecbf072560",
"practices": [],
"prerequisites": [],
"difficulty": 4
},
{
"slug": "isogram",
"name": "Isogram",
Expand Down
19 changes: 19 additions & 0 deletions exercises/practice/series/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Instructions

Given a string of digits, output all the contiguous substrings of length `n` in that string in the order that they appear.

For example, the string "49142" has the following 3-digit series:

- "491"
- "914"
- "142"

And the following 4-digit series:

- "4914"
- "9142"

And if you ask for a 6-digit series from a 5-digit string, you deserve whatever you get.

Note that these series are only required to occupy _adjacent positions_ in the input;
the digits need not be _numerically consecutive_.
19 changes: 19 additions & 0 deletions exercises/practice/series/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"erikschierboom"
],
"files": {
"solution": [
"series.ua"
],
"test": [
"tests.ua"
],
"example": [
".meta/example.ua"
]
},
"blurb": "Given a string of digits, output all the contiguous substrings of length `n` in that string.",
"source": "A subset of the Problem 8 at Project Euler",
"source_url": "https://projecteuler.net/problem=8"
}
2 changes: 2 additions & 0 deletions exercises/practice/series/.meta/example.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Validate ← |2.2 ⍤"Invalid" ◡(×⊙(≤)◡(× ∩(>0) (>0))⧻:)
Slices ← |2 ⍣(◫ Validate)[]
43 changes: 43 additions & 0 deletions exercises/practice/series/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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.

[7ae7a46a-d992-4c2a-9c15-a112d125ebad]
description = "slices of one from one"

[3143b71d-f6a5-4221-aeae-619f906244d2]
description = "slices of one from two"

[dbb68ff5-76c5-4ccd-895a-93dbec6d5805]
description = "slices of two"

[19bbea47-c987-4e11-a7d1-e103442adf86]
description = "slices of two overlap"

[8e17148d-ba0a-4007-a07f-d7f87015d84c]
description = "slices can include duplicates"

[bd5b085e-f612-4f81-97a8-6314258278b0]
description = "slices of a long series"

[6d235d85-46cf-4fae-9955-14b6efef27cd]
description = "slice length is too large"

[d7957455-346d-4e47-8e4b-87ed1564c6d7]
description = "slice length is way too large"

[d34004ad-8765-4c09-8ba1-ada8ce776806]
description = "slice length cannot be zero"

[10ab822d-8410-470a-a85d-23fbeb549e54]
description = "slice length cannot be negative"

[c7ed0812-0e4b-4bf3-99c4-28cbbfc246a2]
description = "empty series is invalid"
3 changes: 3 additions & 0 deletions exercises/practice/series/series.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Returns all the overlapping slices of a contiguous array of a given length
# Slices ? Input Span
Slices ← |2 ⊙(⍤ "Please implement Slices")
34 changes: 34 additions & 0 deletions exercises/practice/series/tests.ua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
~ "series.ua" ~ Slices

# slices of one from one?
⍤⤙≍ ["1"] Slices 1 "1"

# slices of one from two?
⍤⤙≍ ["1" "2"] Slices 1 "12"

# slices of two?
⍤⤙≍ ["35"] Slices 2 "35"

# slices of two overlap?
⍤⤙≍ ["91" "14" "42"] Slices 2 "9142"

# slices can include duplicates?
⍤⤙≍ ["777" "777" "777" "777"] Slices 3 "777777"

# slices of a long series?
⍤⤙≍ ["91849" "18493" "84939" "49390" "93904" "39042" "90424" "04243"] Slices 5 "918493904243"

# slice length is too large?
⍤⤙≍ [] Slices 6 "12345"

# slice length is way too large?
⍤⤙≍ [] Slices 42 "12345"

# slice length cannot be zero?
⍤⤙≍ [] Slices 0 "12345"

# slice length cannot be negative?
⍤⤙≍ [] Slices ¯1 "123"

# empty series is invalid?
⍤⤙≍ [] Slices 1 ""

0 comments on commit 1bcad8a

Please sign in to comment.