Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:54:52+00:00 2026-06-18T11:54:52+00:00

I have this idea (using C language) for checking whether two strings formed from

  • 0

I have this idea (using C language) for checking whether two strings formed from ASCII letters are anagrams of one another:

  1. Check if the strings are the same length.

  2. Check if the sum of the ASCII values of all chars is the same for both strings.

  3. Check if the product of the ASCII values of all chars is the same for both strings.

I believe that if all three are correct, then the strings must be anagrams of one another. However, I can’t prove it. Can someone help me prove or disprove that this would work?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:54:53+00:00Added an answer on June 18, 2026 at 11:54 am

    I wrote a quick program to brute-force search for conflicts and found that this approach does not always work. The strings ABFN and AAHM have the same ASCII sum and product, but are not anagrams of one another. Their ASCII sum is 279 and ASCII product is 23,423,400.

    There are a lot more conflicts than this. My program, searching over all length-four strings, found 11,737 conflicts.

    For reference, here’s the C++ source code:

    #include <iostream>
    #include <map>
    #include <string>
    #include <vector>
    using namespace std;
    
    int main() {
      /* Sparse 2D table where used[sum][prod] is either nothing or is a string
       * whose characters sum to "sum" and whose product is "prod".
       */
      map<int, map<int, string> > used;
    
      /* List of all usable characters in the string. */
      vector<char> usable;
      for (char ch = 'A'; ch <= 'Z'; ch++) {
        usable.push_back(ch);
      }
      for (char ch = 'a'; ch <= 'z'; ch++) {
        usable.push_back(ch);
      }
    
      /* Brute-force search over all possible length-four strings.  To avoid
       * iterating over anagrams, the search only explores strings whose letters
       * are in increasing ASCII order.
       */
      for (int a = 0; a < usable.size(); a++) {
        for (int b = a; b < usable.size(); b++) {
          for (int c = b; c < usable.size(); c++) {
            for (int d = c; d < usable.size(); d++) {
              /* Compute the sum and product. */
              int sum  = usable[a] + usable[b] + usable[c] + usable[d];
              int prod = usable[a] * usable[b] * usable[c] * usable[d];
    
              /* See if we have already seen this. */
              if (used.count(sum) &&
                  used[sum].count(prod)) {
                cout << "Conflict found: " << usable[a] << usable[b] << usable[c] << usable[d] << " conflicts with " << used[sum][prod] << endl;
              }
    
              /* Update the table. */
              used[sum][prod] = string() + usable[a] + usable[b] + usable[c] + usable[d];
            }
          }
        }
      }
    }
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this idea for a RubyGem that I think would be an
I have this grand idea to basically employ some brute force attack to test/verify
I have a html like this: The idea is that divs are floated left
I have searched this site and Google and even though the idea is pretty
I have no idea why this is happening. The error I get is the
I have no idea if this question fit to SO, but if it doesn't
I have no idea if this is possible, but if it is, what would
I have no idea why this doesn't work, but doing some validation functions and
I have no idea if this is possible ... but it would be cool.
I have no idea what this means. But here is the code that it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.