days_in_month = [31 28 31 30 31 30 31 31 30 31 30 31];

day_time = input('Enter day and time as [yyyy mm dd hh mm ss] or 0 for current time: ');
if length(day_time) ~= 6
   day_time = clock;
end
day_time(6) = floor(day_time(6));

debt_s = input('Enter national debt as a string of only digits: ');
debt_z = strcat(fliplr(debt_s), '000000000000000000');
debt_n = debt_z - 48;
incr_s = input('Enter increase per second of debt: ');
incr_s = fliplr(incr_s);
incr_n = incr_s - 48;

year  = day_time(1);
leap = mod(year, 400) == 0 || (mod(year, 100) ~= 0 && mod(year, 4) == 0);
days_in_month(2) = days_in_month(2) + leap;
month = day_time(2);
day   = day_time(3);
hour  = day_time(4);
minute = day_time(5);
second = day_time(6);

while true
   fprintf('%d-%d-%d %d:%d:%d $%s\n', year, month, day, hour, minute, second, char(debt_s));
   second = mod(second+1, 60);
   if second == 0
      minute = mod(minute+1, 60);
      if minute == 0
         hour = mod(hour+1, 24);
         if hour == 0
            day = mod(day, days_in_month(month)) + 1;
            if day == 1
               month = mod(month, 12) + 1;
               if month == 1
                  year = year + 1;
                  leap = mod(year, 400) == 0 || (mod(year, 100) ~= 0 && mod(year, 4) == 0);
               end
            end
         end
      end
   end

   carry = false;
   non_zero = 1;
   for ii = 1:length(debt_n)
      if ii <= length(incr_n)
         debt_n(ii) = debt_n(ii) + incr_n(ii) + carry;
      else
         debt_n(ii) = debt_n(ii) + carry;
      end
      carry = debt_n(ii) > 9;
      if debt_n(ii) > 0
         non_zero = ii;
      end
      debt_n(ii) = mod(debt_n(ii), 10);
   end

   debt_s = char(fliplr(debt_n(1:non_zero)) + 48);
   pause(1);
end

