{"id":15405689,"url":"https://github.com/zverok/ruby_as_apl","last_synced_at":"2026-03-10T18:32:02.259Z","repository":{"id":136288839,"uuid":"264416781","full_name":"zverok/ruby_as_apl","owner":"zverok","description":"Conway's game of life in one statement of idiomatic Ruby... ported from APL","archived":false,"fork":false,"pushed_at":"2020-05-17T11:06:00.000Z","size":10,"stargazers_count":35,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-31T18:00:56.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zverok.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":"2020-05-16T10:56:05.000Z","updated_at":"2023-08-11T18:25:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"c21f1dcf-38b6-4d43-9f46-da5d7c4f5e94","html_url":"https://github.com/zverok/ruby_as_apl","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"309be68a29eb7cf134d2770ce4c0a1e82ec873f0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zverok/ruby_as_apl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fruby_as_apl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fruby_as_apl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fruby_as_apl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fruby_as_apl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zverok","download_url":"https://codeload.github.com/zverok/ruby_as_apl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zverok%2Fruby_as_apl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30347399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T15:55:29.454Z","status":"ssl_error","status_checked_at":"2026-03-10T15:54:58.440Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-10-01T16:18:15.718Z","updated_at":"2026-03-10T18:32:02.231Z","avatar_url":"https://github.com/zverok.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"This repository contains implementation of [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) in _one Ruby statement_.\n\nIt was inspired by (in)famous [APL's one-line](https://aplwiki.com/wiki/John_Scholes%27_Conway%27s_Game_of_Life) implementation and is a more-or-less straightforward port of it into idiomatic Ruby.\n\nTo port the algorithm, a small prototype library with APL-style Array were created—so, technically, it is not a one-statement implementation, but I still prefer to think about it as \"one-statement\" one, as the class implemented is of generic use (somewhat like [Numo::NArray](https://github.com/ruby-numo/numo-narray)), and operations used are familiar to any Rubyist.\n\nYou can read an [explanatory article](https://zverok.github.io/blog/2020-05-16-ruby-as-apl.html) in my blog, but here we'll just show an implementation:\n\n```ruby\nrequire 'apl'\n\nAA = APL::Ary\n\ndef life(current_gen)\n  current_gen.wrap\n    .product(AA[-1, 0, 1], \u0026:hrotate)\n    .product(AA[-1, 0, 1], \u0026:vrotate)\n    .flatten(1).reduce(\u0026:+)\n    .eq(AA[3, 4])\n    .zip(AA[1, current_gen], \u0026:\u0026)\n    .reduce(\u0026:|)\n    .unwrap\nend\n```\n\n...and its usage:\n\n```ruby\ndef show(grid)\n  # APL-style AA#values_at(aa) produces array of items from the first array, taken and shaped\n  # using numbers from second array as indexes.\n  puts AA[' ', '█'].values_at(grid)\nend\n\nglider = AA[1, 1, 1, 1, 0, 0, 0, 1, 0].reshape(3, 3)\ngrid = glider.take(-10, -10)\n\nshow grid.wrap\n# ┌──────────┐\n# │          │\n# │          │\n# │          │\n# │          │\n# │          │\n# │          │\n# │          │\n# │       ███│\n# │       █  │\n# │        █ │\n# └──────────┘\n\n\ngenerations = [grid]\n9.times { generations \u003c\u003c life(generations.last) }\n\nshow AA[*generations]\n\n# or, simpler, with 2.7's Enumerator#produce:\n\ngenerations = Enumerator.produce(grid) { |cur| life(cur) }.take(10).map(\u0026:wrap)\nshow AA[*generations]\n# ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐\n# │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │\n# │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │\n# │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │\n# │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │\n# │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │      █   │\n# │          │ │          │ │          │ │          │ │          │ │       █  │ │      ██  │ │      ██  │ │     ███  │ │     ██   │\n# │          │ │        █ │ │       ██ │ │       ██ │ │      ███ │ │      ██  │ │      █ █ │ │     ██   │ │     █    │ │     █ █  │\n# │       ███│ │       ██ │ │       █ █│ │      ██  │ │      █   │ │      █ █ │ │      █   │ │       █  │ │      █   │ │          │\n# │       █  │ │       █ █│ │       █  │ │        █ │ │       █  │ │          │ │          │ │          │ │          │ │          │\n# │        █ │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │ │          │\n# └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzverok%2Fruby_as_apl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzverok%2Fruby_as_apl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzverok%2Fruby_as_apl/lists"}