brewersfan1976

clock_digits_count.rb

Jun 19th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.18 KB | None | 0 0
  1. def clockDigitsCount(startTime, finishTime)
  2.     output_array = Array.new
  3.    
  4.     start_hour = startTime[0]
  5.     start_minute = startTime[1]
  6.     start_second = startTime[2]
  7.     finish_hour = finishTime[0]
  8.     finish_minute = finishTime[1]
  9.     finish_second = finishTime[2]
  10.     x = 0
  11.     zero = 0
  12.     one = 0
  13.     two = 0
  14.     three = 0
  15.     four = 0
  16.     five = 0
  17.     six = 0
  18.     seven = 0
  19.     eight = 0
  20.     nine = 0
  21.    
  22.     start_time = (startTime[0] * 3600) + (startTime[1] * 60) + startTime[2]
  23.     finish_time = (finishTime[0] * 3600) + (finishTime[1] * 60) + finishTime[2]
  24.    
  25.     while (start_time <= finish_time)
  26.        
  27.            string = start_hour.to_s
  28.            string_length = string.length
  29.        
  30.            if start_hour < 10 then
  31.               zero = zero + 1
  32.            end
  33.        
  34.            while (x < string_length)
  35.                  if string[x] == "0" then
  36.                     zero = zero + 1
  37.                  end
  38.                      
  39.                  if string[x] == "1" then
  40.                     one = one + 1
  41.                  end
  42.                      
  43.                  if string[x] == "2" then
  44.                     two = two + 1
  45.                  end
  46.                      
  47.                  if string[x] == "3" then
  48.                     three = three + 1
  49.                  end
  50.                      
  51.                  if string[x] == "4" then
  52.                     four = four + 1
  53.                  end
  54.                      
  55.                  if string[x] == "5" then
  56.                     five = five + 1
  57.                  end
  58.                      
  59.                  if string[x] == "6" then
  60.                     six = six + 1
  61.                  end
  62.                      
  63.                  if string[x] == "7" then
  64.                     seven = seven + 1
  65.                  end
  66.                      
  67.                  if string[x] == "8" then
  68.                     eight = eight + 1
  69.                  end
  70.                      
  71.                  if string[x] == "9" then
  72.                     nine = nine + 1
  73.                  end
  74.                      
  75.                  x = x + 1
  76.            end
  77.            
  78.            x = 0
  79.                      
  80.            string = start_minute.to_s
  81.            string_length = string.length
  82.                      
  83.            if start_minute < 10 then
  84.               zero = zero + 1
  85.            end
  86.        
  87.            while (x < string_length)
  88.                  if string[x] == "0" then
  89.                     zero = zero + 1
  90.                  end
  91.                      
  92.                  if string[x] == "1" then
  93.                     one = one + 1
  94.                  end
  95.                      
  96.                  if string[x] == "2" then
  97.                     two = two + 1
  98.                  end
  99.                      
  100.                  if string[x] == "3" then
  101.                     three = three + 1
  102.                  end
  103.                      
  104.                  if string[x] == "4" then
  105.                     four = four + 1
  106.                  end
  107.                      
  108.                  if string[x] == "5" then
  109.                     five = five + 1
  110.                  end
  111.                      
  112.                  if string[x] == "6" then
  113.                     six = six + 1
  114.                  end
  115.                      
  116.                  if string[x] == "7" then
  117.                     seven = seven + 1
  118.                  end
  119.                      
  120.                  if string[x] == "8" then
  121.                     eight = eight + 1
  122.                  end
  123.                      
  124.                  if string[x] == "9" then
  125.                     nine = nine + 1
  126.                  end
  127.                      
  128.                  x = x + 1
  129.            end
  130.                      
  131.            x = 0
  132.                      
  133.            string = start_second.to_s
  134.            string_length = string.length
  135.                      
  136.            if start_second < 10 then
  137.               zero = zero + 1
  138.            end
  139.        
  140.            while (x < string_length)
  141.                  if string[x] == "0" then
  142.                     zero = zero + 1
  143.                  end
  144.                      
  145.                  if string[x] == "1" then
  146.                     one = one + 1
  147.                  end
  148.                      
  149.                  if string[x] == "2" then
  150.                     two = two + 1
  151.                  end
  152.                      
  153.                  if string[x] == "3" then
  154.                     three = three + 1
  155.                  end
  156.                      
  157.                  if string[x] == "4" then
  158.                     four = four + 1
  159.                  end
  160.                      
  161.                  if string[x] == "5" then
  162.                     five = five + 1
  163.                  end
  164.                      
  165.                  if string[x] == "6" then
  166.                     six = six + 1
  167.                  end
  168.                      
  169.                  if string[x] == "7" then
  170.                     seven = seven + 1
  171.                  end
  172.                      
  173.                  if string[x] == "8" then
  174.                     eight = eight + 1
  175.                  end
  176.                      
  177.                  if string[x] == "9" then
  178.                     nine = nine + 1
  179.                  end
  180.                      
  181.                  x = x + 1
  182.            end
  183.                      
  184.            x = 0
  185.                      
  186.            start_second = start_second + 1
  187.                      
  188.            if start_second == 60 then
  189.               start_second = 0
  190.               start_minute = start_minute + 1
  191.            end
  192.                
  193.            if start_minute == 60 then
  194.               start_minute = 0
  195.               start_hour = start_hour + 1
  196.            end
  197.                
  198.            if start_hour == 24 then
  199.               start_hour = 0
  200.               start_minute = 0
  201.               start_second = 0
  202.            end
  203.                
  204.            start_time = start_time + 1
  205.     end
  206.                
  207.     output_array[0] = zero
  208.     output_array[1] = one
  209.     output_array[2] = two
  210.     output_array[3] = three
  211.     output_array[4] = four
  212.     output_array[5] = five
  213.     output_array[6] = six
  214.     output_array[7] = seven
  215.     output_array[8] = eight
  216.     output_array[9] = nine
  217.                
  218.     return output_array
  219. end
Advertisement
Add Comment
Please, Sign In to add comment