title: Ugly Numbers
signature: function ugly_numbers(n)
test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver(27, 64)
      print(string.format("TEST-0...%s",result))
  
      result = driver(64, 450)
      print(string.format("TEST-1...%s",result))
  
      result = driver(93, 1250)
      print(string.format("TEST-2...%s",result))
  
      result = driver(90, 1152)
      print(string.format("TEST-3...%s",result))
  
      result = driver(85, 972)
      print(string.format("TEST-4...%s",result))
  
      result = driver(86, 1000)
      print(string.format("TEST-5...%s",result))
  
      result = driver(72, 625)
      print(string.format("TEST-6...%s",result))
  
      result = driver(86, 1000)
      print(string.format("TEST-7...%s",result))
  
      result = driver(32, 90)
      print(string.format("TEST-8...%s",result))
  
      result = driver(1, 1)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
source_py: def ugly_numbers(n):
      ugly = ([0] * n)
      ugly[0] = 1
      i2 = i3 = i5 = 0
      next_multiple_of_2 = 2
      next_multiple_of_3 = 3
      next_multiple_of_5 = 5
      for l in range(1, n):
          ugly[l] = min(next_multiple_of_2, next_multiple_of_3, next_multiple_of_5)
          if (ugly[l] == next_multiple_of_2):
              i2 += 1
              next_multiple_of_2 = (ugly[i2] * 2)
          if (ugly[l] == next_multiple_of_3):
              i3 += 1
              next_multiple_of_3 = (ugly[i3] * 3)
          if (ugly[l] == next_multiple_of_5):
              i5 += 1
              next_multiple_of_5 = (ugly[i5] * 5)
      return ugly[(- 1)]
source_cpp: unsigned ugly_numbers(unsigned n) {
    unsigned ugly [ n ];
    unsigned i2 = 0, i3 = 0, i5 = 0;
    unsigned next_multiple_of_2 = 2;
    unsigned next_multiple_of_3 = 3;
    unsigned next_multiple_of_5 = 5;
    unsigned next_ugly_no = 1;
    ugly [ 0 ] = 1;
    for ( int i = 1;
    i < n;
    i ++ ) {
      next_ugly_no = min ( next_multiple_of_2, min ( next_multiple_of_3, next_multiple_of_5 ) );
      ugly [ i ] = next_ugly_no;
      if ( next_ugly_no == next_multiple_of_2 ) {
        i2 = i2 + 1;
        next_multiple_of_2 = ugly [ i2 ] * 2;
      }
      if ( next_ugly_no == next_multiple_of_3 ) {
        i3 = i3 + 1;
        next_multiple_of_3 = ugly [ i3 ] * 3;
      }
      if ( next_ugly_no == next_multiple_of_5 ) {
        i5 = i5 + 1;
        next_multiple_of_5 = ugly [ i5 ] * 5;
      }
    }
    return next_ugly_no;
  }