{"id":20057683,"url":"https://github.com/todesking/icfp2020","last_synced_at":"2025-07-29T16:04:57.754Z","repository":{"id":136155984,"uuid":"280382007","full_name":"todesking/ICFP2020","owner":"todesking","description":null,"archived":false,"fork":false,"pushed_at":"2020-07-24T19:53:24.000Z","size":207,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-02T09:45:09.255Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/todesking.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-07-17T09:21:40.000Z","updated_at":"2020-07-24T19:53:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"119825e6-b745-4c50-9cb9-cb87c915cf23","html_url":"https://github.com/todesking/ICFP2020","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/todesking/ICFP2020","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todesking%2FICFP2020","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todesking%2FICFP2020/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todesking%2FICFP2020/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todesking%2FICFP2020/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/todesking","download_url":"https://codeload.github.com/todesking/ICFP2020/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todesking%2FICFP2020/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267716396,"owners_count":24133135,"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-29T02:00:12.549Z","response_time":2574,"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":[],"created_at":"2024-11-13T12:59:53.849Z","updated_at":"2025-07-29T16:04:57.722Z","avatar_url":"https://github.com/todesking.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ICFPC 2020\n\n[ICFP Programming Contest 2020](https://icfpcontest2020.github.io/)用のリポジトリです。\n\n\n```shellsession\n# Galaxy evaluator\n$ cd emu\n$ sbt run\n```\n\n## 参加記\n\n今回は初参加でしたが(ソロ)、Galaxy evaluatorを書いただけで終了してしまいました(コンテスト終了後Web UIを追加)。\n\n* 2020-07-17 20:00 とりあえずリポジトリ作る\n* 2020-07-18 20:52 sterter kit (Scala) を導入してsubmitしたりAPI叩いたり。たぶんLightning roundで2点入ったと思うが定かでなし\n* 2020-07-18 20:00 コンテストおよびPegovkaのBlog読んで状況把握。言語仕様が与えられるので、処理系を作ってMessage #42を実行すれば何かがわかるらしいことはわかった\n* 2020-07-19 01:59 Galaxy evaluator作るかってことで、Web UI使うことを見越してPlayのプロジェクト作成\n* 2020-07-19 18:00 実装に取りかかる\n* 2020-07-19 22:57 checkerboard命令で詰まる。どうやら遅延評価が必要らしい\n* 2020-07-20 00:36 遅延評価実装してcheckerboard通す\n* 2020-07-20 03:39 Message #37まで一通りの命令を実装(modulateとかsendとか必要なかったことに後から気づく)\n* 2020-07-20 03:45 interact実装開始、Galaxyの動作テスト\n* 2020-07-20 07:54 遅延評価のバグをようやく修正、Galaxy動いたので満足して寝る(おわり)\n\n実働1日しかないやんけ、次回はもっと頑張りたい。\n\n実装開始がほぼ三日目からというサボりぶりだったんですが、公式がevaluatorの実装やゲームに使うプロトコルなどをどんどんネタバレしだしたのでどうしようかと思った。\n\n\n### 処理系の実装\n\n実装すべき言語は型なしλ計算ベースでこんなかんじ:\n\n```\nexpr          := number | function_name | var_name | apply\nfunction_name := /[a-z][a-z0-9]+/\nvar_name      := /:[a-z0-9]+/\napply         := `ap` expr expr\n```\n\n組み込み関数が色々定義してあって、\n\n```\nap ap add 1 2\n#=\u003e 3\n\nap ap cons 1 2\n#=\u003e (1 . 2)\n\nap ap cons ap neg 1 ap ap cons ap ap add 1 2 nil\n#=\u003e (-1, 3)\n```\n\nなどができる。各種のコンビネータ関数で制御構造を実現。\n\n\n[パーサ](emu/src/main/scala/Parser.scala)では空白で区切ってトークナイズし再帰的に式を読んで[AST](emu/src/main/scala/Tree.scala)構築。\n後々使うので、関数名の表現には引数の数を含めておく(`add:2`、`neg:1`等)。\n\n[評価機](emu/src/main/scala/Engine.scala)ではASTを読んで[値](emu/src/main/scala/V.scala)を生成。\n関数呼び出しが遅延されているので、必要に応じて中身を評価して取り出す。\n\n実装の概略としては、\n\n```\neval expr = unwrap (eval_lazy expr)\n\neval_lazy Tree.Num(n)         = V.Num(n)\neval_lazy Tree.FunName1(name) = V.FunName1(name)\neval_lazy Tree.App(f, x)      = V.LazyApp(eval_lazy(f), eval_lazy(x))\n\nunwrap value = cache.get_or_update(value, unwrap0(value))\n\nunwrap0 V.LazyApp(f, x) = unwrap(f) match {\n  case V.FunName1(name) =\u003e name match {\n    case \"neg\" =\u003e V.Num(unwrap(x).as_int * -1)\n    // ...\n  }\n  case V.FunName2(name) =\u003e V.FunApp2X(name, x)\n  case V.FunApp2X(name, x1) =\u003e name match {\n    case \"add\" =\u003e V.Num(unwrap(x1).as_int + unwrap(x).as_int)\n    // ...\n  }\n  // 組み込み関数はたかだか3引数までなのでこの実装で充分\n  case V.FunName3(name) =\u003e V.FunApp3X(name, x)\n  case V.FunApp3X(name, x1) =\u003e V.FunApp3XX(name, x1, x)\n  case V.FunApp3XX(name, x1, x2) =\u003e name match { ... }\n```\n\nみたいなかんじになりました。\n\n* 関数適用は遅延\n* 値が必要になったらキャッシュしつつ中身を計算する\n\nというだけの話だが苦戦してしまった……\n\nあとは変数を評価する時点ではまだ未定義だったりするのでこいつも遅延してやるとか、Consも関数として使えるのでapp可能にしてやるなど。\n\n## Web UI\n\nEvaluatorが動いたので、あとはgalaxyをprotocolとしてinteractすれば画像が帰ってくる。\n\n二値画像複数枚を適当に着色してまとめる、本当はcanvas使うべきだけど1ピクセルあたりdiv一個として表示(重い)、クリックしたらその座標と現在の状態を元に再度interact走らす。\nという処理を書いてこれを得た。\n\n![Galaxy](./galaxy.png)\n\nICFPC・完！！！！！！！\n\n(本当はこれでようやく入り口なんですが……)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftodesking%2Ficfp2020","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftodesking%2Ficfp2020","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftodesking%2Ficfp2020/lists"}