paiza.ioでnadesiko その22

# 概要
paiza.ioでnadesikoやってみた。
練習問題やってみた。

# 練習問題
qiitaapiを、叩け。

# サンプルコード

```
URL = 「https://qiita.com/api/v2/users/ohisama@github/items?page=1&per_page=5」
データ = URLからAJAXテキスト取得。
データを表示。


```

# 実行結果

```
[{"rendered_body":"\u003ch1 data-sourcepos=\"1:1-1:8\"\u003e\n\u003cspan id=\"概要\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%A6%82%E8%A6%81\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e概要\u003c/h1\u003e\n\u003cp data-sourcepos=\"2:1-3:35\"\u003eenebularで、alexaスキルのwebhookを返してみた。\u003cbr\u003e\nirリモートを選んでみた。\u003c/p\u003e\n\u003ch1 data-sourcepos=\"5:1-5:37\"\u003e\n\u003cspan id=\"irリモートを選んでみた\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#ir%E3%83%AA%E3%83%A2%E3%83%BC%E3%83%88%E3%82%92%E9%81%B8%E3%82%93%E3%81%A7%E3%81%BF%E3%81%9F\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003eirリモートを選んでみた。\u003c/h1\u003e\n\u003ctable data-sourcepos=\"7:1-14:41\"\u003e\n\u003cthead\u003e\n\u003ctr data-sourcepos=\"7:1-7:30\"\u003e\n\u003cth style=\"text-align: left\" data-sourcepos=\"7:2-7:7\"\u003e候補\u003c/th\u003e\n\u003cth style=\"text-align: left\" data-sourcepos=\"7:9-7:12\"\u003etuya\u003c/th\u003e\n\u003cth style=\"text-align: left\" data-sourcepos=\"7:14-7:19\"\u003eNature\u003c/th\u003e\n\u003cth style=\"text-align: left\" data-sourcepos=\"7:21-7:29\"\u003eSwitchBot\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr data-sourcepos=\"9:1-9:51\"\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"9:2-9:17\"\u003eandroidアプリ\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"9:19-9:28\"\u003etuya smart\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"9:30-9:40\"\u003eNature Remo\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"9:42-9:50\"\u003eSwitchBot\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr data-sourcepos=\"10:1-10:25\"\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"10:2-10:12\"\u003ealexa連携\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"10:14-10:16\"\u003e〇\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"10:18-10:20\"\u003e〇\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"10:22-10:24\"\u003e〇\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr data-sourcepos=\"11:1-11:50\"\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"11:2-11:21\"\u003eirリモコン価格\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"11:23-11:30\"\u003e2,780円\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"11:32-11:40\"\u003e11,919円\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"11:42-11:49\"\u003e4,166円\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr data-sourcepos=\"12:1-12:61\"\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"12:2-12:16\"\u003eクラウドapi\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"12:18-12:24\"\u003etuyaapi\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"12:26-12:46\"\u003eNature Remo Cloud API\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"12:48-12:60\"\u003eSwitchBot Api\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr data-sourcepos=\"13:1-13:45\"\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"13:2-13:7\"\u003epython\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"13:9-13:16\"\u003etinytuya\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"13:18-13:31\"\u003eNatureRemo API\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"13:33-13:44\"\u003eSwitchBotAPI\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr data-sourcepos=\"14:1-14:41\"\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"14:2-14:28\"\u003eデヴァイスクローン\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"14:30-14:36\"\u003etasmote\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"14:38-14:38\"\u003e?\u003c/td\u003e\n\u003ctd style=\"text-align: left\" data-sourcepos=\"14:40-14:40\"\u003e?\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cp data-sourcepos=\"16:1-16:9\"\u003e以上。\u003c/p\u003e\n","body":"# 概要\nenebularで、alexaスキルのwebhookを返してみた。\nirリモートを選んでみた。\n\n# irリモートを選んでみた。\n\n|候補|tuya|Nature|SwitchBot|\n|:--|:--|:--|:--|\n|androidアプリ|tuya smart|Nature Remo|SwitchBot|\n|alexa連携|〇|〇|〇|\n|irリモコン価格|2,780円|11,919円|4,166円|\n|クラウドapi|tuyaapi|Nature Remo Cloud API|SwitchBot Api|\n|python|tinytuya|NatureRemo API|SwitchBotAPI|\n|デヴァイスクローン|tasmote|?|?|\n\n以上。\n","coediting":false,"comments_count":0,"created_at":"2023-03-15T10:52:46+09:00","group":null,"id":"c247d091def22bdf66c0","likes_count":0,"private":false,"reactions_count":0,"stocks_count":0,"tags":[{"name":"enebular","versions":[]},{"name":"AlexaSkillsKit","versions":[]}],"title":"enebularでalexaスキル その13","updated_at":"2023-03-15T11:04:24+09:00","url":"https://qiita.com/ohisama@github/items/c247d091def22bdf66c0","user":{"description":null,"facebook_id":null,"followees_count":0,"followers_count":63,"github_login_name":"ohisama","id":"ohisama@github","items_count":3321,"linkedin_id":null,"location":null,"name":"","organization":null,"permanent_id":18104,"profile_image_url":"https://secure.gravatar.com/avatar/2e0bb506fbe90e6572bf92fa05db88d3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","team_only":false,"twitter_screen_name":null,"website_url":null},"page_views_count":null,"team_membership":null},{"rendered_body":"\u003ch1 data-sourcepos=\"1:1-1:8\"\u003e\n\u003cspan id=\"概要\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%A6%82%E8%A6%81\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e概要\u003c/h1\u003e\n\u003cp data-sourcepos=\"2:1-3:22\"\u003epaiza.ioでnadesikoやってみた。\u003cbr\u003e\najax使ってみた。\u003c/p\u003e\n\u003ch1 data-sourcepos=\"6:1-6:23\"\u003e\n\u003cspan id=\"サンプルコード\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%82%B3%E3%83%BC%E3%83%89\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003eサンプルコード\u003c/h1\u003e\n\u003cdiv class=\"code-frame\" data-lang=\"text\" data-sourcepos=\"8:1-26:3\"\u003e\u003cdiv class=\"highlight\"\u003e\u003cpre\u003e\u003ccode\u003e\nURL = 「https://api.aoikujira.com/tenki/week.php?fmt=json\u0026amp;city=319」\nデータ = URLからAJAXテキスト取得\nN = データをJSONデコード。\nN[319][0][\"weathers\"]を表示。\n\nURL = 「https://api.aoikujira.com/tenki/week.php?fmt=json\u0026amp;city=319」\nN = URLからAJAX_JSON取得\nN[319][0][\"weathers\"]を表示。\n\n\nAPIは「https://api.aoikujira.com/time/get.php」\nAPIからAJAX受信した時には\n　　「現在時刻：{対象}」を表示。\nここまで。\n\n\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/div\u003e\n\u003ch1 data-sourcepos=\"28:1-28:14\"\u003e\n\u003cspan id=\"実行結果\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e実行結果\u003c/h1\u003e\n\u003cdiv class=\"code-frame\" data-lang=\"text\" data-sourcepos=\"30:1-35:3\"\u003e\u003cdiv class=\"highlight\"\u003e\u003cpre\u003e\u003ccode\u003eくもり　昼過ぎ　から　晴れ\nくもり　昼過ぎ　から　晴れ\n現在時刻：2023/03/14 13:41:52\n\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/div\u003e\n\u003ch1 data-sourcepos=\"37:1-37:11\"\u003e\n\u003cspan id=\"成果物\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%88%90%E6%9E%9C%E7%89%A9\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e成果物\u003c/h1\u003e\n\u003cp data-sourcepos=\"39:1-39:48\"\u003e\u003cqiita-embed-ogp src=\"https://paiza.io/projects/ZKpERScLfwkoqKdWrxJJzA\"\u003e\u003c/qiita-embed-ogp\u003e\u003c/p\u003e\n\u003cp data-sourcepos=\"42:1-42:9\"\u003e以上。\u003c/p\u003e\n","body":"# 概要\npaiza.ioでnadesikoやってみた。\najax使ってみた。\n\n\n# サンプルコード\n\n```\n\nURL = 「https://api.aoikujira.com/tenki/week.php?fmt=json\u0026city=319」\nデータ = URLからAJAXテキスト取得\nN = データをJSONデコード。\nN[319][0][\"weathers\"]を表示。\n\nURL = 「https://api.aoikujira.com/tenki/week.php?fmt=json\u0026city=319」\nN = URLからAJAX_JSON取得\nN[319][0][\"weathers\"]を表示。\n\n\nAPIは「https://api.aoikujira.com/time/get.php」\nAPIからAJAX受信した時には\n　　「現在時刻：{対象}」を表示。\nここまで。\n\n\n```\n\n# 実行結果\n\n```\nくもり　昼過ぎ　から　晴れ\nくもり　昼過ぎ　から　晴れ\n現在時刻：2023/03/14 13:41:52\n\n```\n\n# 成果物\n\nhttps://paiza.io/projects/ZKpERScLfwkoqKdWrxJJzA\n\n\n以上。\n","coediting":false,"comments_count":0,"created_at":"2023-03-14T13:47:17+09:00","group":null,"id":"1ced456e631408911286","likes_count":0,"private":false,"reactions_count":0,"stocks_count":0,"tags":[{"name":"なでしこ","versions":[]},{"name":"paiza.IO","versions":[]}],"title":"paiza.ioでnadesiko その21","updated_at":"2023-03-14T13:47:17+09:00","url":"https://qiita.com/ohisama@github/items/1ced456e631408911286","user":{"description":null,"facebook_id":null,"followees_count":0,"followers_count":63,"github_login_name":"ohisama","id":"ohisama@github","items_count":3321,"linkedin_id":null,"location":null,"name":"","organization":null,"permanent_id":18104,"profile_image_url":"https://secure.gravatar.com/avatar/2e0bb506fbe90e6572bf92fa05db88d3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","team_only":false,"twitter_screen_name":null,"website_url":null},"page_views_count":null,"team_membership":null},{"rendered_body":"\u003ch1 data-sourcepos=\"1:1-1:8\"\u003e\n\u003cspan id=\"概要\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%A6%82%E8%A6%81\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e概要\u003c/h1\u003e\n\u003cp data-sourcepos=\"2:1-3:30\"\u003epaiza.ioでelixirやってみた。\u003cbr\u003e\n練習問題やってみた。\u003c/p\u003e\n\u003ch1 data-sourcepos=\"5:1-5:14\"\u003e\n\u003cspan id=\"練習問題\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e練習問題\u003c/h1\u003e\n\u003cp data-sourcepos=\"6:1-6:36\"\u003eハノイの塔を可視化せよ。\u003c/p\u003e\n\u003ch1 data-sourcepos=\"8:1-8:26\"\u003e\n\u003cspan id=\"参考にしたページ\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E5%8F%82%E8%80%83%E3%81%AB%E3%81%97%E3%81%9F%E3%83%9A%E3%83%BC%E3%82%B8\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e参考にしたページ\u003c/h1\u003e\n\u003cp data-sourcepos=\"10:1-10:52\"\u003e\u003ciframe id=\"qiita-embed-content__8a0ea6d92c5aafe8037fb8284fe9f051\" src=\"https://qiita.com/embed-contents/link-card#qiita-embed-content__8a0ea6d92c5aafe8037fb8284fe9f051\" data-content=\"https%3A%2F%2Fqiita.com%2Fkob58im%2Fitems%2Feb30f4f06dafacb7ae6b\" frameborder=\"0\" scrolling=\"no\" loading=\"lazy\" style=\"width:100%;\" height=\"29\"\u003e\n\u003c/iframe\u003e\n\u003c/p\u003e\n\u003ch1 data-sourcepos=\"13:1-13:23\"\u003e\n\u003cspan id=\"サンプルコード\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%82%B3%E3%83%BC%E3%83%89\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003eサンプルコード\u003c/h1\u003e\n\u003cdiv class=\"code-frame\" data-lang=\"text\" data-sourcepos=\"15:1-307:3\"\u003e\u003cdiv class=\"highlight\"\u003e\u003cpre\u003e\u003ccode\u003e\ndefmodule Stack do\n\tdef start_link do\n\t\tAgent.start_link(fn -\u0026gt;\n\t\t\t[]\n\t\tend, name: __MODULE__)\n\tend\n\tdef drop do\n\t\tAgent.update(__MODULE__, fn stack -\u0026gt;\n\t\t    po = length(stack) - 2\n\t\t\tstack = List.delete_at(stack, po + 1)\n\t\tend)\n\tend\n\tdef get do\n\t\tAgent.get(__MODULE__, fn stack -\u0026gt;\n\t\t\tstack\n\t\tend)\n\tend\n\tdef rev do\n\t\tAgent.get(__MODULE__, fn stack -\u0026gt;\n\t\t\tEnum.reverse(stack)\n\t\tend)\n\tend\n\tdef push(v) do\n\t\tAgent.update(__MODULE__, fn stack -\u0026gt;\n\t\t\tstack ++ [v]\n\t\tend)\n\tend\nend\n\n\n\ndefmodule Hanoi do\n  def hanoi(n, a, b, c) do\n    if n \u0026gt; 0 do\n      hanoi n - 1, a, c, b\n      Stack.push(\"move(#{a}, #{b});\")\n      hanoi n - 1, c, b, a\n    end\n  end\nend\n\nStack.start_link\nHanoi.hanoi 4, \"0\", \"1\", \"2\"\nIO.puts \"\"\"\n\u0026lt;!doctype html\u0026gt;\n\n\u0026lt;html\u0026gt;\n  \u0026lt;head\u0026gt;\n    \u0026lt;link rel=\"stylesheet\" href=\"lib/style.css\"\u0026gt;\n    \u0026lt;script src=\"https://cdnjs.cloudflare.com/ajax/libs/three.js/99/three.min.js\"\u0026gt;\u0026lt;/script\u0026gt;\n  \u0026lt;/head\u0026gt;\n  \u0026lt;body\u0026gt;\n\u0026lt;canvas id=\"myCanvas\" width=\"400\" height=\"400\"\u0026gt;\u0026lt;/canvas\u0026gt;\n\u0026lt;script\u0026gt;\nlet dragStartX;\nlet dragStartY;\nlet dragStarted = false;\nlet currentAngleX = 3 * Math.PI / 4;\nlet currentAngleY = Math.PI / 7;\nlet oldAngle = -100000; \nconst width = 400;\nconst height = 400;\nconst N = 4;\nconst holeR = 22;\nconst poleR = 13;\nconst thickness = 35;\nconst minR = 40;\nconst stepR = 22;\nconst poleHeight = thickness * (N + 4);\nconst distX = 1000 / 4;\nconst distZ = 1000 / 4;\nconst renderer = new THREE.WebGLRenderer({\n  canvas: document.querySelector('#myCanvas')\n});\nconst scene = new THREE.Scene();\nconst camera = new THREE.OrthographicCamera(-680, +680, 680, -680, 1, 1500);\nwindow.addEventListener('load', init);\nconst canvas = document.getElementById(\"myCanvas\");\ncanvas.addEventListener('mousedown', onMouseDown, false);\ncanvas.addEventListener('mousemove', onMouseMove, false);\ncanvas.addEventListener('mouseup'  , onMouseUp  , false);\ncanvas.addEventListener('mouseover', onMouseOver, false);\nlet rings = [];\nlet instructions = [];\nlet ringInPoles = [];\nfunction makeRingGeometry(radius, holeRadius, extrude) {\n  let arcShape = new THREE.Shape();\n  arcShape.moveTo(0, 0);\n  arcShape.arc(0, 0, radius, 0, Math.PI * 2, false);\n  if (holeRadius \u0026gt; 0) \n  {\n    let holePath = new THREE.Path();\n    holePath.moveTo(0, 0);\n    holePath.arc(0, 0, holeRadius, 0, Math.PI * 2, true);\n    arcShape.holes.push(holePath);\n  }\n  let geometry = new THREE.ExtrudeGeometry(arcShape, extrude);\n  let axis = new THREE.Vector3(1, 0, 0).normalize();\n  let angle = Math.PI / 2;\n  geometry.applyMatrix(new THREE.Matrix4().makeRotationAxis(axis, angle));\n  return geometry;\n}\nfunction init() {\n  renderer.setPixelRatio(window.devicePixelRatio);\n  renderer.setSize(width, height);\n  camera.position.set(0, 0, +800);\n  const light = new THREE.HemisphereLight(0xdddddd, 0x555555, 1.0);\n  scene.add(light);\n  let extrudeSettings = { \n    amount: thickness, \n    bevelEnabled: true, \n    bevelSegments: 2, \n    steps: 2 \n  };\n  let extrudeSettingsPole = { \n    amount: poleHeight, \n    bevelEnabled: true, \n    bevelSegments: 2, \n    steps: 2 \n  };\n  let material = new THREE.MeshLambertMaterial({ \n    color: 0x7777ff,\n    side: THREE.DoubleSide \n  });\n  let materialLast = new THREE.MeshLambertMaterial({ \n    color: 0xcccccc,\n    side: THREE.DoubleSide \n  });\n  let materialPole = new THREE.MeshLambertMaterial({ \n    color: 0xcc3333,\n    side: THREE.DoubleSide \n  });\n  ringInPoles=[[], [], []];\n  for (let i = 0; i \u0026lt; N; i++)\n  {\n    let geom = makeRingGeometry(minR + i * stepR, holeR, extrudeSettings);\n    let mat = new THREE.Matrix4().makeTranslation(-distX, (N - 1 - i + 1) * thickness, -distZ);\n    geom.applyMatrix(mat);\n    if (i === N - 1)\n    {\n      rings.push(new THREE.Mesh(geom, materialLast));\n    }\n    else \n    {\n      rings.push(new THREE.Mesh(geom, material));\n    }\n    ringInPoles[0].push(N - 1 - i);\n    scene.add(rings[i]);\n  }\n  let geomPole;\n  let mat;\n  geomPole = makeRingGeometry(poleR, 0, extrudeSettingsPole);\n  mat = new THREE.Matrix4().makeTranslation(-distX, poleHeight, -distZ);\n  geomPole.applyMatrix(mat);\n  scene.add(new THREE.Mesh(geomPole, materialPole));\n  geomPole = makeRingGeometry(poleR, 0, extrudeSettingsPole);\n  mat = new THREE.Matrix4().makeTranslation(0, poleHeight, 0);\n  geomPole.applyMatrix(mat);\n  scene.add(new THREE.Mesh(geomPole, materialPole));\n  geomPole = makeRingGeometry(poleR, 0, extrudeSettingsPole);\n  mat = new THREE.Matrix4().makeTranslation(distX, poleHeight, distZ);\n  geomPole.applyMatrix(mat);\n  scene.add(new THREE.Mesh(geomPole, materialPole));\n  let gridHelper = new THREE.GridHelper(1000, 8);\n  scene.add(gridHelper); \n  updateCameraPos();\n  redraw();\n\"\"\"\nEnum.map(Stack.rev, fn v -\u0026gt;\n    IO.puts v\nend)\nIO.puts \"\"\"\n  setInterval(timerFunc, 166);\n}\nfunction redraw() {\n  renderer.render(scene, camera);\n}\nfunction move(pole1, pole2) {\n  instructions.push([\"transport\", pole1, pole2]);\n}\nfunction fetchInstruction() {\n  if (instructions.length === 0)\n  {\n    return 0;\n  }\n  let inst = instructions.pop();\n  if (inst[0] == \"transport\") \n  {\n    let poleFrom = inst[1];\n    let poleTo = inst[2];\n    let ringsFrom = ringInPoles[poleFrom];\n    let ringsTo = ringInPoles[poleTo];\n    let distanceToUp = poleHeight - ringInPoles[poleFrom].length * thickness + thickness * 2;\n    let distanceToDown = poleHeight - ringInPoles[poleTo].length * thickness + thickness * (2 - 1);\n    let distanceHorizontal = distX * (poleTo - poleFrom);\n    let ringI = ringsFrom.pop();\n    ringsTo.push(ringI);\n    for (let i = 0; i \u0026lt; distanceToDown / thickness; i++)\n    {\n      instructions.push([\"moveY\", ringI, -thickness]);\n    }\n    for (let i = 0; i \u0026lt; Math.abs(distanceHorizontal) / 50; i++)\n    {\n      instructions.push([\"moveXZ\", ringI, Math.sign(distanceHorizontal) * 50]);\n    }\n    for (let i = 0; i \u0026lt; distanceToUp / thickness; i++)\n    {\n      instructions.push([\"moveY\", ringI, thickness]);\n    }\n    return fetchInstruction();\n  }\n  else if (inst[0] == \"moveY\")\n  {\n    let ringI = inst[1];\n    let moveY = inst[2];\n    mat = new THREE.Matrix4().makeTranslation(0, moveY, 0);\n    rings[ringI].geometry.applyMatrix(mat);\n    return instructions.length;\n  }\n  else if (inst[0] == \"moveXZ\")\n  {\n    let ringI = inst[1];\n    let moveXZ = inst[2];\n    mat = new THREE.Matrix4().makeTranslation(moveXZ, 0, moveXZ);\n    rings[ringI].geometry.applyMatrix(mat);\n    return instructions.length;\n  }\n  return 0;\n}\nfunction timerFunc() {\n  fetchInstruction();\n  redraw();\n}\nfunction onMouseDown(e) {\n  let rect = e.target.getBoundingClientRect();\n  let x = e.clientX - rect.left;\n  let y = e.clientY - rect.top;\n  dragStartX = x;\n  dragStartY = y;\n  dragStarted = true;\n}\nfunction updateCameraPos() {\n  camera.position.x = 900 * Math.cos(currentAngleY) * (Math.cos(currentAngleX));\n  camera.position.y = 900 * Math.sin(currentAngleY);\n  camera.position.z = 900 * Math.cos(currentAngleY) * (Math.sin(currentAngleX));\n  camera.lookAt(new THREE.Vector3(0, 100, 0));\n}\nfunction onMouseMove(e) {\n  let rect = e.target.getBoundingClientRect();\n  let x = e.clientX - rect.left;\n  let y = e.clientY - rect.top;\n  if (dragStarted) \n  {\n    let dx = x - dragStartX;\n    let dy = y - dragStartY;\n    currentAngleX += dx / 50;\n    currentAngleY += dy / 50;\n    if (currentAngleY \u0026gt; 0.45 * Math.PI) \n    {\n      currentAngleY = 0.45 * Math.PI;\n    }\n    else if (currentAngleY \u0026lt; -0.45 * Math.PI)\n    {\n      currentAngleY = -0.45 * Math.PI;\n    }\n    dragStartX = x;\n    dragStartY = y;\n    updateCameraPos();\n    redraw();\n  }\n}\nfunction onMouseUp(e) {\n  dragStarted = false;\n}\nfunction onMouseOver(e) {\n  dragStarted = false;\n}\n\u0026lt;/script\u0026gt;\n  \u0026lt;/body\u0026gt;\n\u0026lt;/html\u0026gt;\n\"\"\"\n\n\n\n\n\n\n\n\n\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/div\u003e\n\u003ch1 data-sourcepos=\"309:1-309:14\"\u003e\n\u003cspan id=\"実行結果\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e実行結果\u003c/h1\u003e\n\u003cp data-sourcepos=\"311:1-311:120\"\u003e\u003ca href=\"https://camo.qiitausercontent.com/f6bb964d9f0b13f9648bb2e278b395c7232cf362/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f31383130342f63323265366531382d353037372d303936392d356630312d6563643063353361306461642e706e67\" target=\"_blank\" rel=\"nofollow noopener\"\u003e\u003cimg src=\"https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F18104%2Fc22e6e18-5077-0969-5f01-ecd0c53a0dad.png?ixlib=rb-4.0.0\u0026amp;auto=format\u0026amp;gif-q=60\u0026amp;q=75\u0026amp;s=39c915d12d1cab6e3ac2859e3581ce66\" alt=\"image.png\" data-canonical-src=\"https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/c22e6e18-5077-0969-5f01-ecd0c53a0dad.png\" srcset=\"https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F18104%2Fc22e6e18-5077-0969-5f01-ecd0c53a0dad.png?ixlib=rb-4.0.0\u0026amp;auto=format\u0026amp;gif-q=60\u0026amp;q=75\u0026amp;w=1400\u0026amp;fit=max\u0026amp;s=0fb41c6f38bc9c7db28d920a665fb280 1x\" loading=\"lazy\"\u003e\u003c/a\u003e\u003c/p\u003e\n\u003ch1 data-sourcepos=\"314:1-314:11\"\u003e\n\u003cspan id=\"成果物\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%88%90%E6%9E%9C%E7%89%A9\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e成果物\u003c/h1\u003e\n\u003cp data-sourcepos=\"316:1-316:64\"\u003e\u003ciframe id=\"qiita-embed-content__23d8e422784b1a9cd6317899ce706dc1\" src=\"https://qiita.com/embed-contents/link-card#qiita-embed-content__23d8e422784b1a9cd6317899ce706dc1\" data-content=\"https%3A%2F%2Fpaiza.io%2Fprojects%2FQrIWVQgiOKxVz71j2BSeag%3Flanguage%3Delixir\" frameborder=\"0\" scrolling=\"no\" loading=\"lazy\" style=\"width:100%;\" height=\"29\"\u003e\n\u003c/iframe\u003e\n\u003c/p\u003e\n\u003cp data-sourcepos=\"319:1-319:9\"\u003e以上。\u003c/p\u003e\n","body":"# 概要\npaiza.ioでelixirやってみた。\n練習問題やってみた。\n\n# 練習問題\nハノイの塔を可視化せよ。\n\n# 参考にしたページ\n\nhttps://qiita.com/kob58im/items/eb30f4f06dafacb7ae6b\n\n\n# サンプルコード\n\n```\n\ndefmodule Stack do\n\tdef start_link do\n\t\tAgent.start_link(fn -\u003e\n\t\t\t[]\n\t\tend, name: __MODULE__)\n\tend\n\tdef drop do\n\t\tAgent.update(__MODULE__, fn stack -\u003e\n\t\t    po = length(stack) - 2\n\t\t\tstack = List.delete_at(stack, po + 1)\n\t\tend)\n\tend\n\tdef get do\n\t\tAgent.get(__MODULE__, fn stack -\u003e\n\t\t\tstack\n\t\tend)\n\tend\n\tdef rev do\n\t\tAgent.get(__MODULE__, fn stack -\u003e\n\t\t\tEnum.reverse(stack)\n\t\tend)\n\tend\n\tdef push(v) do\n\t\tAgent.update(__MODULE__, fn stack -\u003e\n\t\t\tstack ++ [v]\n\t\tend)\n\tend\nend\n\n\n\ndefmodule Hanoi do\n  def hanoi(n, a, b, c) do\n    if n \u003e 0 do\n      hanoi n - 1, a, c, b\n      Stack.push(\"move(#{a}, #{b});\")\n      hanoi n - 1, c, b, a\n    end\n  end\nend\n\nStack.start_link\nHanoi.hanoi 4, \"0\", \"1\", \"2\"\nIO.puts \"\"\"\n\u003c!doctype html\u003e\n\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003clink rel=\"stylesheet\" href=\"lib/style.css\"\u003e\n    \u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/three.js/99/three.min.js\"\u003e\u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n\u003ccanvas id=\"myCanvas\" width=\"400\" height=\"400\"\u003e\u003c/canvas\u003e\n\u003cscript\u003e\nlet dragStartX;\nlet dragStartY;\nlet dragStarted = false;\nlet currentAngleX = 3 * Math.PI / 4;\nlet currentAngleY = Math.PI / 7;\nlet oldAngle = -100000; \nconst width = 400;\nconst height = 400;\nconst N = 4;\nconst holeR = 22;\nconst poleR = 13;\nconst thickness = 35;\nconst minR = 40;\nconst stepR = 22;\nconst poleHeight = thickness * (N + 4);\nconst distX = 1000 / 4;\nconst distZ = 1000 / 4;\nconst renderer = new THREE.WebGLRenderer({\n  canvas: document.querySelector('#myCanvas')\n});\nconst scene = new THREE.Scene();\nconst camera = new THREE.OrthographicCamera(-680, +680, 680, -680, 1, 1500);\nwindow.addEventListener('load', init);\nconst canvas = document.getElementById(\"myCanvas\");\ncanvas.addEventListener('mousedown', onMouseDown, false);\ncanvas.addEventListener('mousemove', onMouseMove, false);\ncanvas.addEventListener('mouseup'  , onMouseUp  , false);\ncanvas.addEventListener('mouseover', onMouseOver, false);\nlet rings = [];\nlet instructions = [];\nlet ringInPoles = [];\nfunction makeRingGeometry(radius, holeRadius, extrude) {\n  let arcShape = new THREE.Shape();\n  arcShape.moveTo(0, 0);\n  arcShape.arc(0, 0, radius, 0, Math.PI * 2, false);\n  if (holeRadius \u003e 0) \n  {\n    let holePath = new THREE.Path();\n    holePath.moveTo(0, 0);\n    holePath.arc(0, 0, holeRadius, 0, Math.PI * 2, true);\n    arcShape.holes.push(holePath);\n  }\n  let geometry = new THREE.ExtrudeGeometry(arcShape, extrude);\n  let axis = new THREE.Vector3(1, 0, 0).normalize();\n  let angle = Math.PI / 2;\n  geometry.applyMatrix(new THREE.Matrix4().makeRotationAxis(axis, angle));\n  return geometry;\n}\nfunction init() {\n  renderer.setPixelRatio(window.devicePixelRatio);\n  renderer.setSize(width, height);\n  camera.position.set(0, 0, +800);\n  const light = new THREE.HemisphereLight(0xdddddd, 0x555555, 1.0);\n  scene.add(light);\n  let extrudeSettings = { \n    amount: thickness, \n    bevelEnabled: true, \n    bevelSegments: 2, \n    steps: 2 \n  };\n  let extrudeSettingsPole = { \n    amount: poleHeight, \n    bevelEnabled: true, \n    bevelSegments: 2, \n    steps: 2 \n  };\n  let material = new THREE.MeshLambertMaterial({ \n    color: 0x7777ff,\n    side: THREE.DoubleSide \n  });\n  let materialLast = new THREE.MeshLambertMaterial({ \n    color: 0xcccccc,\n    side: THREE.DoubleSide \n  });\n  let materialPole = new THREE.MeshLambertMaterial({ \n    color: 0xcc3333,\n    side: THREE.DoubleSide \n  });\n  ringInPoles=[[], [], []];\n  for (let i = 0; i \u003c N; i++)\n  {\n    let geom = makeRingGeometry(minR + i * stepR, holeR, extrudeSettings);\n    let mat = new THREE.Matrix4().makeTranslation(-distX, (N - 1 - i + 1) * thickness, -distZ);\n    geom.applyMatrix(mat);\n    if (i === N - 1)\n    {\n      rings.push(new THREE.Mesh(geom, materialLast));\n    }\n    else \n    {\n      rings.push(new THREE.Mesh(geom, material));\n    }\n    ringInPoles[0].push(N - 1 - i);\n    scene.add(rings[i]);\n  }\n  let geomPole;\n  let mat;\n  geomPole = makeRingGeometry(poleR, 0, extrudeSettingsPole);\n  mat = new THREE.Matrix4().makeTranslation(-distX, poleHeight, -distZ);\n  geomPole.applyMatrix(mat);\n  scene.add(new THREE.Mesh(geomPole, materialPole));\n  geomPole = makeRingGeometry(poleR, 0, extrudeSettingsPole);\n  mat = new THREE.Matrix4().makeTranslation(0, poleHeight, 0);\n  geomPole.applyMatrix(mat);\n  scene.add(new THREE.Mesh(geomPole, materialPole));\n  geomPole = makeRingGeometry(poleR, 0, extrudeSettingsPole);\n  mat = new THREE.Matrix4().makeTranslation(distX, poleHeight, distZ);\n  geomPole.applyMatrix(mat);\n  scene.add(new THREE.Mesh(geomPole, materialPole));\n  let gridHelper = new THREE.GridHelper(1000, 8);\n  scene.add(gridHelper); \n  updateCameraPos();\n  redraw();\n\"\"\"\nEnum.map(Stack.rev, fn v -\u003e\n    IO.puts v\nend)\nIO.puts \"\"\"\n  setInterval(timerFunc, 166);\n}\nfunction redraw() {\n  renderer.render(scene, camera);\n}\nfunction move(pole1, pole2) {\n  instructions.push([\"transport\", pole1, pole2]);\n}\nfunction fetchInstruction() {\n  if (instructions.length === 0)\n  {\n    return 0;\n  }\n  let inst = instructions.pop();\n  if (inst[0] == \"transport\") \n  {\n    let poleFrom = inst[1];\n    let poleTo = inst[2];\n    let ringsFrom = ringInPoles[poleFrom];\n    let ringsTo = ringInPoles[poleTo];\n    let distanceToUp = poleHeight - ringInPoles[poleFrom].length * thickness + thickness * 2;\n    let distanceToDown = poleHeight - ringInPoles[poleTo].length * thickness + thickness * (2 - 1);\n    let distanceHorizontal = distX * (poleTo - poleFrom);\n    let ringI = ringsFrom.pop();\n    ringsTo.push(ringI);\n    for (let i = 0; i \u003c distanceToDown / thickness; i++)\n    {\n      instructions.push([\"moveY\", ringI, -thickness]);\n    }\n    for (let i = 0; i \u003c Math.abs(distanceHorizontal) / 50; i++)\n    {\n      instructions.push([\"moveXZ\", ringI, Math.sign(distanceHorizontal) * 50]);\n    }\n    for (let i = 0; i \u003c distanceToUp / thickness; i++)\n    {\n      instructions.push([\"moveY\", ringI, thickness]);\n    }\n    return fetchInstruction();\n  }\n  else if (inst[0] == \"moveY\")\n  {\n    let ringI = inst[1];\n    let moveY = inst[2];\n    mat = new THREE.Matrix4().makeTranslation(0, moveY, 0);\n    rings[ringI].geometry.applyMatrix(mat);\n    return instructions.length;\n  }\n  else if (inst[0] == \"moveXZ\")\n  {\n    let ringI = inst[1];\n    let moveXZ = inst[2];\n    mat = new THREE.Matrix4().makeTranslation(moveXZ, 0, moveXZ);\n    rings[ringI].geometry.applyMatrix(mat);\n    return instructions.length;\n  }\n  return 0;\n}\nfunction timerFunc() {\n  fetchInstruction();\n  redraw();\n}\nfunction onMouseDown(e) {\n  let rect = e.target.getBoundingClientRect();\n  let x = e.clientX - rect.left;\n  let y = e.clientY - rect.top;\n  dragStartX = x;\n  dragStartY = y;\n  dragStarted = true;\n}\nfunction updateCameraPos() {\n  camera.position.x = 900 * Math.cos(currentAngleY) * (Math.cos(currentAngleX));\n  camera.position.y = 900 * Math.sin(currentAngleY);\n  camera.position.z = 900 * Math.cos(currentAngleY) * (Math.sin(currentAngleX));\n  camera.lookAt(new THREE.Vector3(0, 100, 0));\n}\nfunction onMouseMove(e) {\n  let rect = e.target.getBoundingClientRect();\n  let x = e.clientX - rect.left;\n  let y = e.clientY - rect.top;\n  if (dragStarted) \n  {\n    let dx = x - dragStartX;\n    let dy = y - dragStartY;\n    currentAngleX += dx / 50;\n    currentAngleY += dy / 50;\n    if (currentAngleY \u003e 0.45 * Math.PI) \n    {\n      currentAngleY = 0.45 * Math.PI;\n    }\n    else if (currentAngleY \u003c -0.45 * Math.PI)\n    {\n      currentAngleY = -0.45 * Math.PI;\n    }\n    dragStartX = x;\n    dragStartY = y;\n    updateCameraPos();\n    redraw();\n  }\n}\nfunction onMouseUp(e) {\n  dragStarted = false;\n}\nfunction onMouseOver(e) {\n  dragStarted = false;\n}\n\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n\"\"\"\n\n\n\n\n\n\n\n\n\n```\n\n# 実行結果\n\n![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/c22e6e18-5077-0969-5f01-ecd0c53a0dad.png)\n\n\n# 成果物\n\nhttps://paiza.io/projects/QrIWVQgiOKxVz71j2BSeag?language=elixir\n\n\n以上。\n","coediting":false,"comments_count":0,"created_at":"2023-03-13T16:49:42+09:00","group":null,"id":"bc2754ee537cc3d796fe","likes_count":1,"private":false,"reactions_count":0,"stocks_count":0,"tags":[{"name":"Elixir","versions":[]},{"name":"paiza.IO","versions":[]},{"name":"ハノイの塔","versions":[]}],"title":"paiza.ioでelixir その212","updated_at":"2023-03-13T16:49:42+09:00","url":"https://qiita.com/ohisama@github/items/bc2754ee537cc3d796fe","user":{"description":null,"facebook_id":null,"followees_count":0,"followers_count":63,"github_login_name":"ohisama","id":"ohisama@github","items_count":3321,"linkedin_id":null,"location":null,"name":"","organization":null,"permanent_id":18104,"profile_image_url":"https://secure.gravatar.com/avatar/2e0bb506fbe90e6572bf92fa05db88d3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","team_only":false,"twitter_screen_name":null,"website_url":null},"page_views_count":null,"team_membership":null},{"rendered_body":"\u003ch1 data-sourcepos=\"1:1-1:8\"\u003e\n\u003cspan id=\"概要\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%A6%82%E8%A6%81\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e概要\u003c/h1\u003e\n\u003cp data-sourcepos=\"2:1-3:30\"\u003epaiza.ioでelixirやってみた。\u003cbr\u003e\n練習問題やってみた。\u003c/p\u003e\n\u003ch1 data-sourcepos=\"5:1-5:14\"\u003e\n\u003cspan id=\"練習問題\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e練習問題\u003c/h1\u003e\n\u003cp data-sourcepos=\"6:1-6:36\"\u003eハノイの塔の解を求めよ。\u003c/p\u003e\n\u003ch1 data-sourcepos=\"8:1-8:23\"\u003e\n\u003cspan id=\"サンプルコード\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%82%B3%E3%83%BC%E3%83%89\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003eサンプルコード\u003c/h1\u003e\n\u003cdiv class=\"code-frame\" data-lang=\"text\" data-sourcepos=\"10:1-42:3\"\u003e\u003cdiv class=\"highlight\"\u003e\u003cpre\u003e\u003ccode\u003e\n\ndefmodule Hanoi do\n  def hanoi(n, a, b, c) do\n    if n \u0026gt; 0 do\n      hanoi n - 1, a, c, b\n      IO.puts \"#{n}を #{a} -\u0026gt; #{b}\"\n      hanoi n - 1, c, b, a\n    end\n  end\nend\n\n#Hanoi.hanoi 4, \"A\", \"B\", \"C\"\nHanoi.hanoi 4, \"0\", \"1\", \"2\"\n\ndefmodule Hanoi do\n    def hanoi(n, x, y, z) do\n        if n \u0026gt; 0 do\n            hanoi(n - 1, x, z, y)\n        end \n        IO.puts \"#{x} -\u0026gt; #{y}\"\n        if n \u0026gt; 0 do\n            hanoi(n - 1, x, z, y)\n        end\n    end\nend\n\nHanoi.hanoi(4, \"a\", \"b\", \"c\")\n\n\n\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/div\u003e\n\u003ch1 data-sourcepos=\"44:1-44:14\"\u003e\n\u003cspan id=\"実行結果\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e実行結果\u003c/h1\u003e\n\u003cdiv class=\"code-frame\" data-lang=\"text\" data-sourcepos=\"46:1-94:3\"\u003e\u003cdiv class=\"highlight\"\u003e\u003cpre\u003e\u003ccode\u003e1を 0 -\u0026gt; 2\n2を 0 -\u0026gt; 1\n1を 2 -\u0026gt; 1\n3を 0 -\u0026gt; 2\n1を 1 -\u0026gt; 0\n2を 1 -\u0026gt; 2\n1を 0 -\u0026gt; 2\n4を 0 -\u0026gt; 1\n1を 2 -\u0026gt; 1\n2を 2 -\u0026gt; 0\n1を 1 -\u0026gt; 0\n3を 2 -\u0026gt; 1\n1を 0 -\u0026gt; 2\n2を 0 -\u0026gt; 1\n1を 2 -\u0026gt; 1\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; b\na -\u0026gt; c\na -\u0026gt; b\n\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/div\u003e\n\u003ch1 data-sourcepos=\"96:1-96:11\"\u003e\n\u003cspan id=\"成果物\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%88%90%E6%9E%9C%E7%89%A9\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e成果物\u003c/h1\u003e\n\u003cp data-sourcepos=\"98:1-98:48\"\u003e\u003cqiita-embed-ogp src=\"https://paiza.io/projects/l3UKquyAPVQZJa7tfEBqxg\"\u003e\u003c/qiita-embed-ogp\u003e\u003c/p\u003e\n\u003cp data-sourcepos=\"101:1-101:9\"\u003e以上。\u003c/p\u003e\n","body":"# 概要\npaiza.ioでelixirやってみた。\n練習問題やってみた。\n\n# 練習問題\nハノイの塔の解を求めよ。\n\n# サンプルコード\n\n```\n\n\ndefmodule Hanoi do\n  def hanoi(n, a, b, c) do\n    if n \u003e 0 do\n      hanoi n - 1, a, c, b\n      IO.puts \"#{n}を #{a} -\u003e #{b}\"\n      hanoi n - 1, c, b, a\n    end\n  end\nend\n\n#Hanoi.hanoi 4, \"A\", \"B\", \"C\"\nHanoi.hanoi 4, \"0\", \"1\", \"2\"\n\ndefmodule Hanoi do\n    def hanoi(n, x, y, z) do\n        if n \u003e 0 do\n            hanoi(n - 1, x, z, y)\n        end \n        IO.puts \"#{x} -\u003e #{y}\"\n        if n \u003e 0 do\n            hanoi(n - 1, x, z, y)\n        end\n    end\nend\n\nHanoi.hanoi(4, \"a\", \"b\", \"c\")\n\n\n\n```\n\n# 実行結果\n\n```\n1を 0 -\u003e 2\n2を 0 -\u003e 1\n1を 2 -\u003e 1\n3を 0 -\u003e 2\n1を 1 -\u003e 0\n2を 1 -\u003e 2\n1を 0 -\u003e 2\n4を 0 -\u003e 1\n1を 2 -\u003e 1\n2を 2 -\u003e 0\n1を 1 -\u003e 0\n3を 2 -\u003e 1\n1を 0 -\u003e 2\n2を 0 -\u003e 1\n1を 2 -\u003e 1\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e b\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e b\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e b\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e b\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e c\na -\u003e b\na -\u003e b\na -\u003e b\na -\u003e c\na -\u003e b\n\n```\n\n# 成果物\n\nhttps://paiza.io/projects/l3UKquyAPVQZJa7tfEBqxg\n\n\n以上。\n\n\n","coediting":false,"comments_count":0,"created_at":"2023-03-13T15:55:45+09:00","group":null,"id":"c962ee1e2d00e806c8c2","likes_count":1,"private":false,"reactions_count":0,"stocks_count":0,"tags":[{"name":"Elixir","versions":[]},{"name":"paiza.IO","versions":[]},{"name":"ハノイの塔","versions":[]}],"title":"paiza.ioでelixir その211","updated_at":"2023-03-13T15:55:45+09:00","url":"https://qiita.com/ohisama@github/items/c962ee1e2d00e806c8c2","user":{"description":null,"facebook_id":null,"followees_count":0,"followers_count":63,"github_login_name":"ohisama","id":"ohisama@github","items_count":3321,"linkedin_id":null,"location":null,"name":"","organization":null,"permanent_id":18104,"profile_image_url":"https://secure.gravatar.com/avatar/2e0bb506fbe90e6572bf92fa05db88d3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","team_only":false,"twitter_screen_name":null,"website_url":null},"page_views_count":null,"team_membership":null},{"rendered_body":"\u003ch1 data-sourcepos=\"1:1-1:8\"\u003e\n\u003cspan id=\"概要\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%A6%82%E8%A6%81\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e概要\u003c/h1\u003e\n\u003cp data-sourcepos=\"2:1-3:30\"\u003epaiza.ioでelixirやってみた。\u003cbr\u003e\n練習問題やってみた。\u003c/p\u003e\n\u003ch1 data-sourcepos=\"5:1-5:14\"\u003e\n\u003cspan id=\"練習問題\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e練習問題\u003c/h1\u003e\n\u003cp data-sourcepos=\"6:1-6:33\"\u003e入れた順と逆順で返せ。\u003c/p\u003e\n\u003ch1 data-sourcepos=\"8:1-8:23\"\u003e\n\u003cspan id=\"サンプルコード\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%82%B3%E3%83%BC%E3%83%89\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003eサンプルコード\u003c/h1\u003e\n\u003cdiv class=\"code-frame\" data-lang=\"text\" data-sourcepos=\"10:1-53:3\"\u003e\u003cdiv class=\"highlight\"\u003e\u003cpre\u003e\u003ccode\u003e\ndefmodule Stack do\n\tdef start_link do\n\t\tAgent.start_link(fn -\u0026gt;\n\t\t\t[]\n\t\tend, name: __MODULE__)\n\tend\n\tdef drop do\n\t\tAgent.update(__MODULE__, fn stack -\u0026gt;\n\t\t    po = length(stack) - 2\n\t\t\tstack = List.delete_at(stack, po + 1)\n\t\tend)\n\tend\n\tdef get do\n\t\tAgent.get(__MODULE__, fn stack -\u0026gt;\n\t\t\tstack\n\t\tend)\n\tend\n\tdef rev do\n\t\tAgent.get(__MODULE__, fn stack -\u0026gt;\n\t\t\tEnum.reverse(stack)\n\t\tend)\n\tend\n\tdef push(v) do\n\t\tAgent.update(__MODULE__, fn stack -\u0026gt;\n\t\t\tstack ++ [v]\n\t\tend)\n\tend\nend\n\nStack.start_link\nStack.push(\"a\")\nStack.push(\"b\")\nStack.push(\"c\")\nStack.get\n|\u0026gt; IO.inspect\nStack.rev\n|\u0026gt; IO.inspect\nEnum.map(Stack.rev, fn v -\u0026gt;\n    IO.puts v\nend)\n\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/div\u003e\n\u003ch1 data-sourcepos=\"55:1-55:14\"\u003e\n\u003cspan id=\"実行結果\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e実行結果\u003c/h1\u003e\n\u003cdiv class=\"code-frame\" data-lang=\"text\" data-sourcepos=\"57:1-64:3\"\u003e\u003cdiv class=\"highlight\"\u003e\u003cpre\u003e\u003ccode\u003e[\"a\", \"b\", \"c\"]\n[\"c\", \"b\", \"a\"]\nc\nb\na\n\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/div\u003e\n\u003ch1 data-sourcepos=\"66:1-66:11\"\u003e\n\u003cspan id=\"成果物\" class=\"fragment\"\u003e\u003c/span\u003e\u003ca href=\"#%E6%88%90%E6%9E%9C%E7%89%A9\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e\u003c/a\u003e成果物\u003c/h1\u003e\n\u003cp data-sourcepos=\"68:1-68:64\"\u003e\u003cqiita-embed-ogp src=\"https://paiza.io/projects/w2rBHK76LtqwiE7PF_s1-Q?language=elixir\"\u003e\u003c/qiita-embed-ogp\u003e\u003c/p\u003e\n\u003cp data-sourcepos=\"71:1-71:9\"\u003e以上。\u003c/p\u003e\n","body":"# 概要\npaiza.ioでelixirやってみた。\n練習問題やってみた。\n\n# 練習問題\n入れた順と逆順で返せ。\n\n# サンプルコード\n\n```\n\ndefmodule Stack do\n\tdef start_link do\n\t\tAgent.start_link(fn -\u003e\n\t\t\t[]\n\t\tend, name: __MODULE__)\n\tend\n\tdef drop do\n\t\tAgent.update(__MODULE__, fn stack -\u003e\n\t\t    po = length(stack) - 2\n\t\t\tstack = List.delete_at(stack, po + 1)\n\t\tend)\n\tend\n\tdef get do\n\t\tAgent.get(__MODULE__, fn stack -\u003e\n\t\t\tstack\n\t\tend)\n\tend\n\tdef rev do\n\t\tAgent.get(__MODULE__, fn stack -\u003e\n\t\t\tEnum.reverse(stack)\n\t\tend)\n\tend\n\tdef push(v) do\n\t\tAgent.update(__MODULE__, fn stack -\u003e\n\t\t\tstack ++ [v]\n\t\tend)\n\tend\nend\n\nStack.start_link\nStack.push(\"a\")\nStack.push(\"b\")\nStack.push(\"c\")\nStack.get\n|\u003e IO.inspect\nStack.rev\n|\u003e IO.inspect\nEnum.map(Stack.rev, fn v -\u003e\n    IO.puts v\nend)\n\n```\n\n# 実行結果\n\n```\n[\"a\", \"b\", \"c\"]\n[\"c\", \"b\", \"a\"]\nc\nb\na\n\n```\n\n# 成果物\n\nhttps://paiza.io/projects/w2rBHK76LtqwiE7PF_s1-Q?language=elixir\n\n\n以上。\n","coediting":false,"comments_count":0,"created_at":"2023-03-13T15:42:32+09:00","group":null,"id":"195772ebcfd0370d2f58","likes_count":1,"private":false,"reactions_count":0,"stocks_count":0,"tags":[{"name":"Elixir","versions":[]},{"name":"paiza.IO","versions":[]}],"title":"paiza.ioでelixir その210","updated_at":"2023-03-13T15:42:32+09:00","url":"https://qiita.com/ohisama@github/items/195772ebcfd0370d2f58","user":{"description":null,"facebook_id":null,"followees_count":0,"followers_count":63,"github_login_name":"ohisama","id":"ohisama@github","items_count":3321,"linkedin_id":null,"location":null,"name":"","organization":null,"permanent_id":18104,"profile_image_url":"https://secure.gravatar.com/avatar/2e0bb506fbe90e6572bf92fa05db88d3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","team_only":false,"twitter_screen_name":null,"website_url":null},"page_views_count":null,"team_membership":null}]
```

# 成果物

https://paiza.io/projects/-sf0nvrfgTyW1CggNwHTXw?language=nadesiko


以上。