{"id":19436378,"url":"https://github.com/beached/nerd_snipe_001","last_synced_at":"2025-10-29T14:04:18.191Z","repository":{"id":149955361,"uuid":"79176602","full_name":"beached/nerd_snipe_001","owner":"beached","description":"Remove the conditionals","archived":false,"fork":false,"pushed_at":"2017-01-17T14:25:18.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-25T06:46:41.736Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beached.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-17T01:43:22.000Z","updated_at":"2017-01-17T01:46:39.000Z","dependencies_parsed_at":"2023-05-05T06:19:27.707Z","dependency_job_id":null,"html_url":"https://github.com/beached/nerd_snipe_001","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/beached/nerd_snipe_001","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fnerd_snipe_001","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fnerd_snipe_001/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fnerd_snipe_001/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fnerd_snipe_001/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beached","download_url":"https://codeload.github.com/beached/nerd_snipe_001/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fnerd_snipe_001/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260016014,"owners_count":22946319,"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-10T15:10:51.811Z","updated_at":"2025-10-13T16:44:36.180Z","avatar_url":"https://github.com/beached.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nerd_snipe_001\nRemove the conditionals from\n\n```\nif( n % 2 == 0 ) {\n    result = 8 + n/2;\n} else {\n    result = 7 - n/2;\n}\n```\n\nCompiled with g++ -O3 -march=native benchmark.cpp and the results are consitantly around when run with ./a.out 1500\n```\na-\u003e 'Darrell Wright': 1199.53ms for 244500 calls 4.90606μs per item\nb-\u003e 'Darrell Wright': 1332.5ms for 264000 calls 5.04736μs per item\nc-\u003e 'Darrell Wright': 1051.46ms for 243000 calls 4.327μs per item\nd-\u003e 'Arnold Kim': 663.334ms for 276000 calls 2.40338μs per item\ne-\u003e 'Original': 959.478ms for 222000 calls 4.32197μs per item\nf-\u003e 'Shaun Winters - A': 678.823ms for 255000 calls 2.66205μs per item\ng-\u003e 'Matt Bryan - A': 884.76ms for 244500 calls 3.61865μs per item\nh-\u003e 'Matt Bryan - B': 864.59ms for 238500 calls 3.62512μs per item\ni-\u003e 'Shaun Winters - B': 6325.32ms for 262500 calls 24.0964μs per item\n```\nSee [Arnold's Explanation](./arnolds_explanation.jpeg) for a description of his approach\n\nMatt Bryan's approach was:\n```\nEVEN\n8 + n / 2; \n= (16 + n) / 2\n= (16 + Zn) / 2\n= (15 + Z + Zn) / 2\n\nODD\n7 - n / 2;\n=(14 - n) / 2\n=(14+Zn) / 2 \n=(15 + Z + Zn) / 2\n```\nSince we now have an equation that works for both odd and even numbers, all we need is a solution for Z\n```\nZ = ((n%2)* -2) + 1 should work\n\nSo\n\nint Z = ((n%2)*(-2)) + 1 \nreturn (15 + Z + Z * n) / 2\n```\nI added a + (n%2) to Matt's to fix up odd arguments \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeached%2Fnerd_snipe_001","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeached%2Fnerd_snipe_001","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeached%2Fnerd_snipe_001/lists"}