Factorial Problem

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
349
Office Version
  1. 2003 or older
Platform
  1. Windows
I want to calculate a value (x) using factorials for any given word (w) as per the following logic:

For example,
if w=BOB then, x = 3!/(2!1!) --- BOB has three letters (3!) with B twice (2!) and O once (1!);
if w=ABE then, x = 3!/(1!1!1!) --- ABE has three letters (3!) with A once (1!), B once (1!), and E once (1!);
if w=ABBA then, x = 4!/(2!2!) --- ABBA has four letters (4!) with A twice (2!) and B twice (2!);

Is there a way to execute and output x for any w input?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
if w=BOB then, x = 3?

if w=ABE then, x = 6?

if w=ABBA then, x = 6?

Is that correct?
 
Upvote 0
@Phuoc

if w=ABBA then x=24 (4fact divided by product of 2fact & 2fact).
first two correct.
 
Upvote 0
if w=ABBA then, x = 4!/(2!2!)

4! = 24

(2!2!) = 2 *2 = 4

24/4 = 6 not 24?
 
Upvote 0
Try this

Code:
=FACT(LEN(A1))/PRODUCT(FACT(FREQUENCY(SEARCH(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),A1),ROW(INDIRECT("1:"&LEN(A1))))))
 
Upvote 0
Works as a formula, but how it be integrated in a code?
 
Upvote 0
Here is function that you can use in your code (it will also works as a UDF... User Defined Function... in a worksheet formula as well) that can handle a word (no spaces) of up to 17 letters long .
VBA Code:
Function WordFactorial(Word As String) As Long
  Dim X As Long, Product As Long, Lets As String, Letters(65 To 90) As String
  If Len(Word) < 18 Then
    For X = 1 To Len(Word)
      Letters(Asc(Mid(UCase(Word), X, 1))) = Val(Letters(Asc(Mid(UCase(Word), X, 1)))) + 1
    Next
    Lets = Replace(Join(Letters, ""), " ", "")
    Product = 1
    For X = 1 To Len(Lets)
      Product = Product * Application.Fact(Mid(Lets, X, 1))
    Next
    WordFactorial = Application.Fact(Len(Word)) / Product
  End If
End Function
 
Upvote 0
@Rick Rothstein ;

This works for a word; but if instead of a word it is a string, with alphanumeric values, can this be modified?
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,609
Members
449,174
Latest member
ExcelfromGermany

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top