title: Ugly Numbers
signature: uglyNumbers(n) {
test_code: import 'dart:convert';
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual.toString() == expected.toString();
  }
  
  String driver(n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }catch(exception_object){
          return exception_object.runtimeType.toString();
      }
  }
  
  int main() {
  
      print("TEST-0...${driver(
          27, 
          64)
      }");
  
      print("TEST-1...${driver(
          64, 
          450)
      }");
  
      print("TEST-2...${driver(
          93, 
          1250)
      }");
  
      print("TEST-3...${driver(
          90, 
          1152)
      }");
  
      print("TEST-4...${driver(
          85, 
          972)
      }");
  
      print("TEST-5...${driver(
          86, 
          1000)
      }");
  
      print("TEST-6...${driver(
          72, 
          625)
      }");
  
      print("TEST-7...${driver(
          86, 
          1000)
      }");
  
      print("TEST-8...${driver(
          32, 
          90)
      }");
  
      print("TEST-9...${driver(
          1, 
          1)
      }");
  
      return 0;
  }
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;
  }