-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersistenceCheckV4.m
47 lines (33 loc) · 1.26 KB
/
PersistenceCheckV4.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function [ countMAT, persMAX, maxMAT ] = PersistenceCheckV4(inputMAT, base)
%this version accepts rows of number in inputMat,
%base number will be input and calculated in;
%calculates the multiplicative persistance;
%outputs results of persistence into countMAX
%the number with the maximum persistence into persMAX,
%and matrix of maximum number maxMAT
function persistance = PersistenceCalculater(input)
%initialise numberBase
numberBase = string(input);
%initialise length of number
digit = strlength(numberBase);
%initialise count
persistance = 0;
%loop while digits are more than one
while digit > 1
%split into individual digits
numArray = string(num2cell(cell2mat(numberBase)));
result = 1;
for numb = numArray
numbdec = base2dec(numb, base);
result = result * numbdec;
end
numberBase = string(dec2base(result, base));
digit = strlength(string(numberBase));
persistance = persistance + 1;
end
end
countMAT = arrayfun(@(input) PersistenceCalculater(input), inputMAT);
resultMAT = string([inputMAT; countMAT]);
persMAX = string(max(countMAT));
maxMAT = resultMAT(1, ismember(resultMAT(2, :), persMAX));
end