Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elm でつくるルービックキューブ

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Elm でつくるルービックキューブ

Avatar for Tomoya Kashifuku

Tomoya Kashifuku

November 18, 2022
Tweet

More Decks by Tomoya Kashifuku

Other Decks in Programming

Transcript

  1. 自己紹介
 カシフクトモヤ @tnyo43 ( @cashooooou) 普段は TypeScript と React でフロントエンドを書いてる.

    2018年に初めて Elm で小さい Webアプリを作った. ポケモンが好き(このあと昨日出た新作をやる) 1 / 11
  2. データ構造を定義する
 5 / 11 回転させるとき、キューブは種類ごとに独立して考えられる. キューブの種類ごとに色と位置に番号をつけたベクトルとみなす. (本当は個々のキューブの向きも管理する必要があるのでもうちょっと複雑) type alias Cube

    = { corner : Array Int , edge : Array Int , center : Array Int } init : () -> Cube init _ = Cube (Array.fromList [0, 1, 2, 3, 4, 5, 6, 7]) (Array.fromList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) (Array.fromList [0, 1, 2, 3, 4, 5]) 0 5 2 3 1 6 7
  3. データ構造を定義する
 rotate: Side -> Cube -> Cube rotate side cube

    = case side of Top -> { corner = replace cube.corner [(0, 1), (1, 2), (2, 3), (3, 0)] , edges = replace cube.edges [(0, 3), (3, 2), (2, 1), (1, 0)] } Left -> { corner = replace cube.corner [(0, 3), (3, 7), (7, 4), (4, 0)] , edges = replace cube.edges [(1, 8), (8, 5), (5, 11), (11, 1)] } ... 7 / 11