title: Program Binary Decimal Conversion
signature: function program_binary_decimal_conversion(n)
source_py: def program_binary_decimal_conversion(n):
      num = n
      dec_value = 0
      base = 1
      temp = num
      while temp:
          last_digit = (temp % 10)
          temp = int((temp / 10))
          dec_value += (last_digit * base)
          base = (base * 2)
      return dec_value
source_cpp: int program_binary_decimal_conversion(int n) {
    int num = n;
    int dec_value = 0;
    int base = 1;
    int temp = num;
    while ( temp ) {
      int last_digit = temp % 10;
      temp = temp / 10;
      dec_value += last_digit * base;
      base = base * 2;
    }
    return dec_value;
  }
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(70, 14)
      print(string.format("TEST-0...%s",result))
  
      result = driver(95, 23)
      print(string.format("TEST-1...%s",result))
  
      result = driver(41, 9)
      print(string.format("TEST-2...%s",result))
  
      result = driver(97, 25)
      print(string.format("TEST-3...%s",result))
  
      result = driver(8, 8)
      print(string.format("TEST-4...%s",result))
  
      result = driver(16, 8)
      print(string.format("TEST-5...%s",result))
  
      result = driver(41, 9)
      print(string.format("TEST-6...%s",result))
  
      result = driver(57, 17)
      print(string.format("TEST-7...%s",result))
  
      result = driver(81, 17)
      print(string.format("TEST-8...%s",result))
  
      result = driver(78, 22)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 14, "inputs": {"n": 70}}, {"idx": 1, "outputs": 23, "inputs": {"n": 95}}, {"idx": 2, "outputs": 9, "inputs": {"n": 41}}, {"idx": 3, "outputs": 25, "inputs": {"n": 97}}, {"idx": 4, "outputs": 8, "inputs": {"n": 8}}, {"idx": 5, "outputs": 8, "inputs": {"n": 16}}, {"idx": 6, "outputs": 9, "inputs": {"n": 41}}, {"idx": 7, "outputs": 17, "inputs": {"n": 57}}, {"idx": 8, "outputs": 17, "inputs": {"n": 81}}, {"idx": 9, "outputs": 22, "inputs": {"n": 78}}]
question_info.extension: lua
question_info.entry_fn_name: program_binary_decimal_conversion
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__