function [x, y] = ten_hundred(series)
% function [x, y] = ten_hundred(series)
% See Youtube https://youtu.be/NP3ZdQwrL_Q
% This function takes a time series n1, n2, ..., nt,
% finds index i such that ni <= nt/10 but n{i+1}>nt/10, 
% finds index j such that nj <= nt/100 but n{j+1}>nt/100.
% returns the "10 gap" x = t-i, and "100 gap" y = i-j.  More formally:
%
% Input
%     series: a real-valued vector [n1, n2, ..., nt] for the number of cases at time 1...t
% Output
%     x: integer, the number of indices between nt/10 and nt (see above), or NaN if the whole series is larger than nt/10
%     y: integer, the number of indices between nt/100 and nt/10, or NaN if the whole series is larger than nt/100
%
% By Jerry Zhu, jerryzhu@cs.wisc.edu, http://www.cs.wisc.edu/~jerryzhu.  
% Version 1.0 April 1, 2020
% This is Version 1.1 April 3, 2020.  Check: series has to end positive.

t = length(series);

if (series(t)<=0)
  x = NaN;
  y = NaN;
  return
end

% find the day with 10 times less cases
threshold10 = series(t)/10;
i = max(find(series <= threshold10));
if isempty(i)
  x = NaN;
else
  x = t - i;
end
    
% find the day with 100 times less cases
threshold100 = series(t)/100;
j = max(find(series <= threshold100));
if isempty(j)
  y = NaN;
else
  y = i - j;
end
    
end
