title: Decimal Representation Given Binary String Divisible 10 Not
signature: function decimal_representation_given_binary_string_divisible_10_not(bin)
source_py: def decimal_representation_given_binary_string_divisible_10_not(bin):
      n = len(bin)
      if (bin[(n - 1)] == '1'):
          return False
      sum = 0
      i = (n - 2)
      while (i >= 0):
          if (bin[i] == '1'):
              posFromRight = ((n - i) - 1)
              if ((posFromRight % 4) == 1):
                  sum = (sum + 2)
              elif ((posFromRight % 4) == 2):
                  sum = (sum + 4)
              elif ((posFromRight % 4) == 3):
                  sum = (sum + 8)
              elif ((posFromRight % 4) == 0):
                  sum = (sum + 6)
          i = (i - 1)
      if ((sum % 10) == 0):
          return True
      return False
source_cpp: bool decimal_representation_given_binary_string_divisible_10_not(string bin) {
    int n = bin . size ( );
    if ( bin [ n - 1 ] == '1' ) return false;
    int sum = 0;
    for ( int i = n - 2;
    i >= 0;
    i -- ) {
      if ( bin [ i ] == '1' ) {
        int posFromRight = n - i - 1;
        if ( posFromRight % 4 == 1 ) sum = sum + 2;
        else if ( posFromRight % 4 == 2 ) sum = sum + 4;
        else if ( posFromRight % 4 == 3 ) sum = sum + 8;
        else if ( posFromRight % 4 == 0 ) sum = sum + 6;
      }
    }
    if ( sum % 10 == 0 ) return true;
    return false;
  }
question_info.entry_fn_name: decimal_representation_given_binary_string_divisible_10_not
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(bin, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(bin) 
      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("101000", true)
      print(string.format("TEST-0...%s",result))
  
      result = driver("39613456759141", false)
      print(string.format("TEST-1...%s",result))
  
      result = driver("11", false)
      print(string.format("TEST-2...%s",result))
  
      result = driver("PoiHjo", true)
      print(string.format("TEST-3...%s",result))
  
      result = driver("2", true)
      print(string.format("TEST-4...%s",result))
  
      result = driver("0000101", false)
      print(string.format("TEST-5...%s",result))
  
      result = driver("T  s dZKeDX gK", true)
      print(string.format("TEST-6...%s",result))
  
      result = driver("3944713969", false)
      print(string.format("TEST-7...%s",result))
  
      result = driver("1000", false)
      print(string.format("TEST-8...%s",result))
  
      result = driver("ifYUgdpmt", true)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": true, "inputs": {"bin": "101000"}}, {"idx": 1, "outputs": false, "inputs": {"bin": "39613456759141"}}, {"idx": 2, "outputs": false, "inputs": {"bin": "11"}}, {"idx": 3, "outputs": true, "inputs": {"bin": "PoiHjo"}}, {"idx": 4, "outputs": true, "inputs": {"bin": "2"}}, {"idx": 5, "outputs": false, "inputs": {"bin": "0000101"}}, {"idx": 6, "outputs": true, "inputs": {"bin": "T  s dZKeDX gK"}}, {"idx": 7, "outputs": false, "inputs": {"bin": "3944713969"}}, {"idx": 8, "outputs": false, "inputs": {"bin": "1000"}}, {"idx": 9, "outputs": true, "inputs": {"bin": "ifYUgdpmt"}}]