{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "{-# LANGUAGE NegativeLiterals #-}\n", "{-# LANGUAGE FlexibleContexts #-}" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import Data.List.Split (splitOn)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "hexStep :: (Int, Int) -> String -> (Int, Int)\n", "hexStep (n, ne) s = case s of \n", " \"n\" -> (n + 1, ne)\n", " \"ne\" -> (n, ne + 1)\n", " \"nw\" -> (n + 1, ne - 1)\n", " \"s\" -> (n - 1, ne)\n", " \"se\" -> (n - 1, ne + 1)\n", " \"sw\" -> (n, ne - 1)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "hexPath = foldl hexStep (0, 0)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "