I have this JavaScript Function that works:
var char = 10;
function grc(len) {
if (len < 1) {
return 0;
}
if (len == 1) {
return Math.pow(char, 5);
}
return Math.pow(char, len - 1) + grc(len - 1);
}
console.log(grc(5));
Non-working Javascript?
var char = 10;
function grc(len) {
if (len < 1) {
return 0;
}
if (len == 1) {
return Math.pow(char, len);
}
return Math.pow(char, len - 1) + grc(len - 1);
}
console.log(grc(5));
And I need it in VBA, I gave it a try but I'm not good in VBA:
Function GRC(length)
If (length < 1) Then
GRC = 0
End If
If (length = 1) Then
GRC = char ^ length
End If
GRC = char ^ (length - 1) + GRC(length - 1)
End Function
But it doesn't Work, I'm trying to write this in excel so not really getting any useful errors. its supposed to work like this:
the GRC function would need to know the "characters" variable and take in the "length" variable, in java-script I just created the "characters" variable above the function so the function could call on to it. But in this scenario I'm using VBA and in excel which I don't know if there is a way to get a variable from the spreadsheet without taking it in to the function. as far as the expected output goes if: char = "10", "length" = "5" then the output would be: 111,110 if: char = "52", "length" = "3" then the output would be: 143,364
the algorithm that it's using is from https://www.grc.com/haystack.htm
number-of-charactersmakes no sense. This looks more like pseudo code, but even then it has undefined references.numberofcharacters? It is undefined.