Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Connect the corners without 4 in a row

Connect opposite corners of a rectangle of characters without putting 4 characters in a row. Input Two numbers, W and H, representing the width and height of the rectangle Each number will be ...

1 answer  ·  posted 1y ago by trichoplax‭  ·  last activity 9mo ago by WheatWizard‭

Question code-golf
#2: Post edited by user avatar trichoplax‭ · 2023-06-18T04:17:31Z (9 months ago)
Add missing newline
  • Connect opposite corners of a rectangle of characters without putting 4 characters in a row.
  • ## Input
  • - Two numbers, W and H, representing the width and height of the rectangle
  • - Each number will be in the range 2 to 70
  • ## Output
  • - A rectangular grid of characters, of width W and height H
  • - You may choose any 2 distinct characters to represent path and background
  • - The output must contain 2 connected path characters in diagonally opposite corners of the grid
  • - Connected means there is a path from one to the other moving only between adjacent path characters
  • - Adjacent means 1 character away horizontally or vertically (but not both - diagonal adjacency does not count as connection for this challenge)
  • - The output must not contain 4 adjacent path characters in a line horizontally or vertically
  • - There is no limit to how many of the characters may be path characters, provided there are never 4 in a row.
  • - There may be redundant sections connected to the path
  • - There may be disconnected sections of path provided the main path meets the requirements
  • ## Examples
  • These examples use `#` for a path character and `.` for the background.
  • ### Valid examples for input 4, 3
  • ```text
  • ##..
  • .##.
  • ..##
  • .###
  • .#..
  • ##..
  • #...
  • ##..
  • .###
  • ##.#
  • .###
  • ##.#
  • ```
  • ### Invalid examples for input 4, 3
  • ```text
  • 4 in a line horizontally:
  • #...
  • ####
  • ...#
  • Depends on diagonal adjacency, which does not count as connection:
  • #...
  • .#..
  • ..##
  • Does not connect diagonally opposite corners:
  • ###.
  • ..##
  • ###.
  • ```
  • ### Valid examples for input 7, 5
  • ```text
  • ###....
  • ..#....
  • ..###..
  • ....#..
  • ....###
  • ##.....
  • .##....
  • ..##...
  • ...##..
  • ....###
  • #......
  • #......
  • ##.###.
  • .#.#.##
  • .###..#
  • ###....
  • ..###..
  • ###.###
  • #...#.#
  • ###...#
  • ```
  • ### Invalid examples for input 7, 5
  • ```text
  • Does not connect two diagonally opposite corners:
  • ###....
  • ..###..
  • ....###
  • ...##..
  • ...#...
  • Has 4 in a row horizontally:
  • ####...
  • ...#...
  • ...###.
  • .....#.
  • .....##
  • Has 4 in a row vertically:
  • ###....
  • ..#....
  • ..#.###
  • ..###.#
  • ......#
  • Depends on diagonal adjacency, which does not count as connection:
  • ##.....
  • ..##...
  • ....##.
  • ......#
  • ......#
  • ```
  • ## Validator
  • You can check a specific output using this [path validator](https://trichoplax.github.io/connect-the-corners-validator/), which will give a reason for any failed validations.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • Connect opposite corners of a rectangle of characters without putting 4 characters in a row.
  • ## Input
  • - Two numbers, W and H, representing the width and height of the rectangle
  • - Each number will be in the range 2 to 70
  • ## Output
  • - A rectangular grid of characters, of width W and height H
  • - You may choose any 2 distinct characters to represent path and background
  • - The output must contain 2 connected path characters in diagonally opposite corners of the grid
  • - Connected means there is a path from one to the other moving only between adjacent path characters
  • - Adjacent means 1 character away horizontally or vertically (but not both - diagonal adjacency does not count as connection for this challenge)
  • - The output must not contain 4 adjacent path characters in a line horizontally or vertically
  • - There is no limit to how many of the characters may be path characters, provided there are never 4 in a row.
  • - There may be redundant sections connected to the path
  • - There may be disconnected sections of path provided the main path meets the requirements
  • ## Examples
  • These examples use `#` for a path character and `.` for the background.
  • ### Valid examples for input 4, 3
  • ```text
  • ##..
  • .##.
  • ..##
  • .###
  • .#..
  • ##..
  • #...
  • ##..
  • .###
  • ##.#
  • .###
  • ##.#
  • ```
  • ### Invalid examples for input 4, 3
  • ```text
  • 4 in a line horizontally:
  • #...
  • ####
  • ...#
  • Depends on diagonal adjacency, which does not count as connection:
  • #...
  • .#..
  • ..##
  • Does not connect diagonally opposite corners:
  • ###.
  • ..##
  • ###.
  • ```
  • ### Valid examples for input 7, 5
  • ```text
  • ###....
  • ..#....
  • ..###..
  • ....#..
  • ....###
  • ##.....
  • .##....
  • ..##...
  • ...##..
  • ....###
  • #......
  • #......
  • ##.###.
  • .#.#.##
  • .###..#
  • ###....
  • ..###..
  • ###.###
  • #...#.#
  • ###...#
  • ```
  • ### Invalid examples for input 7, 5
  • ```text
  • Does not connect two diagonally opposite corners:
  • ###....
  • ..###..
  • ....###
  • ...##..
  • ...#...
  • Has 4 in a row horizontally:
  • ####...
  • ...#...
  • ...###.
  • .....#.
  • .....##
  • Has 4 in a row vertically:
  • ###....
  • ..#....
  • ..#.###
  • ..###.#
  • ......#
  • Depends on diagonal adjacency, which does not count as connection:
  • ##.....
  • ..##...
  • ....##.
  • ......#
  • ......#
  • ```
  • ## Validator
  • You can check a specific output using this [path validator](https://trichoplax.github.io/connect-the-corners-validator/), which will give a reason for any failed validations.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
#1: Initial revision by user avatar trichoplax‭ · 2022-10-30T03:51:41Z (over 1 year ago)
Connect the corners without 4 in a row
Connect opposite corners of a rectangle of characters without putting 4 characters in a row.

## Input
- Two numbers, W and H, representing the width and height of the rectangle
- Each number will be in the range 2 to 70

## Output
- A rectangular grid of characters, of width W and height H
- You may choose any 2 distinct characters to represent path and background
- The output must contain 2 connected path characters in diagonally opposite corners of the grid
  - Connected means there is a path from one to the other moving only between adjacent path characters
  - Adjacent means 1 character away horizontally or vertically (but not both - diagonal adjacency does not count as connection for this challenge)
- The output must not contain 4 adjacent path characters in a line horizontally or vertically
- There is no limit to how many of the characters may be path characters, provided there are never 4 in a row.
  - There may be redundant sections connected to the path
  - There may be disconnected sections of path provided the main path meets the requirements

## Examples

These examples use `#` for a path character and `.` for the background.

### Valid examples for input 4, 3

```text
##..
.##.
..##

.###
.#..
##..

#...
##..
.###

##.#
.###
##.#
```

### Invalid examples for input 4, 3

```text
4 in a line horizontally:

#...
####
...#

Depends on diagonal adjacency, which does not count as connection:

#...
.#..
..##

Does not connect diagonally opposite corners:
###.
..##
###.
```

### Valid examples for input 7, 5

```text
###....
..#....
..###..
....#..
....###

##.....
.##....
..##...
...##..
....###

#......
#......
##.###.
.#.#.##
.###..#

###....
..###..
###.###
#...#.#
###...#
```

### Invalid examples for input 7, 5

```text
Does not connect two diagonally opposite corners:

###....
..###..
....###
...##..
...#...

Has 4 in a row horizontally:

####...
...#...
...###.
.....#.
.....##

Has 4 in a row vertically:

###....
..#....
..#.###
..###.#
......#

Depends on diagonal adjacency, which does not count as connection:

##.....
..##...
....##.
......#
......#
```

## Validator
You can check a specific output using this [path validator](https://trichoplax.github.io/connect-the-corners-validator/), which will give a reason for any failed validations.

> Explanations are optional, but I'm more likely to upvote answers that have one.