{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Advent of Code 2017\n",
    "\n",
    "## December 4th\n",
    "To ensure security, a valid passphrase must contain no duplicate words.\n",
    "\n",
    "For example:\n",
    "\n",
    "* aa bb cc dd ee is valid.\n",
    "* aa bb cc dd aa is not valid - the word aa appears more than once.\n",
    "* aa bb cc dd aaa is valid - aa and aaa count as different words.\n",
    "\n",
    "The system's full passphrase list is available as your puzzle input. How many passphrases are valid?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from notebook_preamble import J, V, define"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I'll assume the input is a Joy sequence of sequences of integers.\n",
    "\n",
    "    [[5 1 9 5]\n",
    "     [7 5 4 3]\n",
    "     [2 4 6 8]]\n",
    "\n",
    "So, obviously, the initial form will be a `step` function:\n",
    "\n",
    "    AoC2017.4 == 0 swap [F +] step"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "    F == [size] [unique size] cleave =\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `step_zero` combinator includes the `0 swap` that would normally open one of these definitions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "==== Help on step_zero ====\n",
      "\n",
      "0 roll> step\n",
      "\n",
      "---- end (step_zero)\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "J('[step_zero] help')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "    AoC2017.4 == [F +] step_zero"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "define('AoC2017.4 [[size] [unique size] cleave = +] step_zero')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "J('''\n",
    "\n",
    "[[5 1 9 5]\n",
    " [7 5 4 3]\n",
    " [2 4 6 8]] AoC2017.4\n",
    "\n",
    "''')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
