-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rectangles
exercise
#124
Draft
ErikSchierboom
wants to merge
1
commit into
main
Choose a base branch
from
rectangles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,63 @@ | ||
# Instructions | ||
|
||
Count the rectangles in an ASCII diagram like the one below. | ||
|
||
```text | ||
+--+ | ||
++ | | ||
+-++--+ | ||
| | | | ||
+--+--+ | ||
``` | ||
|
||
The above diagram contains these 6 rectangles: | ||
|
||
```text | ||
|
||
|
||
+-----+ | ||
| | | ||
+-----+ | ||
``` | ||
|
||
```text | ||
+--+ | ||
| | | ||
| | | ||
| | | ||
+--+ | ||
``` | ||
|
||
```text | ||
+--+ | ||
| | | ||
+--+ | ||
|
||
|
||
``` | ||
|
||
```text | ||
|
||
|
||
+--+ | ||
| | | ||
+--+ | ||
``` | ||
|
||
```text | ||
|
||
|
||
+--+ | ||
| | | ||
+--+ | ||
``` | ||
|
||
```text | ||
|
||
++ | ||
++ | ||
|
||
|
||
``` | ||
|
||
You may assume that the input is always a proper rectangle (i.e. the length of every line equals the length of the first line). |
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": [ | ||
"rectangles.ua" | ||
], | ||
"test": [ | ||
"tests.ua" | ||
], | ||
"example": [ | ||
".meta/example.ua" | ||
] | ||
}, | ||
"blurb": "Count the rectangles in an ASCII diagram." | ||
} |
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,12 @@ | ||
ValidPair ← /×≡(=°⊟) ⊏ | ||
ValidXs ← ValidPair [0_1 2_3] | ||
ValidYs ← ValidPair [0_2 1_3] | ||
Valid ← ×⊃(ValidXs≡⊢|ValidYs≡⊣) | ||
Parse ← ⊜∘(≠@\n.) | ||
Candidates ← ▽≡Valid.⧅<4⊚⌕@+ | ||
Rectangle ← ( | ||
∩(⍜-⇡+1⊃(/↥|/↧))≡(⊃⊢⊣) | ||
◴⊂⊂⊃(⊂⊃(⊞⊂⊢|⊞⊂⊣)|≡⇌⊃(⊞⊂⊢|⊞⊂⊣)⊂⊃(⊢|⊣):) | ||
/↧≠@ ≡⊡ ⊙¤ | ||
) | ||
Rectangles ← /+≡Rectangle⊙¤⊸Candidates Parse | ||
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,54 @@ | ||
# 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. | ||
|
||
[485b7bab-4150-40aa-a8db-73013427d08c] | ||
description = "no rows" | ||
include = false | ||
|
||
[076929ed-27e8-45dc-b14b-08279944dc49] | ||
description = "no columns" | ||
include = false | ||
|
||
[0a8abbd1-a0a4-4180-aa4e-65c1b1a073fa] | ||
description = "no rectangles" | ||
|
||
[a4ba42e9-4e7f-4973-b7c7-4ce0760ac6cd] | ||
description = "one rectangle" | ||
|
||
[ced06550-83da-4d23-98b7-d24152e0db93] | ||
description = "two rectangles without shared parts" | ||
|
||
[5942d69a-a07c-41c8-8b93-2d13877c706a] | ||
description = "five rectangles with shared parts" | ||
|
||
[82d70be4-ab37-4bf2-a433-e33778d3bbf1] | ||
description = "rectangle of height 1 is counted" | ||
|
||
[57f1bc0e-2782-401e-ab12-7c01d8bfc2e0] | ||
description = "rectangle of width 1 is counted" | ||
|
||
[ef0bb65c-bd80-4561-9535-efc4067054f9] | ||
description = "1x1 square is counted" | ||
|
||
[e1e1d444-e926-4d30-9bf3-7d8ec9a9e330] | ||
description = "only complete rectangles are counted" | ||
|
||
[ca021a84-1281-4a56-9b9b-af14113933a4] | ||
description = "rectangles can be of different sizes" | ||
|
||
[51f689a7-ef3f-41ae-aa2f-5ea09ad897ff] | ||
description = "corner is required for a rectangle to be complete" | ||
|
||
[d78fe379-8c1b-4d3c-bdf7-29bfb6f6dc66] | ||
description = "large input with many rectangles" | ||
|
||
[6ef24e0f-d191-46da-b929-4faca24b4cd2] | ||
description = "rectangles must have four sides" |
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 number of rectangles in a grid | ||
# Count ? Grid | ||
Rectangles ← |1 ⊙(⍤"Please implement Rectangles" 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,88 @@ | ||
~ "rectangles.ua" ~ Rectangles | ||
|
||
# No rectangles | ||
Grid ← $ | ||
⍤⤙≍ 0 Rectangles Grid | ||
|
||
# One rectangle | ||
Grid ← $ +-+ | ||
$ | | | ||
$ +-+ | ||
⍤⤙≍ 1 Rectangles Grid | ||
|
||
# Two rectangles without shared parts | ||
Grid ← $ +-+ | ||
$ | | | ||
$ +-+-+ | ||
$ | | | ||
$ +-+ | ||
⍤⤙≍ 2 Rectangles Grid | ||
|
||
# Five rectangles with shared parts | ||
Grid ← $ +-+ | ||
$ | | | ||
$ +-+-+ | ||
$ | | | | ||
$ +-+-+ | ||
⍤⤙≍ 5 Rectangles Grid | ||
|
||
# Rectangle of height 1 is counted | ||
Grid ← $ +--+ | ||
$ +--+ | ||
⍤⤙≍ 1 Rectangles Grid | ||
|
||
# Rectangle of width 1 is counted | ||
Grid ← $ ++ | ||
$ || | ||
$ ++ | ||
⍤⤙≍ 1 Rectangles Grid | ||
|
||
# 1x1 square is counted | ||
Grid ← $ ++ | ||
$ ++ | ||
⍤⤙≍ 1 Rectangles Grid | ||
|
||
# Only complete rectangles are counted | ||
Grid ← $ +-+ | ||
$ | | ||
$ +-+-+ | ||
$ | | - | ||
$ +-+-+ | ||
⍤⤙≍ 1 Rectangles Grid | ||
|
||
# Rectangles can be of different sizes | ||
Grid ← $ +------+----+ | ||
$ | | | | ||
$ +---+--+ | | ||
$ | | | | ||
$ +---+-------+ | ||
⍤⤙≍ 3 Rectangles Grid | ||
|
||
# Corner is required for a rectangle to be complete | ||
Grid ← $ +------+----+ | ||
$ | | | | ||
$ +------+ | | ||
$ | | | | ||
$ +---+-------+ | ||
⍤⤙≍ 2 Rectangles Grid | ||
|
||
# Large input with many rectangles | ||
Grid ← $ +---+--+----+ | ||
$ | +--+----+ | ||
$ +---+--+ | | ||
$ | +--+----+ | ||
$ +---+--+--+-+ | ||
$ +---+--+--+-+ | ||
$ +------+ | | | ||
$ +-+ | ||
⍤⤙≍ 60 Rectangles Grid | ||
|
||
# Rectangles must have four sides | ||
Grid ← $ +-+ +-+ | ||
$ | | | | | ||
$ +-+-+-+ | ||
$ | | | ||
$ +-+-+-+ | ||
$ | | | | | ||
$ +-+ +-+ | ||
⍤⤙≍ 5 Rectangles Grid |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really work. I'm putting this PR up in the hope that someone can solve this more easily than I can :)