Jorden van Leeuwen
27349
27349
Rank2
2
Badges170
170
Score
Jorden van Leeuwen submitted a Comment to Solution 2585335 @Jovan Krunic:
%
% find(vertcat(1,diff(a(:)),1))
% val=a(ans(diff(ans)==max(diff(ans))))
%
% the approach is:
% find the differences between the elements of the vector
% consecutive zero's mean there is a run of the same values
% get the indices of none zero elements of this vector
% get the differences of these indices (which are a measure for the length the run of consecutive zero's, the 'gap' resulting from removing the zeros)
% note that to make this work for vectors that start or end with the longest run we add a 1 to the beginning and the end of the first difference vector
% get the max value from this last result which is the max sequence length
% get the indices of these max values, that is, the first indices of the runs that have this max length
% note that this last result is always a column vector
% get the values of the first elements of the runs with max length from the original vector
% note that if the original vector was a row vector, the result will be a row vector and when it was a column vector the result is a column vector,
% as required in the problem description
function val=longrun(a)
val = [];
if length(a) > 0
% a(:) will convert a to a column vector
a_as_column_vector = a(:);
% differences between elements of a
diff_a = diff(a_as_column_vector);
% differences between elements of a enclosed in ones (to make sure first and last element are non zero)
vertcat_1_diff_a_1 = vertcat(1, diff_a, 1);
% non zero elements of vertcat_1_diff_a_1
find_vertcat_1_diff_a_1 = find(vertcat_1_diff_a_1);
% the difference between the non zero indices is equal to the length of the run of consecutive numbers
lengts_of_runs_of_consecutive_numbers = diff(find_vertcat_1_diff_a_1);
% set the elements that have the max length to one and the others to 0 - note that shift of indices as a result of diff is compensated by adding 1 at the front of the vector
indices_of_elements_that_have_max_length_run = lengts_of_runs_of_consecutive_numbers == max(lengts_of_runs_of_consecutive_numbers);
indices_of_first_elements_of_longest_run_of_consecutive_numbers = find_vertcat_1_diff_a_1(indices_of_elements_that_have_max_length_run);
values_of_first_elements_of_longest_run_of_consecutive_numbers = a(indices_of_first_elements_of_longest_run_of_consecutive_numbers);
val = values_of_first_elements_of_longest_run_of_consecutive_numbers;
end
end
on 17 Jan 2021 |
Jorden van Leeuwen submitted Solution 4612900 to Problem 672. Longest run of consecutive numbers on 17 Jan 2021 |
Jorden van Leeuwen submitted Solution 4584923 to Problem 44960. Rescale Scores on 12 Jan 2021 |
Jorden van Leeuwen submitted Solution 4583798 to Problem 44950. Calculate Inner Product on 12 Jan 2021 |
Jorden van Leeuwen submitted Solution 4583413 to Problem 44952. Find MPG of Lightest Cars on 12 Jan 2021 |
Jorden van Leeuwen submitted a Comment to Solution 3957788 how is the size of a solution calculated?
These solutions with a regexp seem to be designed to get this count low but imho are not the best solutions and should not be allowed as leading solutions. It is more of a keep the size low trick.
on 10 Jan 2021 |
Jorden van Leeuwen received Commenter badge for Solution 4571038 on 10 Jan 2021 |
Jorden van Leeuwen submitted a Comment to Solution 4571038 It should be mentioned in the problem that hotels and ratings are column vectors.
My solution
good = hotels(ratings >= cutoff)';
failed because I (imho correctly) assumed that a list is a row vector.
on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4571038 to Problem 44949. Find the Best Hotels on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570948 to Problem 44958. Crop an Image on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570878 to Problem 44958. Crop an Image on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570783 to Problem 44945. Calculate BMI on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570743 to Problem 44934. Plot Damped Sinusoid on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570728 to Problem 44948. Calculate a Damped Sinusoid on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570703 to Problem 44951. Verify Law of Large Numbers on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570668 to Problem 44947. Find the Oldest Person in a Room on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570658 to Problem 44944. Convert from Fahrenheit to Celsius on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570653 to Problem 44943. Calculate Amount of Cake Frosting on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570638 to Problem 1. Times 2 - START HERE on 10 Jan 2021 |
Jorden van Leeuwen received Solver badge for Solution 4570613 on 10 Jan 2021 |
Jorden van Leeuwen submitted Solution 4570613 to Problem 44946. Solve a System of Linear Equations on 10 Jan 2021 |