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 »
Sandbox

Post History

50%
+0 −0
Sandbox Connect the corners without 4 in a row [FINALIZED]

posted 1y ago by trichoplax‭  ·  edited 1y ago by trichoplax‭

#12: Post edited by user avatar trichoplax‭ · 2022-10-30T03:53:06Z (over 1 year ago)
Mark as finalized
  • 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 by user avatar trichoplax‭ · 2022-10-30T03:49:54Z (over 1 year ago)
Add link to validator
  • 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 by user avatar trichoplax‭ · 2022-10-30T00:09:36Z (over 1 year ago)
Remove accidental link markdown
  • 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 by user avatar trichoplax‭ · 2022-10-29T17:24:53Z (over 1 year ago)
Improve examples
  • 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 by user avatar trichoplax‭ · 2022-10-29T17:01:07Z (over 1 year ago)
Remove redundant examples
  • 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 by user avatar trichoplax‭ · 2022-10-29T04:00:37Z (over 1 year ago)
Golf the output spec
  • 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 by user avatar trichoplax‭ · 2022-10-08T05:19:58Z (over 1 year ago)
Settle of input range 2 to 70 to fit in a codeblock without a horizontal scroll bar
  • 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
  • ```
  • 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 by user avatar trichoplax‭ · 2022-10-08T05:08:12Z (over 1 year ago)
Test code block width to settle on max input size
  • 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 by user avatar trichoplax‭ · 2022-10-06T14:22:57Z (over 1 year ago)
Add visible background character for clarity
  • 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 by user avatar trichoplax‭ · 2022-10-05T00:58:28Z (over 1 year ago)
Add some more example cases for 3, 3
  • 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 by user avatar trichoplax‭ · 2022-10-04T16:44:06Z (over 1 year ago)
Add examples and work on output spec
  • 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 by user avatar trichoplax‭ · 2022-10-04T16:08:31Z (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 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.