Giveaway Answer this question and get 1000TBT ;D

Status
Not open for further replies.
solve/1
% Get the lowest integer with persistence P
solve(P)->
solve(P, 0).

% solve/2
solve(P, I)->
case persistence(I) of
P-> I;
_-> solve(P, 1+I)
end.

% persistence/1
% Get the multiplicative persistence of integer N
persistence(N)->
persistence(N, 0).

% persistence/2
persistence(N, Rounds) when N < 10 ->
Rounds;

persistence(N, Rounds)->
persistence(integer_to_list(N), 1, Rounds + 1).

% persistence/3
persistence([], Product, Rounds) when Product > 9 ->
% io:format("round ~p product = ~p~n", [Rounds, Product]),
persistence(integer_to_list(Product), 1, Rounds + 1);
persistence([], _Product, Rounds)->
Rounds;

persistence([H|T], Product, Rounds)->
% io:format("H= ~p~n",[H]),
persistence( T, Product * (H-$0), Rounds).



679.
 
solve/1
% Get the lowest integer with persistence P
solve(P)->
solve(P, 0).

% solve/2
solve(P, I)->
case persistence(I) of
P-> I;
_-> solve(P, 1+I)
end.

% persistence/1
% Get the multiplicative persistence of integer N
persistence(N)->
persistence(N, 0).

% persistence/2
persistence(N, Rounds) when N < 10 ->
Rounds;

persistence(N, Rounds)->
persistence(integer_to_list(N), 1, Rounds + 1).

% persistence/3
persistence([], Product, Rounds) when Product > 9 ->
% io:format("round ~p product = ~p~n", [Rounds, Product]),
persistence(integer_to_list(Product), 1, Rounds + 1);
persistence([], _Product, Rounds)->
Rounds;

persistence([H|T], Product, Rounds)->
% io:format("H= ~p~n",[H]),
persistence( T, Product * (H-$0), Rounds).



679.

nice google research! :p
 
Okay, how do I explain this: First things first, the answer WILL BE DIVISIBLE BY EITHER 3, 5 OR 7 (Odd, prime numbers, single digit)

P=persistence wanted [5]
N=number [?]

First number-(5+1)=6-not divisible by 3, 5 or 7 (must be whole number)
Second number-(6 [new number]+1)=7 --> 67 not divisible by 3,5 or 7
Third number-(7+2)=9 -->679 divisible by 7! Therefore this is the lowest possible term with 5 multiplicative persistence

Therefore, N=679

You could keep going to get larger numbers, however, this one is the smallest.

Continuation: 4th & 5th number-(9+3)=12 --> 67912 --) not divisible by 3, 5 or 7

You can continue this for as long as you like.

Hope my answer was adequate. It took me too long to solve this. I guess you could say I'm pretty persistent :)

- - - Post Merge - - -

I adore math and science okay?
 
it's too late anyway Yano
and i highly doubt you didn't google it.
 
Status
Not open for further replies.
Back
Top