{"id":18633486,"url":"https://github.com/rahat-khan-pathan/hackerrank-custom-checker-code","last_synced_at":"2025-11-04T09:30:34.900Z","repository":{"id":204236560,"uuid":"711394744","full_name":"Rahat-Khan-Pathan/Hackerrank-Custom-Checker-Code","owner":"Rahat-Khan-Pathan","description":"Hackerrank custom checker code for C programming. Verify function definitions \u0026 calls within main function. Enhance code quality. 🚀","archived":false,"fork":false,"pushed_at":"2023-10-29T15:44:41.000Z","size":24,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-27T08:10:31.194Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rahat-Khan-Pathan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-29T05:54:15.000Z","updated_at":"2023-11-22T14:12:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"b0896aaa-3ea0-4584-93dc-8bd34c010a12","html_url":"https://github.com/Rahat-Khan-Pathan/Hackerrank-Custom-Checker-Code","commit_stats":null,"previous_names":["rahat-khan-pathan/hackerrank-custom-checker-code"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rahat-Khan-Pathan%2FHackerrank-Custom-Checker-Code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rahat-Khan-Pathan%2FHackerrank-Custom-Checker-Code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rahat-Khan-Pathan%2FHackerrank-Custom-Checker-Code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rahat-Khan-Pathan%2FHackerrank-Custom-Checker-Code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rahat-Khan-Pathan","download_url":"https://codeload.github.com/Rahat-Khan-Pathan/Hackerrank-Custom-Checker-Code/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239432092,"owners_count":19637780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T05:15:25.714Z","updated_at":"2025-11-04T09:30:34.862Z","avatar_url":"https://github.com/Rahat-Khan-Pathan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Step 1: Extract the source code from a HackerRank file\n\nTo extract the source code from a HackerRank file, you can follow these steps:\n\n```python\nwith open(t_obj.submission_code_path, \"r\") as code_file:\n    code_contents = code_file.read()\n```\n\n### Step 2: Remove all comments from the source code\n\nTo remove comments from the source code, consider using regular expressions or code parsing. Here's a general approach:\n\n- Use regular expressions or code parsing to identify and remove comments in the source code.\n- Make sure to handle both single-line (//) and multi-line (/\\* \\*/) comments.\n\n```python\ncomment_pattern = r'//.*|/\\*[\\s\\S]*?\\*/'\ncode_contents = re.sub(comment_pattern, '', code_contents)\n```\n\n### Step 3: Convert all macros or typedef definitions for data types\n\nTo convert macros or typedef definitions for data types, you can use regular expressions to identify and replace them. For example, if you want to convert macros like `#define` or `typedef`:\n\n- Use regular expressions to identify macro or typedef definitions in the source code.\n- Replace them with their expanded forms or desired types if necessary.\n\n```python\n# convert all defines for data types only\ndefine_pattern = r'#\\s*define\\s+(\\w+)\\s+([^#\\n]+)'\ndefine_matches = re.findall(define_pattern, code_contents)\ndefine_dict = {name: value.strip() for name, value in define_matches}\ndef replace_macros(match):\n    macro_name = match.group(0)\n    if macro_name in define_dict:\n        return define_dict[macro_name]\n    return match.group(0)\ncode_contents = re.sub(r'\\b\\w+\\b', replace_macros, code_contents)\n# convert all typedef definitions of data types only\ntypedef_dict = {}\ntypedef_pattern = r'typedef\\s+([\\w\\s]+)\\s+(\\w+);'\nmatches = re.findall(typedef_pattern, code_contents, re.DOTALL)\nfor match in matches:\n    typedef_dict[match[1]] = match[0].strip()\ndef replace_typedefs(match):\n    typedef_alias = match.group(1)\n    if typedef_alias in typedef_dict:\n        return typedef_dict[typedef_alias]\n    return match.group(0)\ncode_contents = re.sub(r'\\b(\\w+)\\b', replace_typedefs, code_contents)\n```\n\n### Step 4: Check if the relevant function is present in the source code\n\nTo check if a specific function is present in the source code:\n\n- Make sure to remove spaces from the line to check all cases.\n- Make sure you know all the valid function definitions.\n- Verify if the function's declaration is found in the source code.\n\n```python\nfunction_name = \"intfuntion_name(\"\nfunction_name2 = \"longlongfuntion_name(\"\nfunction_name3 = \"longlongintfuntion_name(\"\n# removed all spaces from line to check all cases\ncode_without_spaces = re.sub(r'\\s', '', code_contents)\nif function_name in code_without_spaces or function_name2 in code_without_spaces or function_name3 in code_without_spaces:\n        # the function is found in the source code\n```\n\n### Step 5: If step 4 is okay, check if the function is called inside the main function scope\n\nTo check if a function is called inside the `main` function scope:\n\n- Search for the `main` function declaration in the source code.\n- Use stack to keep track of the scope of main function.\n\n```python\ncode_lines = code_contents.split('\\n')\ninside_main = False\nbr_found = False\nfound=False\nstack = []\nfunction_call_name = \"function_name(\"\n# now check if the function was called inside the main function\nfor line in code_lines:\n    if \"main(\" in line:\n        inside_main = True\n    if inside_main:\n        if len(stack)==0 and br_found==True:\n            break\n        if function_call_name in re.sub(r'\\s', '', line): # removed all spaces from line to check\n            # the caller function is found inside the scope of main function\n            r_obj.message = \"Success\"\n            r_obj.result = True\n            r_obj.score = 1.0\n            found=True\n            break\n        if '{' in line:\n            stack.append('{')\n            br_found=True\n        if '}' in line:\n            stack.pop()\nif found == False:\n    r_obj.message = \"The 'count_before_one()' function is not called inside the main function.\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahat-khan-pathan%2Fhackerrank-custom-checker-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frahat-khan-pathan%2Fhackerrank-custom-checker-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahat-khan-pathan%2Fhackerrank-custom-checker-code/lists"}