Image

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

5 by 5 knight's tour string validator [FINALIZED]

+0
−0

Now posted: 5 by 5 knight's tour string validator


The squares of a 5 by 5 chessboard are labelled with the letters A to Y in English reading order:

A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y

Determine whether a string is a knight's tour of this board.

Input

  • A string of 25 distinct letters from A to Y inclusive.

Output

  • An indication of whether this string represents a valid knight's tour on the 5 by 5 chessboard. This may be one of 2 distinct values, or any truthy or falsy value if your language supports that concept.
    • If using 2 distinct values, you may choose either of them to indicate a valid knight's tour. Specifically, it is permitted to use false or a specific falsy output to indicate valid and/or to use true or a specific truthy output to indicate invalid.
    • If using arbitrary truthy and falsy values, so you have more than 2 distinct values for your outputs, you must use truthy to indicate a valid knight's tour, not the other way around.
  • The string is a valid knight's tour if each consecutive pair of letters is a knight's move apart on the 5 by 5 chessboard. That is, the pair of letters is one of:
    • Differing by 1 row and 2 columns.
    • Differing by 2 rows and 1 column.
  • The first and last letters do not need to be a knight's move apart from each other (if all consecutive pairs are a knight's move apart, it is impossible for the first and last to be, since the board has an odd number of squares).

Test cases

Test cases are in the format input : output, with the output being true for a valid tour and false otherwise.

MJCFQXODGPWTIBKVSHENYRULA : true
ALURYNEHSVKBITWPGDOXQFCJM : true
IBKVSHENYRULAMJCFQXODGPWT : false
URYNEHSVKBITWPGDOXQFCJMAL : false
LIBJPWNCFTVSHAOURGDMXQYKE : false
NFDGRYKEHQXPJCLWTIAOUSVMB : false
ROHKVDTILUCYNGPBXMJSEWAQF : false
HEWALSJXBKRODVFQNCYITMPGU : false

Scoring

This is a code golf challenge. Your score is the number of bytes in your code. Lowest score for each language wins.

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

History

0 comment threads