{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": [ "## Spoiler warning\n", "Contains solution for AOC 2019 Day 1" ] }, { "metadata": {}, "cell_type": "code", "source": "@file:DependsOn(\"com.toldoven.aoc:aoc-kotlin-notebook:1.1.1\")", "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "import com.toldoven.aoc.notebook.AocClient\n", "\n", "// Initialize a day\n", "val aoc = AocClient.fromEnv().interactiveDay(2019, 1)" ], "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "// Live countdown synchronized with Advent of Code server time\n", "aoc.waitUntilUnlocked()" ], "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "// View part one problem description\n", "aoc.viewPartOne()" ], "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "// Get the input\n", "aoc.input()" ], "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "val result = aoc.input()\n", " .lines()\n", " .map { it.toInt() }\n", " .sumOf {\n", " it / 3 - 2\n", " }\n", "\n", "result" ], "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "// Submit the first part\n", "aoc.submitPartOne(result)" ], "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "// View part two problem description\n", "aoc.viewPartTwo()" ], "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "val result = aoc.input()\n", " .lines()\n", " .map { it.toInt() }\n", " .sumOf {\n", " generateSequence(it) {\n", " it / 3 - 2\n", " }\n", " .drop(1)\n", " .takeWhile { it > 0 }\n", " .sum()\n", " }\n", "\n", "result" ], "outputs": [], "execution_count": null }, { "metadata": {}, "cell_type": "code", "source": [ "// Submit the second part\n", "aoc.submitPartTwo(result)" ], "outputs": [], "execution_count": null } ], "metadata": { "kernelspec": { "display_name": "Kotlin", "language": "kotlin", "name": "kotlin" }, "language_info": { "name": "kotlin", "version": "1.9.23", "mimetype": "text/x-kotlin", "file_extension": ".kt", "pygments_lexer": "kotlin", "codemirror_mode": "text/x-kotlin", "nbconvert_exporter": "" }, "ktnbPluginMetadata": { "projectLibraries": false } }, "nbformat": 4, "nbformat_minor": 0 }