Re: coding an anagram function

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"N Ramsay" <neil@xxxxxxxxxxx> wrote in message
news:1161333528.328394.107300@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

I need to create a VBA function which compares two cells to see if the
contents are anagrams of each other. Result of function would be true /
false.

The cells will only contain letters, and no letter will appear more
than 9 times. Each cell will never have any more than 40 characters in
total. Spaces can be ignored.

The logic I was planning to use was to assign every letter of the
alphabet a numeric value and then add up the numeric values of each
string to give a numeric result.

For this to produce a unique result for any given string, i was
planning to use values like the following:

a=1
b=1.1
c=1.01
d=1.001
e=1.0001
f=1.00001
g=10
h=10.1
i=10.01
j=10.001
k=10.0001
l=10.00001
m=100
n=100.1
o=100.01
p=100.001
q=100.0001
r=100.00001
s=1000
t=1000.1
u=1000.01
v=1000.001
w=1000.0001
x=1000.00001
y=10000
z=10000.1

Given that no letter can appear more than 9 times, I believe this
should return a unique result for every possible string of letters.

So, if the function compares two strings and gets the same addition
based on the above rules, the strings must contain the same letters and
are therefore anagrams of each other.

However, I have no idea how to code this in VBA.

Can anyone either suggest code for this, or another way of comparing
two strings to see if they are anagrams of each other?

Many thanks in advance,

Neil.

Very clever.

I would be more obvious and sort both strings, then compare.


.



Relevant Pages

  • Re: a string, a string array and character array
    ... with strings, like sorting. ... uppercase letters have different numerical values but the ... or lowercase letters? ... behaviour) that "lowercase and uppercase letters have different numerical ...
    (comp.soft-sys.matlab)
  • Re: Bayesian updating with multiple events.
    ... probabilities 2/5, etc. ... strings are equally likely. ... probabilities of the letters on cards 2 and 3. ... may not always be as informative as seeing the card ... ...
    (sci.math)
  • Re: Whats going on here?
    ... > letters and numbers at the bottom of documents, ... > long strings of letters/numbers, and another program that does just the ... The length of the code is 16 plus twice the length of the plaintext. ...
    (sci.crypt)
  • Re: sort an array of strings
    ... > These are normal strings and you can store anything in it < 100 bytes. ... Ordinary quicksort on *average* performs fewer compares and data ... moves than either heap-sort or merge-sort. ... Mergesort is the only sorting algorithm that performs ...
    (comp.lang.c)
  • Re: Whats going on here?
    ... > letters and numbers at the bottom of documents, ... The messages are secret notes to ... > long strings of letters/numbers, and another program that does just the ...
    (sci.crypt)