{"id":15474504,"url":"https://github.com/andyatkinson/recursion-examples","last_synced_at":"2026-05-13T06:07:55.522Z","repository":{"id":66952270,"uuid":"82730748","full_name":"andyatkinson/recursion-examples","owner":"andyatkinson","description":"Recursion examples in Ruby","archived":false,"fork":false,"pushed_at":"2019-10-24T18:11:51.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-12T08:45:52.014Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/andyatkinson.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-02-21T21:51:12.000Z","updated_at":"2019-10-24T18:11:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"ed46b06c-e35f-4193-ad46-4912314be7c3","html_url":"https://github.com/andyatkinson/recursion-examples","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"ab73d87b13cd9435968ebe9d649d4ce8551473da"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyatkinson%2Frecursion-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyatkinson%2Frecursion-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyatkinson%2Frecursion-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyatkinson%2Frecursion-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andyatkinson","download_url":"https://codeload.github.com/andyatkinson/recursion-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241404209,"owners_count":19957650,"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-10-02T03:02:33.602Z","updated_at":"2026-05-13T06:07:55.492Z","avatar_url":"https://github.com/andyatkinson.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Recursion Examples\n\nTree recursion, start with a root, perform an action, move to the left or right.\nIn a binary search tree, the value held by the node's left child is always less than or equal to its own value.\n\n\n##### Factorial\n\n```\nruby factorial.rb 3 #=\u003e 6\n```\n\n##### Fibonacci\n\n```\nruby fibonacci.rb 5 #=\u003e 5\n```\n\n##### Fibonacci with memoization\n\n##### Reverse a string\n\nGeneral approach, two cases, base case, string is 1 char long, then we know it is \"reversed\" because it is the same forwards or backwards (one char), otherwise we aren't at the base case.\n\nBuild a new string starting with last character, append a recursive call to the remaining chars in the string, from char 0 to penultimate char.\n\n```\nruby reverse.rb foobar\n```\n\n##### Permutations\n\nGet all permutations (without built-in function) for a string. Add a second version that removes duplicates.\nThis creates a recursion tree for words of 4 characters or more.\n\n#### More topics\n\n * Tail call recursion\n * Recursion with sorting algorithm\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyatkinson%2Frecursion-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandyatkinson%2Frecursion-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyatkinson%2Frecursion-examples/lists"}