Untitled
unknown
plain_text
9 months ago
689 B
4
Indexable
function [num_triplets, max_triplet] = findTriplets(v)
% Input: v - vector of numbers
% Output:
% num_triplets - total number of increasing triplets
% max_triplet - vector containing the triplets with the highest sum
%usare la funzione sum, trovare numero triplette, tripletta con somma massima, considerare triplette duplicate
num_triplets=0;
max_triplet=[];
max_sum=-inf;
for i=1:(length(v)-2)
triplet=v(i:i+2);
if triplet(1)<triplet(2) && triplet(2)<triplet(3)
num_triplets=num_triplets+1;
current_sum=sum(triplet);
if current_sum>max_sum
max_sum=current_sum;
max_triplet=triplet;
end
end
end
Editor is loading...
Leave a Comment