title: Minimum Perimeter N Blocks
signature: function minimum_perimeter_n_blocks(n)
source_py: def minimum_perimeter_n_blocks(n):
      l = math.sqrt(n)
      sq = (l * l)
      if (sq == n):
          return (l * 4)
      else:
          row = (n / l)
          perimeter = (2 * (l + row))
          if ((n % l) != 0):
              perimeter += 2
          return perimeter
source_cpp: int minimum_perimeter_n_blocks(int n) {
    int l = sqrt ( n );
    int sq = l * l;
    if ( sq == n ) return l * 4;
    else {
      long long int row = n / l;
      long long int perimeter = 2 * ( l + row );
      if ( n % l != 0 ) perimeter += 2;
      return perimeter;
    }
  }
question_info.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 math.abs(actual - expected) < 1e-09
  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(45, 28.832815729997478)
      print(string.format("TEST-0...%s",result))
  
      result = driver(80, 37.77708763999664)
      print(string.format("TEST-1...%s",result))
  
      result = driver(54, 29.393876913398138)
      print(string.format("TEST-2...%s",result))
  
      result = driver(48, 29.712812921102035)
      print(string.format("TEST-3...%s",result))
  
      result = driver(83, 36.4417343165772)
      print(string.format("TEST-4...%s",result))
  
      result = driver(68, 32.984845004941285)
      print(string.format("TEST-5...%s",result))
  
      result = driver(32, 24.62741699796952)
      print(string.format("TEST-6...%s",result))
  
      result = driver(20, 19.88854381999832)
      print(string.format("TEST-7...%s",result))
  
      result = driver(68, 32.984845004941285)
      print(string.format("TEST-8...%s",result))
  
      result = driver(66, 34.49615361854384)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 28.832815729997478, "inputs": {"n": 45}}, {"idx": 1, "outputs": 37.77708763999664, "inputs": {"n": 80}}, {"idx": 2, "outputs": 29.393876913398138, "inputs": {"n": 54}}, {"idx": 3, "outputs": 29.712812921102035, "inputs": {"n": 48}}, {"idx": 4, "outputs": 36.4417343165772, "inputs": {"n": 83}}, {"idx": 5, "outputs": 32.984845004941285, "inputs": {"n": 68}}, {"idx": 6, "outputs": 24.62741699796952, "inputs": {"n": 32}}, {"idx": 7, "outputs": 19.88854381999832, "inputs": {"n": 20}}, {"idx": 8, "outputs": 32.984845004941285, "inputs": {"n": 68}}, {"idx": 9, "outputs": 34.49615361854384, "inputs": {"n": 66}}]
question_info.extension: lua
question_info.entry_fn_name: minimum_perimeter_n_blocks
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__