{"id":19672722,"url":"https://github.com/halilozel1903/kotlinsmithnumber","last_synced_at":"2025-07-28T01:34:29.026Z","repository":{"id":153177443,"uuid":"628413613","full_name":"halilozel1903/KotlinSmithNumber","owner":"halilozel1903","description":"This simple finds smith numbers in the Kotlin. 💫 1️⃣1️⃣","archived":false,"fork":false,"pushed_at":"2024-03-10T11:44:09.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-31T20:51:39.227Z","etag":null,"topics":["kotlin","kotlin-android","kotlin-android-application","kotlin-android-tutorial","kotlin-beginner","kotlin-example","kotlin-examples","kotlin-language","kotlin-sample","kotlin-sample-app","kotlin-tutorial","kotlin-tutorials"],"latest_commit_sha":null,"homepage":"https://halilozel1903.medium.com/membership","language":"Kotlin","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/halilozel1903.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,"zenodo":null}},"created_at":"2023-04-15T21:44:02.000Z","updated_at":"2023-04-15T21:54:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"f79eaa76-f95f-4b87-8153-f94b03b04888","html_url":"https://github.com/halilozel1903/KotlinSmithNumber","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/halilozel1903/KotlinSmithNumber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilozel1903%2FKotlinSmithNumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilozel1903%2FKotlinSmithNumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilozel1903%2FKotlinSmithNumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilozel1903%2FKotlinSmithNumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/halilozel1903","download_url":"https://codeload.github.com/halilozel1903/KotlinSmithNumber/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilozel1903%2FKotlinSmithNumber/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267451093,"owners_count":24089293,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["kotlin","kotlin-android","kotlin-android-application","kotlin-android-tutorial","kotlin-beginner","kotlin-example","kotlin-examples","kotlin-language","kotlin-sample","kotlin-sample-app","kotlin-tutorial","kotlin-tutorials"],"created_at":"2024-11-11T17:13:07.685Z","updated_at":"2025-07-28T01:34:29.005Z","avatar_url":"https://github.com/halilozel1903.png","language":"Kotlin","funding_links":["https://www.buymeacoffee.com/halilozel1903"],"categories":[],"sub_categories":[],"readme":"## Kotlin Smith Number 🎬 2️⃣ 📗\n\n![Kotlin Smith Number](https://miro.medium.com/v2/resize:fit:1400/format:webp/1*rgUu5-sCYn24KBnGDs0f5g.png)\n\nA `Smith number` is a composite number whose sum of digits in its prime factorization is equal to the sum of digits in the number itself. \n\nFor example, `85` is a Smith number because:\n85 = 5 x 17 (prime factorization) sum of digits in 85 = 8 + 5 = 13 sum of digits in 5 + 1 + 7 = 13\n\nHere is a program in `Kotlin` that finds all the Smith numbers within a given range:\n\n```kotlin\nfun main() {\n    val range = 1..100\n    println(\"Smith numbers between ${range.first} and ${range.last}:\")\n    range.filter { isSmithNumber(it) }.forEach(::println)\n}\n\nfun isSmithNumber(num: Int): Boolean {\n    return if (num \u003c 4) false\n    else sumOfDigits(num) == primeFactors(num).sumOf { sumOfDigits(it) }\n}\n\nfun primeFactors(n: Int): List\u003cInt\u003e {\n    var number = n\n    val factors = mutableListOf\u003cInt\u003e()\n    var i = 2\n    while (i \u003c= number) {\n        while (number % i == 0) {\n            factors.add(i)\n            number /= i\n        }\n        i++\n    }\n    return factors\n}\n\nfun sumOfDigits(n: Int): Int {\n    return n.toString().sumOf { it - '0' }\n}\n```\nThe `main` function sets a range for which Smith numbers are to be found, and loops through each number in the range. If a number is found to be a Smith number, it is printed to the console.\n\nThe `isSmithNumber` function checks whether a given number is a Smith number. It first checks if the number is less than 4, in which case it cannot be a composite number and therefore cannot be a Smith number. It then calculates the sum of digits in the number itself and in its prime factors, and returns `true` if the two sums are equal.\n\nThe `primeFactors` function returns a list of prime factors of a given number. It loops through each number from 2 to the square root of the given number, checking if each number is a factor. If a number is a factor, it is added to the list of factors and the given number is divided by it. If the given number is still greater than 1 after the loop, it is added to the list of factors as well.\n\nThe `sumOfDigits` function returns the sum of digits in a given number. It loops through each digit in the number, adding it to a running sum.\n\nNote that this program assumes that the given range starts from 1 and goes up to 100, but this can be easily modified by changing the values of `start` and `end` in the `main` function.\n\nWhen we run the program, it will output all the smith numbers up to the limit we set:\n\n```kotlin\nSmith numbers between 1 and 100:\n4\n5\n7\n11\n13\n17\n19\n22\n23\n27\n29\n31\n37\n41\n43\n47\n53\n58\n59\n61\n67\n71\n73\n79\n83\n85\n89\n94\n97\n```\n## Donation 💸\n\nIf this project help 💁 you, Can you give me a cup of coffee? ☕\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/halilozel1903)\n\n## License ℹ️\n```\nMIT License\n\nCopyright (c) 2023 Halil OZEL\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalilozel1903%2Fkotlinsmithnumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalilozel1903%2Fkotlinsmithnumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalilozel1903%2Fkotlinsmithnumber/lists"}