Post History
#12: Post edited
Connect the corners without 4 in a row
- Connect the corners without 4 in a row [FINALIZED]
- 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.
- ## Now posted: [Connect the corners without 4 in a row](https://codegolf.codidact.com/posts/287321)
- ---
- 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.
#11: Post edited
- 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:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > 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.
#10: Post edited
- 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:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > 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:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#9: Post edited
- 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.
For input 3, 3, here are some examples of valid outputs:- ```text
###..#..###..##..###..#..###############.####- ```
Here is a selection of valid paths for input 7, 5:- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
Invalid examples for input 7, 5:- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
Goes outside the rectangle bounds:###......#......###......#.....##.#...#.##...###.Has 4 in a row horizontally:- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > 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:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#8: Post edited
- 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.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
#..###..##..##..###..#..#######..#...####.#...##.#.##...#####....#.####...#..####- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > 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.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#7: Post edited
- 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 pattern of characters representing a path- You may choose any 2 distinct characters to represent the path and the background- There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.- For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively- The output must be contained within a rectangle of width and height W and H, or H and W, respectively- If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters- You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps- The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish- Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection- The path may have redundant branches that are not needed for making it valid, if you wish- There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically- The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1## Attempt at more concise output spec- The output must be contained within a rectangle of width W and height H, or width H and height W- The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and `.` for the background.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
- #..
- ###
- ..#
- #..
- ##.
- .##
- #..
- #..
- ###
- ###
- #..
- #..
- .##
- ##.
- #..
- .##
- .#.
- ##.
- ..#
- ###
- #..
- ..#
- .##
- ##.
- ..#
- ..#
- ###
- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > 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.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
- #..
- ###
- ..#
- #..
- ##.
- .##
- #..
- #..
- ###
- ###
- #..
- #..
- .##
- ##.
- #..
- .##
- .#.
- ##.
- ..#
- ###
- #..
- ..#
- .##
- ##.
- ..#
- ..#
- ###
- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#6: Post edited
- 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 3 to 79- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and `.` for the background.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
- #..
- ###
- ..#
- #..
- ##.
- .##
- #..
- #..
- ###
- ###
- #..
- #..
- .##
- ##.
- #..
- .##
- .#.
- ##.
- ..#
- ###
- #..
- ..#
- .##
- ##.
- ..#
- ..#
- ###
- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
> Explanations in answers are optional, but I'm more likely to upvote answers that have one.# Code block width test:```text1 2 3 4 5 6 701234567890123456789012345678901234567890123456789012345678901234567890123456789```
- 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 pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and `.` for the background.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
- #..
- ###
- ..#
- #..
- ##.
- .##
- #..
- #..
- ###
- ###
- #..
- #..
- .##
- ##.
- #..
- .##
- .#.
- ##.
- ..#
- ###
- #..
- ..#
- .##
- ##.
- ..#
- ..#
- ###
- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > Explanations are optional, but I'm more likely to upvote answers that have one.
#5: Post edited
- 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 3 to 255- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and `.` for the background.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
- #..
- ###
- ..#
- #..
- ##.
- .##
- #..
- #..
- ###
- ###
- #..
- #..
- .##
- ##.
- #..
- .##
- .#.
- ##.
- ..#
- ###
- #..
- ..#
- .##
- ##.
- ..#
- ..#
- ###
- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
> Explanations in answers 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 3 to 79
- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and `.` for the background.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
- #..
- ###
- ..#
- #..
- ##.
- .##
- #..
- #..
- ###
- ###
- #..
- #..
- .##
- ##.
- #..
- .##
- .#.
- ##.
- ..#
- ###
- #..
- ..#
- .##
- ##.
- ..#
- ..#
- ###
- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- # Code block width test:
- ```text
- 1 2 3 4 5 6 7
- 01234567890123456789012345678901234567890123456789012345678901234567890123456789
- ```
#4: Post edited
- 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 3 to 255
- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
These examples use `#` for a path character and space for the background.- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
#############- ###
########- ###
- ###
#############- ###
########- ###
- ###
- ###
- ###
- ###
# #- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
########################## #### # ##### ########## #### # #### #- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
############- Goes outside the rectangle bounds:
########## ## #####Has 4 in a row horizontally or vertically:###########- Depends on diagonal adjacency, which does not count as connection:
########```
- 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 3 to 255
- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and `.` for the background.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- ..#
- ..#
- ##.
- .##
- ..#
- ##.
- .#.
- .##
- #..
- ###
- ..#
- #..
- ##.
- .##
- #..
- #..
- ###
- ###
- #..
- #..
- .##
- ##.
- #..
- .##
- .#.
- ##.
- ..#
- ###
- #..
- ..#
- .##
- ##.
- ..#
- ..#
- ###
- ###
- ###
- ###
- ###
- #.#
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###....
- ..#....
- ..###..
- ....#..
- ....###
- ##.....
- .##....
- ..##...
- ...##..
- ....###
- #......
- #......
- ##.###.
- .#.#.##
- .###..#
- ###....
- ..###..
- ###.###
- #...#.#
- ###...#
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###....
- ..###..
- ....###
- ...##..
- ...#...
- Goes outside the rectangle bounds:
- ###....
- ..#....
- ..###..
- ....#..
- ...##.#
- ...#.##
- ...###.
- Has 4 in a row horizontally:
- ####...
- ...#...
- ...###.
- .....#.
- .....##
- Has 4 in a row vertically:
- ###....
- ..#....
- ..#.###
- ..###.#
- ......#
- Depends on diagonal adjacency, which does not count as connection:
- ##.....
- ..##...
- ....##.
- ......#
- ......#
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
#3: Post edited
- 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 3 to 255
- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and space for the background.
For input 3, 3, any of the following paths are valid:- ```text
- ###
- #
- #
- ##
- ##
- #
- #
- ##
- ##
- #
- #
- ###
- ###
- #
- #
- ##
- ##
- #
- #
- ##
- ##
- #
- #
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###
- #
- ###
- #
- ###
- ##
- ##
- ##
- ##
- ###
- #
- #
- ## ###
- # # ##
- ### #
- ###
- ###
- ### ###
- # # #
- ### #
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###
- ###
- ###
- ##
- #
- Goes outside the rectangle bounds:
- ###
- #
- ###
- #
- ## #
- # ##
- ###
- Has 4 in a row horizontally or vertically:
- ####
- #
- ###
- #
- ##
- Depends on diagonal adjacency, which does not count as connection:
- ##
- ##
- ##
- #
- #
- ```
- 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 3 to 255
- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and space for the background.
- For input 3, 3, here are some examples of valid outputs:
- ```text
- ###
- #
- #
- ##
- ##
- #
- ##
- #
- ##
- #
- ###
- #
- #
- ##
- ##
- #
- #
- ###
- ###
- #
- #
- ##
- ##
- #
- ##
- #
- ##
- #
- ###
- #
- #
- ##
- ##
- #
- #
- ###
- ###
- ###
- ###
- ###
- # #
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###
- #
- ###
- #
- ###
- ##
- ##
- ##
- ##
- ###
- #
- #
- ## ###
- # # ##
- ### #
- ###
- ###
- ### ###
- # # #
- ### #
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###
- ###
- ###
- ##
- #
- Goes outside the rectangle bounds:
- ###
- #
- ###
- #
- ## #
- # ##
- ###
- Has 4 in a row horizontally or vertically:
- ####
- #
- ###
- #
- ##
- Depends on diagonal adjacency, which does not count as connection:
- ##
- ##
- ##
- #
- #
- ```
#2: Post edited
- 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 3 to 255
- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4.
- 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 3 to 255
- ## Output
- - A pattern of characters representing a path
- - You may choose any 2 distinct characters to represent the path and the background
- - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically.
- - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively
- - The output must be contained within a rectangle of width and height W and H, or H and W, respectively
- - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters
- - You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4. For example, you could choose to always treat the even input as the width where there is one even and one odd, if that helps
- - The path must connect opposite corners of a W by H or H by W rectangle, but you may choose whether that is top left to bottom right, or top right to bottom left, and you may vary this decision for different inputs if you wish
- - Only horizontal and vertical adjacency count as connection. Diagonal adjacency is not connection
- - The path may have redundant branches that are not needed for making it valid, if you wish
- - There may be other disconnected path characters that do not contribute to the valid path if you wish, provided there are never 4 adjacent in a line horizontally or vertically
- - The output does not need to be deterministic. That is, you may give different output for the same input on different runs of your code. If your output is not deterministic, you must demonstrate that the output will always be valid, or will be valid with probability 1
- ## Attempt at more concise output spec
- - The output must be contained within a rectangle of width W and height H, or width H and height W
- - The output must contain 2 connected path characters separated horizontally and vertically by W and H, or H and W, respectively
- - The output must not contain 4 adjacent path characters in a line horizontally or vertically
- ## Examples
- These examples use `#` for a path character and space for the background.
- For input 3, 3, any of the following paths are valid:
- ```text
- ###
- #
- #
- ##
- ##
- #
- #
- ##
- ##
- #
- #
- ###
- ###
- #
- #
- ##
- ##
- #
- #
- ##
- ##
- #
- #
- ###
- ```
- Here is a selection of valid paths for input 7, 5:
- ```text
- ###
- #
- ###
- #
- ###
- ##
- ##
- ##
- ##
- ###
- #
- #
- ## ###
- # # ##
- ### #
- ###
- ###
- ### ###
- # # #
- ### #
- ```
- Invalid examples for input 7, 5:
- ```text
- Does not connect two diagonally opposite corners:
- ###
- ###
- ###
- ##
- #
- Goes outside the rectangle bounds:
- ###
- #
- ###
- #
- ## #
- # ##
- ###
- Has 4 in a row horizontally or vertically:
- ####
- #
- ###
- #
- ##
- Depends on diagonal adjacency, which does not count as connection:
- ##
- ##
- ##
- #
- #
- ```
#1: Initial revision
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 3 to 255 ## Output - A pattern of characters representing a path - You may choose any 2 distinct characters to represent the path and the background - There must be no occurrences of 4 adjacent path characters in a line horizontally or vertically. - For inputs W and H, the horizontal and vertical offsets between the ends of the path must be either W and H, or H and W, respectively - The output must be contained within a rectangle of width and height W and H, or H and W, respectively - If outputting as a sequence of lines of characters, or as newline separated lines of characters, each line does not have to be the same length. A shorter line will be considered equivalent to a line of the same length as the maximum line length of the output, padded with background characters You may switch the order of width and height for some inputs if you wish. Specifically, a valid output for 4, 3 is also a valid output for 3, 4.