title: Program Binary Decimal Conversion 1
signature: function program_binary_decimal_conversion_1(n)
source_py: def program_binary_decimal_conversion_1(n):
      num = n
      dec_value = 0
      base1 = 1
      len1 = len(num)
      for i in range((len1 - 1), (- 1), (- 1)):
          if (num[i] == '1'):
              dec_value += base1
          base1 = (base1 * 2)
      return dec_value
source_cpp: int program_binary_decimal_conversion_1(string n) {
    string num = n;
    int dec_value = 0;
    int base = 1;
    int len = num . length ( );
    for ( int i = len - 1;
    i >= 0;
    i -- ) {
      if ( num [ i ] == '1' ) dec_value += base;
      base = base * 2;
    }
    return dec_value;
  }
question_info.entry_fn_name: program_binary_decimal_conversion_1
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
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 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("uEmIAgF", 0)
      print(string.format("TEST-0...%s",result))
  
      result = driver("753310137", 20)
      print(string.format("TEST-1...%s",result))
  
      result = driver("010011010", 154)
      print(string.format("TEST-2...%s",result))
  
      result = driver("kNi", 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver("04562016903312", 130)
      print(string.format("TEST-4...%s",result))
  
      result = driver("000111101", 61)
      print(string.format("TEST-5...%s",result))
  
      result = driver("bk", 0)
      print(string.format("TEST-6...%s",result))
  
      result = driver("9", 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver("1", 1)
      print(string.format("TEST-8...%s",result))
  
      result = driver("XxT nXLlk", 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"n": "uEmIAgF"}}, {"idx": 1, "outputs": 20, "inputs": {"n": "753310137"}}, {"idx": 2, "outputs": 154, "inputs": {"n": "010011010"}}, {"idx": 3, "outputs": 0, "inputs": {"n": "kNi"}}, {"idx": 4, "outputs": 130, "inputs": {"n": "04562016903312"}}, {"idx": 5, "outputs": 61, "inputs": {"n": "000111101"}}, {"idx": 6, "outputs": 0, "inputs": {"n": "bk"}}, {"idx": 7, "outputs": 0, "inputs": {"n": "9"}}, {"idx": 8, "outputs": 1, "inputs": {"n": "1"}}, {"idx": 9, "outputs": 0, "inputs": {"n": "XxT nXLlk"}}]