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 »

Review Suggested Edit

You can't approve or reject suggested edits because you haven't yet earned the Edit Posts ability.

Approved.
This suggested edit was approved and applied to the post over 3 years ago by snail_‭.

0 / 255
Is it a near-anagram?
  • Two words are [anagrams](https://en.wikipedia.org/wiki/Anagram) of each other if the letters of one can be reordered to spell the other; e.g. ADOBE and ABODE are anagrams. An alternate way of describing it is that both words contain the same count of each letter. If you were to make a table:
  • ADOBE ABODE
  • ----- -----
  • A: 1 A: 1
  • B: 1 B: 1
  • D: 1 D: 1
  • E: 1 E: 1
  • O: 1 O: 1
  • We can define a "near-anagram" as a pair of words that are *almost* anagrams, in the sense that they differ by only one letter. For example, TULIP and TUPLE are near-anagrams. TUPLE can be rearranged to spell TULEP, which differs from TULIP by only one letter. As a table:
  • TUPLE TULIP
  • ----- -----
  • E: 1 I: 1
  • L: 1 L: 1
  • P: 1 P: 1
  • T: 1 T: 1
  • U: 1 U: 1
  • # Challenge
  • The challenge is to take two strings as input and determine if they are near-anagrams.
  • - The strings can be taken in any convenient format for your language (strings, sequences of characters, etc.)
  • - The output can be any two distinct values, as long as they are always consistent; e.g. 0 and 1 for false and true.
  • - The strings will only contain alphabet characters in a single case. You can assume either upper or lower, whichever is convenient; examples are in upper. Input will contain no whitespace. (It is acceptable to take the input as a single string containing the words separated by whitespace, if it is convenient.)
  • - You can assume the strings will not be the same. A decision problem to handle equal strings is not very interesting. They may be proper anagrams, however.
  • - You can assume the input is not empty.
  • - The two words might not be the same length; they may differ by one letter at most (see test cases.)
  • Winning criteria is code-golf. Shortest answer in each language wins.
  • # Test Cases
  • ADOBE ABODE -> false (proper anagram)
  • TUPLE TULIP -> true (near-anagram)
  • ABCDE DADBC -> true (two Ds)
  • BAR BARN -> true (one extra letter)
  • BARN BARREN -> false (too different)
  • Two words are [anagrams](https://en.wikipedia.org/wiki/Anagram) of each other if the letters of one can be reordered to spell the other; e.g. ADOBE and ABODE are anagrams. An alternate way of describing it is that both words contain the same count of each letter. If you were to make a table:
  • ADOBE ABODE
  • ----- -----
  • A: 1 A: 1
  • B: 1 B: 1
  • D: 1 D: 1
  • E: 1 E: 1
  • O: 1 O: 1
  • We can define a "near-anagram" as a pair of words that are *almost* anagrams, in the sense that they differ by only one letter. For example, TULIP and TUPLE are near-anagrams. TUPLE can be rearranged to spell TULEP, which differs from TULIP by only one letter. As a table:
  • TUPLE TULIP
  • ----- -----
  • E: 1 I: 1
  • L: 1 L: 1
  • P: 1 P: 1
  • T: 1 T: 1
  • U: 1 U: 1
  • # Challenge
  • The challenge is to take two strings as input and determine if they are near-anagrams.
  • - The strings can be taken in any convenient format for your language (strings, sequences of characters, etc.)
  • - The output can be any two distinct values, as long as they are always consistent; e.g. 0 and 1 for false and true.
  • - The strings will only contain alphabet characters in a single case. You can assume either upper or lower, whichever is convenient; examples are in upper. Input will contain no whitespace. (It is acceptable to take the input as a single string containing the words separated by whitespace, if it is convenient.)
  • - You can assume the strings will not be the same. A decision problem to handle equal strings is not very interesting. They may be proper anagrams, however.
  • - You can assume the input is not empty.
  • - The two words might not be the same length; they may differ by one letter at most (see test cases.)
  • Winning criteria is <a class="badge is-tag">code-golf</a>. Shortest answer in each language wins.
  • # Test Cases
  • ADOBE ABODE -> false (proper anagram)
  • TUPLE TULIP -> true (near-anagram)
  • ABCDE DADBC -> true (two Ds)
  • BAR BARN -> true (one extra letter)
  • BARN BARREN -> false (too different)

Suggested over 3 years ago by General Sebast1an‭